I have two python dictionary variables. One is a dict with IDs as keys and long strings as values, the other one is a dict with different type of IDs as keys and list as values.
They look like this:
**dContigData**
Chromosome_8.8 AAACGCAATAACCAGAAAACCAATTTTTAAAATATTAAACCCAACGAAAT...
Chromosome_8.4 CCTAACCCTAACCCTAACCCTAACCCTAACCCTAACCCTAACCCTAACCC...
Chromosome_8.5 CTAACCCTAACCCTAACCCTAACCCTAACCCTAACCCTAACCCTAACCCT...
Chromosome_8.6 GCCTGCTCGTAACCCTGACTCGTCCACCCCCAATCCGTCACCCCATTAAT...
Chromosome_8.7 CCCTAACCCTAACCCTAACCCTAACCCTAACCCTAACCCTAACCCTAACC...
Chromosome_8.1 TCGCTTCGGCGGTCCTGCGGCATCTTTGTACTTCTTGTGGAAGTCGTCAA...
Chromosome_8.2 CCCTAACCCTAACCCTAACCCTAACCCTAACCCTAACCCTAACCCTAACC...
Chromosome_8.3 TAACCCTAACCCTAACCCTAACCCTAACCCTAACCCTAACCCTAACCCTA...
and the other:
e = dict() # temporary dictionary variable:
MGG_08464T0 ['Chromosome_8.4', 306312, 306647, 306759, 307475]
MGG_06151T0 ['Chromosome_8.3', 2749586, 2750617]
MGG_07594T0 ['Chromosome_8.3', 1141635, 1142444]
MGG_13455T0 ['Chromosome_8.3', 1512811, 1512907, 1513002, 1513487, 1513578, 1513822, 1514067, 1514645]
MGG_00992T0 ['Chromosome_8.5', 896033, 896144, 896226, 896573, 896655, 897307]
MGG_04622T0 ['Chromosome_8.1', 7084849, 7084958, 7085037, 7085724]
So, I have written code to print the key from "dict e" and substring of dContigData value from "dict e" value[1]-1 (306311 in the first case, subtract 1 because of python position) to value[-1] (307475 in the first case). However, the values in a list are not in the same length, although the position information elements (the elements just after the first element in the list. e.g. Chromosome_8.X) are always in pairs. Actually, what I want to do is iterate the position information elements in each list and substring the string of dContigData.
My code:
dContigData = readContigFasta()
#for key in dContigData:
# print(key, dContigData[key][0:50]+"...")
for key in e:
for contigID in dContigData:
if e[key][0] == contigID:
#print (key, e[key])
print (key, dContigData[contigID][e[key][1]-1:e[key][-1]]) # -1 for start base 0
EDIT: Okay, many of you do not get my question, so if you do not understand the above mumbles, just concentrate on the end result below, please. ;)
Result supposed to be (for example as the 5th in "dict e" with 3 pieces):
e.g.
MGG_00992T0 [896032]ATGGGCATTTCGGCTCGGGTCAGTAC[896144]...[896225]GCTGACCCATTACAGGTTGGGGGCTTTAA[896573]...[896654]ACCAAAGTTCCCACTTGTCCCCTGGGACCGAGATGTCCAACAATGA[897307]
[number] and ... for easier understanding (supposed to NOT be included)
Any idea to substring a string and then concatenate back to a string while looping?