Note that there are some explanatory texts on larger screens.

plurals
  1. POmerging dictionarys using keys in one to scan values of another
    primarykey
    data
    text
    <p>Need help merging two dictionaries using the keys from one to look at values in another. If returns true it would append its own values into the other dictionary (updating it.. but not overwriting already present values)</p> <p>The code (sorry first custom script ever):</p> <pre><code>otuid2clusteridlist = dict() finallist = otuid2clusteridlist clusterid2denoiseidlist = dict() #first block, also = finallist we append all other blocks into. for line in open('cluster_97.ucm', 'r'): lineArray = re.split('\s+',line) otuid = lineArray[0] clusterid = lineArray[3] if otuid in otuid2clusteridlist: otuid2clusteridlist[otuid].append(clusterid) else: otuid2clusteridlist[otuid] = list() otuid2clusteridlist[otuid].append(clusterid) #second block, higher tier needs to expand previous blocks hash for line in open('denoise.ucm_test', 'r'): lineArray = re.split('\s+', line) clusterid = lineArray[4] denoiseid = lineArray[3] if clusterid in clusterid2denoiseidlist: clusterid2denoiseidlist[clusterid].append(denoiseid) else: clusterid2denoiseidlist[clusterid] = list() clusterid2denoiseidlist[clusterid].append(denoiseid) #print/return function for testing (will convert to write out later) for key in finallist: print "OTU:", key, "has", len(finallist[key]), "sequence(s) which", "=", finallist[key] </code></pre> <p>Block one returns </p> <pre><code>OTU: 3 has 3 sequence(s) which = ['5PLAS.R2.h_35336', 'GG13_52054', 'GG13_798'] OTU: 5 has 1 sequence(s) which = ['DEX1.h_14175'] OTU: 4 has 1 sequence(s) which = ['PLAS.h_34150'] OTU: 7 has 1 sequence(s) which = ['DEX12.13.h_545'] OTU: 6 has 1 sequence(s) which = ['GG13_45705'] </code></pre> <p>Block two returns</p> <pre><code>OTU: GG13_45705 has 4 sequence(s) which = ['GG13_45705', 'GG13_6312', 'GG13_32148', 'GG13_35246'] </code></pre> <p>So the goal is to add block two's out put into block one. I would like it to add in like this</p> <pre><code>... OTU: 6 has 4 sequence(s) which = ['GG13_45705', 'GG13_6312', 'GG13_32148', 'GG13_35246'] </code></pre> <p>I attempted <code>dic.update</code> but it just adds block twos contents into block one since the key is not present in block one.</p> <p>I think my issue is more complicated, I need block two to look within block one's value for its key and append values into that list.</p> <p>I have been trying for loops and .append (similar to the code already wrote) but I am lacking the overall knowledge of python to solve this.</p> <p>Ideas?</p> <p>Additions,</p> <p>Some subsets of the data:</p> <p>cluster_97.ucm (block one's file):</p> <pre><code>5 376 * DEX1.h_14175 DEX1.h_14175 6 294 * GG13_45705 GG13_45705 0 447 98.7 DEX22.h_37221 DEX29.h_4583 1 367 98.9 DEX14.15.h_35477 DEX27.h_779 1 443 98.4 DEX27.h_3794 DEX27.h_779 0 478 97.9 DEX22.h_7519 DEX29.h_4583 </code></pre> <p>denoise.ucm_test (block two's file):</p> <pre><code>11 294 * GG13_45705 GG13_45705 11 278 99.6 GG13_6312 GG13_45705 11 285 99.6 GG13_32148 GG13_45705 11 275 99.6 GG13_35246 GG13_45705 </code></pre> <p>I picked these subsets because the 2nd line in file one is what file two would would be updating.</p> <p>If anyone wants to give it a shot. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload