I have created a list:
arraynums = [ 0.3888553 0.3898553 0.3908553 0.3918553 0.3928553 0.3938553
0.3948553 0.3958553 0.3968553 0.3978553 0.3988553]
and a dictionary that has been sorted by key values (here's a portion of the dictionary):
sd =({'0.3880434': ['GGATCG'], '0.3883449': ['TTCACG'], '0.388449': ['ATGGCG'], '0.3890966': ['ACTCGC'], '0.3893325': ['GTGGAT'], '0.3893478': ['GATACG'], '0.3900749': ['CAGAAG'], '0.3900875': ['CGAGAG'], '0.3900915': ['ATCGGG'], '0.3901032': ['CACCGG'], '0.3901743': ['AAAGAC'], '0.3906361': ['TACGGC'], '0.390682': ['CCATCG'], '0.3909258': ['GGATGA'], '0.3910728': ['AAGATA'], '0.391648': ['GCAACG'], '0.3919125': ['AGGACT', 'GATCGC'], '0.3921844': ['AGAGAA'], '0.3922956': ['CGGGAA'], '0.3927617': ['ATGGAA'], '0.3927763': ['TTGTCG'], '0.3928683': ['ACAGAC'], '0.39309': ['CGCGCT'], '0.3938553': ['AGGACG'], '0.3940998': ['AAGAGC'], '0.3941768': ['GTCGGA'], '0.394966': ['CGTTCC'], '0.395116': ['TGGAAG'], '0.3954179': ['CCGTCC'], '0.3955623': ['AATCGC'], '0.3956923': ['GGACGG']})
I have been using this code to find the closest values to the values listed in the above list:
for k in arraynums:
index = sd.bisect(k)
key = sd.iloc[index]
seq = sd[key]
However, the key and seq's printed from this portion of the code does not correctly identify the closest values for k. I'm not quite sure what is going wrong. I think it might have to do with the way I created the arraynums
list. I created the list using this:
arraynums = numpy.arange(float(middlevalue) - 0.005, float(middlevalue) + 0.005, 0.001)
EDIT:
A note to the dictionary above: some of the values are negative and the output for each key is the same negative value... I've also sorted the dictionary using SortedDict()