python - using enumerate to iterate over a dictionary of lists to extract information -


i got earlier today how obtain positional information dictionary using enumerate(). provide code shortly. however, i've found cool tool, want implement in different manner obtain more information dictionary.

i have dictionary:

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

and file:

a    73 b    15 etc 

what want find difference max of first element in list min second element. example, difference of 21 , 30. want add these differences until hit pair (range) of numbers number file matches (if makes sense).

here code i've been working on:

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]             sd,  in enumerate(exons[name]):                 while not snpos<=max(i):                     intron = min(i+1) - max(i) #this doesn't work unfortunately. says can't add 1                     totalintron = 0 + intron                 if snpos<=max(i):                     exonmin = min(i)                     exonnumber = sd+1                     print exonnumber,name,totalintron                     break 

i think it's sd (indexer) confusing me. don't know how use in context. commented out portions other avenues i've tried failed successful. help? know confusing question , code might little mixed up, that's because can't output correct other mistakes yet.

i want output based on file provided:

exon   name    introntotal     3       38 1    b    0 

to try provide question: critical part of problem don't think enumerate think does. enumerate numbers things iterating over. when go through loop, sd first 0, 1... , that's all. in case, want @ adjacent list entries (it seems?), more idiomatic ways of looping in python aren't clean. like:

... y = exons[name]  index in range(len(y) - 1): # - 1 prevent going out of bounds     first_max = max(y[index])     second_min = min(y[index+1])     ... # more stuff, didn't follow you're trying 

i add hardcore pythonistas, can of course clever stuff write more idiomatically , avoid c style loop wrote, think getting zip , on might bit confusing new python.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -