Morning all,<br><br>  I took the pseudocode that Emile provided and tried to write a python program. I may have taken the pseudocode to literally. <br><br>So what I wrote was this:<br>xml = open(&quot;final.txt&quot;,&#39;r&#39;)<br>
gen = open(&quot;final_gen.txt&quot;,&#39;r&#39;)<br><br>PIDS = {}<br>for proteinVals in gen:<br>    ID = proteinVals.split()[0]<br>    PIDS[ID] = proteinVals<br><br>print PIDS<br><br>for line in xml:<br>    ID = proteinVals.split()[1]<br>
    rslt = &quot;%s,%s&quot;% (line,PIDS[ID])<br>    print rslt<br><br clear="all">So the first part I get. I read in gen that has this format as a text file:<br><i>Protein ID, Locus Tag, Start/Stop</i><br>ZP_05482482, StAA4_010100030484, complement(NZ_ACEV01000078.1:25146..40916)<br>
ZP_07281899, SSMG_05939, complement(NZ_GG657746.1:6565974..6581756)<br>ZP_05477599, StAA4_010100005861, NZ_ACEV01000013.1:86730..102047<br>...<br>Put that into a dictionary with a key that is the Protein ID at position 0 in the dictionary.<br>
<br>The second part reads in the file xml which has this format:<br><i>Species, Protein ID, E Value, Length</i><br>Streptomyces sp. AA4, ZP_05482482, 2.8293600000000001e-140, 5256,  <br>Streptomyces sp. AA4, ZP_05482482, 8.0333299999999997e-138, 5256,  <br>
Streptomyces sp. AA4, ZP_05482482, 1.08889e-124, 5256,  <br>Streptomyces sp. AA4, ZP_07281899, 2.9253900000000001e-140, 5260,  <br>Streptomyces sp. AA4, ZP_07281899, 8.2369599999999995e-138, 5260, <br>....<br>*same protein id multiple entries<br>
<br>The program splits the file and does something with the 1 position which is the proten id in the xml file. After that I am not really sure what is happening. I can&#39;t remember what the %s means. Something with a string?<br>
<br>When this runs I get the following error:<br>Traceback (most recent call last):<br>  File &quot;/Users/ara/Desktop/biopy_programs/merge2.py&quot;, line 18, in &lt;module&gt;<br>    rslt = &quot;%s,%s&quot;% (line,PIDS[ID])<br>
KeyError: &#39;StAA4_010100017400,&#39;<br><br>From what I can tell it&#39;s not happy about the dictionary key.<br><br>In the end I am looking for a way to merge these two files and for each protein ID add the locus tag and start/stop like this:<br>
<i>Species, Protein ID, Locus Tag, E Value, Length</i>, <i>Start/Stop</i><br>
Streptomyces sp. AA4, ZP_05482482, StAA4_010100030484, 2.8293600000000001e-140, 5256, complement(NZ_ACEV01000078.1:25146..40916)<br>
Streptomyces sp. AA4, ZP_05482482, StAA4_010100030484, 8.0333299999999997e-138, 5256, complement(NZ_ACEV01000078.1:25146..40916)<br>
Streptomyces sp. AA4, ZP_05482482, StAA4_010100030484, 1.08889e-124, 5256, complement(NZ_ACEV01000078.1:25146..40916) <br>
Streptomyces sp. AA4, ZP_07281899, SSMG_05939, 2.9253900000000001e-140, 5260, complement(NZ_GG657746.1:6565974..6581756)<br>
Streptomyces sp. AA4, ZP_07281899, SSMG_05939, 8.2369599999999995e-138, 5260, complement(NZ_GG657746.1:6565974..6581756)<br><br>Do you have any suggestions for how to proceed. It feels like I am getting closer. :)<br><br>
<br>Note:<br>When I change this part of the code to 0<br>for line in xml:<br>
    ID = proteinVals.split()[0]<br>
    rslt = &quot;%s,%s&quot;% (line,PIDS[ID])<br>
    print rslt<br><br>I get the following output:<br>Streptomyces sp. AA4, ZP_05482482, 8.0333299999999997e-138, 5256,  <br>,ZP_05479896, StAA4_010100017400, NZ_ACEV01000043.1:241968..&gt;242983<br><br>Streptomyces sp. AA4, ZP_05482482, 1.08889e-124, 5256,  <br>
,ZP_05479896, StAA4_010100017400, NZ_ACEV01000043.1:241968..&gt;242983<br><br>Streptomyces sp. AA4, ZP_07281899, 2.9253900000000001e-140, 5260,  <br>,ZP_05479896, StAA4_010100017400, NZ_ACEV01000043.1:241968..&gt;242983<br>
<br>Which seems closer but all it&#39;s doing is repeating the same Locus Tag and Start/Stop for each entry.<br><br>Thank you!<br>Ara<br><br><br>-- <br>Quis hic locus, quae regio, quae mundi plaga. Ubi sum. Sub ortu solis an sub cardine glacialis ursae.<br>