python - Determine location given a dictionary with lists inside of a list -


i'm new here , need some code i've been working on because i've gotten myself lost , confused.

first, created dictionary based on website. sample of dictionary looks this:

length = {'a': [(0,21), (30,41), (70,80)] 'b': [(0,42), (70,80)]..etc} 

i have file use iterate on dictionary contains information:

a    32 b    15 etc 

what want take first feature in file , match key of dictionary. once have matched, want to see range number in file matches to. example, first feature in file match , second range. means want output show name (a) , display 2 because matched second range.

i've tried code below:

import csv open('exome_agg_cons_snps_pct_refseq_hgmd_reinitialized.txt') f:     reader = csv.dictreader(f,delimiter="\t")     row in reader:         snppos = row['snp_rein']         name = row['isoform']         snpos = int(snppos)         if name in exons:             y = exons[name]             if y[0] <= snpos <=y[1]:                 print name,snppos 

this, however, doesn't give me output. i'm not sure wrong code. new though. think might missing something. also, realize code won't want (tell me range matched to). thinking of using .index() function i'm not sure can use in case have. suggestions?

if list in dictionary ordered method work

  1. the enumerate method provides 2 output 1 index , next 1 value .
  2. since value here list iterating on lists[one list @ time ].
  3. we using max method find maximum of list
  4. then comparing value text .
  5. if print index +1 , name

code:

for sd,  in enumerate(exons[name]):     if snpos<=max(i) , snpos>=min(i):         print sd+1,name         break 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -