sd = "/home/olya/Downloads/sd_aggagg_both"
gff = "/home/olya/Downloads/GCF_016415705.1_ASM1641570v1_feature_table.txt"

MIN_DIST = 5
MAX_DIST = 12
we_have = []

with open(sd) as f:
    for line in f:
        parts = line.split()
        we_have.append({
            "start": int(parts[0]),
            "end": int(parts[1]),
            "strand": parts[2],
        })

CDS = []

with open(gff) as f:
    for line in f:
        if line.startswith("#"):
            continue
        parts = line.split("\t")
        if parts[0] != "CDS":
            continue
        CDS.append({
            "start": int(parts[7]),
            "end": int(parts[8]),
            "strand": parts[9],
        })

count = 0
for finding in we_have:
    flag = False

    for cds in CDS:
        if finding["strand"] != cds["strand"]:
            continue

        if finding["strand"] == "+":
            dist = cds["start"] - finding["end"]
        else:
            dist = finding["start"] - cds["end"]

        if MIN_DIST <= dist <= MAX_DIST:
            flag = True
            break

    if flag:
        count += 1

total = len(we_have)

print("We have:", total)
print("Correct findings:", count)
print(count / total * 100, "%")