multiple positions exist in multiple region

Viewed 19

I have a variant position file and an exon region file.

1   242600263 
12  54757526  
11  45853978

The exon region file looks like this.

1:11861218-11861456 MTHFR-001_2
22:44280101-44280243   PNPLA5-201_7

Both files have around 100,000 lines.

For now, I write the exon region file into one dictionary, using the region as key.

When looping through the variant file, check if this position located in any key of exon dictionary.

for i in F1: <- loop through exon file 
    chrpos, exon, check=i
    exondict[chrpos]=exon

for j in F2: <- loop through variant file
    chr=j[0]
    if chr=="11": <- get chr 11 first
        variant=j[1]
        for chrpos in exondict.keys():
            chr, pos= chrpos.split(':')
            start, stop= pos.split('-')
            chr, start, stop
            if int(start)<=int(variant)<=int(stop):
                 newlist=[exondict[chrpos]]+ j
                 W.writerow(newlist)

Basically, I got what I want.

Just wondering if there is more elegant way to do this.

Thank you!

For example, a variant position is chr11:108164047 which locates within 11:108164040-108164204 ATM-201_31.

0 Answers
Related