python - Using `if` statement to determine if two values are in a range -


i have dictionary looks this:

{'nm_100': [(0,20), (30,40), (70,90)], 'nm_200': [(0,35), (75,85), (90,100), (200,300)]} 

and tab separated file contains information:

isoform    strand    pos_rein1    pos_rein2 nm_100    -    32    35 nm_100    -    16    16 nm_200    -    76    77 nm_200    -    89    90 

what want test if both positions in file fall in same range of paired numbers in dictionary. example, both 32 , 35 lie in same range of paired numbers? (in case (30,40)) if do, proceed. if don't (as last case in file), not proceed. have far:

import csv open('indel_mod0_cdsstart_rein_both.txt') f:     reader = csv.dictreader(f,delimiter="\t")     row in reader:         pos = row['pos_rein1']         pos2 = row['pos_rein2']         name = row['isoform']         strand = row['strand']         ppos1 = int(pos)         ppos2 = int(pos2)         if name in exons:             y = exons[name]             i, (low,high) in enumerate(exons[name]):                 if low <= ppos1 <= high: #is there way edit line test if ppos2 in range                     exonnumber = i+1 

i'm testing see if first position falls in range of numbers, there easy way correct account both of numbers?

just use and add second test:

if low <= ppos1 <= high , low <= ppos2 <= high: 

if had more positions test, switch using all(), , store positions in sequence (here called positions):

if all(low <= pos <= high pos in positions): 

Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -