I posted here last night but no one responded. I've since made some progress. Here's the code:for rows in range(len(kmerl)):
for cols in range(len(kmerl[rows])):
mdarray = {(i,j):0 for j in range(cols+1) for i in range(rows+1)}
nucs = {'A':mdarray, 'G':mdarray, 'T':mdarray, 'C':mdarray}
'''
for i in range(len(kmerl)):
for j in range(len(kmerl[i])):
if kmerl[i][j] == 'A':
try:
print(kmerl)
nucs['A'][i][j] = 1
print(nucs['A'][i][j])
print('test')
except KeyError:
pass
elif kmerl[i][j] == 'C':
try:
nucs['C'][i][j] = 1
except KeyError:
pass
elif kmerl[i][j] == 'G':
try:
nucs['G'][i][j] = 1
except KeyError:
pass
elif kmerl[i][j] == 'T':
try:
nucs['T'][i][j] = 1
except KeyError:
pass'''
>>57047968
Basically, I have a set of tuples (i,j) for rows and columns, with each row column pair being set = 0. This tuple is contained as a value in the dictionary with keys {AGCT]. I have a file that is going to generate most of this information, and I need to get the count of each A, G, C, T at a given row/column position.
If I have a 2 lines of sequence: AGCCCAGACTACT, AGGGCTAGATAA
And I split them into 3 substrings of size k = 1 such as: C, G.
For example. This is the actual output from my terminal when I generate this dictionary using the above parameters dictionary.
{'A': {(1, 0): 0, (0, 0): 0}, 'G': {(1, 0): 0, (0, 0): 0}, 'T': {(1, 0): 0, (0, 0): 0}, 'C': {(1, 0): 0, (0, 0): 0}}
So now I need to get the count of each occurrence of A,C,G,T, and store a count as a subvalue of the tuple value.
So in this example it would be:
{'A': {(1, 0): 0, (0, 0): 0}, 'G': {(1, 0): 1, (0, 0): 0}, 'T': {(1, 0): 0, (0, 0): 0}, 'C': {(1, 0): 0, (0, 0): 1}}
I have added a 1 to G:(1:0): and C:(0:0):. Furthermore, I need to be able to increase this value given a larger col/row size if new occurences of AGCT happen, meaning I could do +=1
>>57047968
anon plz
>>57047968
I'm lazy and in class so could you put your problem into a tl;dr? You'd probably get more responses.
>>57048301
tl;dr how do I change the subvalue (where subvalue is the value of the 'value') of a dictionary without changing its key or value
dictionaryd = {keys:value:subvalue}
>>57048445
I should note:
in dictionary d value = tuple(i,j)
so dictionaryd = {keys:(i,j):value}
how do I do something like this:
dictionaryd[keys][i][j] = 1
>>57047968
I don't have a clue about your problem, but I think you should revise your data model, it's a mess and make your problem impenetrable.
For example, why don't you value and subvalue a pair?
Pic totally related. Beware of the unforseen consequences of the double helix.
>>57048573
>For example, why don't you value and subvalue a pair?
What do you mean? Likedictd {keys:[value][pair]:[subvalue][pair]}?
This would give me too many dimensions to the array. And that's not really the problem, it's being able to modify value of:dictionaryd = {keys:(i,j):value}
Once the dictionary array is created, keys, and (i,j) will remain constant. They will only be used for indexing