#!/usr/bin/env -S awk -f
# Usage: $0 -v min_identity=30 \
#     -v min_coverage=75 \
#     ./file.blastp.tsv
# The blastp.tsv file should have
# the four following supplementary colums
#     query length,
#     query gene ID,
#     subject length,
#     subject gene ID

BEGIN {
    OFS="\t"
}

function get_coverage(sequence_length, sequence_start, sequence_end) {
    return (sequence_end - sequence_start + 1) / sequence_length * 100
}

{
    qgeneid=$14
    sgeneid=$16
    qstart=$7
    qend=$8
    sstart=$9
    send=$10
    qlength=$13
    slength=$15
    identity=$3
    evalue=$11
    bitscore=$12
    if (get_coverage(qlength, qstart, qend) > min_coverage && get_coverage(slength, sstart, send) > min_coverage && identity > min_identity) {
        print $0
    }
}
