Answers.Body: <p><a href="http://biopython.org/DIST/docs/tutorial/Tutorial.html#sec63" rel="nofollow noreferrer">Biopython can index a fastafile</a> and you can access the sequences by their ID in a dict-like manner.</p>
  <p>All that is left for you to do is extract the IDs from your file. (<a href="https://biopython.org/DIST/docs/api/Bio.SearchIO.HmmerIO-module.html" rel="nofollow noreferrer">more Biopython</a>)</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-08-18T10:06:01.020Z
Answers.Text: I didn't know they supported parsing hmmer outputs, thank you very much
Answers.UserDisplayName: Mike 
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-08-24T11:34:59.073Z
Answers.Text: Hi Pallie, I merged my drugbank file with my proteome file; I'm getting duplicated because of the drugbank file. Is there a way around this with additional keys or something of that sort?
Answers.UserDisplayName: Mike 
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-08-24T12:22:23.423Z
Answers.Text: Hi Mike, open a new question and show your code, input, and expected output so people can help :)
Answers.UserDisplayName: Pallie
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-08-24T14:44:24.800Z
Answers.Text: sounds great thank you! This is a really powerful protocol, automating it and getting it on the web would go a long way
Answers.UserDisplayName: Mike 
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-08-18T09:45:18.050Z
Answers.LastActivityDate: 2020-08-18T09:45:18.050Z
Answers.UserDisplayName: Pallie
Body: <pre><code>0.980634         -                    572         sp|P06672|PDC_ZYMMO                         -                     568                               1.2e-263             874.5          0.0            1        1      6.6e-267  1.4e-263   874.2      0.0       5         562    15     570    12     572    0.98   Uncharacterized                         protein                   OS=Lomentospora            prolificans        OX=41688             GN=jhhlp_005678  PE=3             SV=1
  </code></pre>
  <p>I've asked a similar question before. I have a better understanding of python now and would like to revisit this. Can someone critique my thinking?</p>
  <p>I have an HMM output file that contains about 20 fields. There are two sets of IDs, e.g., P006672 and jhhlp_005678</p>
  <p>In a separate file are FASTA-formatted sequences linked to these IDs.</p>
  <p>Proposed solution:</p>
  <p>1</p>
  <pre><code>   a) read in fields containing IDs, lets called them fields 8 and 6; 
  
  
     b) store field values in an array or dictionary (whatever the proper data structure is for 
    this). Let's called this Fields_8_and_6
  </code></pre>
  <ol start="2">
  <li><p>a) read proteome file containing FASTA-formatted sequences</p>
  <p>b) Grep and store as ID:sequence key:value pairs; let's call this ID_to_sequence</p>
  </li>
  <li><p>a) Compare Fields_8_and_6 to ID_to_sequence</p>
  <p>b) Write ID1:sequence1 ID2:sequence2 as pairs into one file</p>
  </li>
  </ol>
  <ol start="4">
  <li><p>send to ClustalO</p>
  </li>
  </ol>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-08-18T09:49:08.800Z
Comments.Text: I'm not sure if this will be helpful to you, but my initial idea would be to use the very helpful pandas module in python to parse the table, then use some sort of regex to recover the required IDs (for example, I might set a regex query to recover 'text between vertical lines' to get P06672, and 'text after =' to get jhhlp_005678). There are tutorials for pandas and regex on the Software Carpentry website.
Comments.UserDisplayName: Laura
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-08-18T10:03:44.827Z
Comments.Text: Got it, I know I've used both biopython and regex to parse the IDs before, and I've used awk to calculate query coverage (e.g., awk '{$1 = ($17-$16)/$6}1' ). Thanks very much for this
Comments.UserDisplayName: Mike 
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-04-05T04:03:27.683Z
Comments.Text: pandas will do it, but as pointed out BioPython has an HMM package.
Comments.UserDisplayName: M__
Tags: <bioconductor><python><proteomics>
Title: How can I match sequences with IDs using python dictionaries?
ThreadText: # How can I match sequences with IDs using python dictionaries?
  
  (Asked by: username_0 on 2020-08-18)
  
  ```
  0.980634         -                    572         sp|P06672|PDC_ZYMMO                         -                     568                               1.2e-263             874.5          0.0            1        1      6.6e-267  1.4e-263   874.2      0.0       5         562    15     570    12     572    0.98   Uncharacterized                         protein                   OS=Lomentospora            prolificans        OX=41688             GN=jhhlp_005678  PE=3             SV=1
  
  ```
  
  I've asked a similar question before. I have a better understanding of python now and would like to revisit this. Can someone critique my thinking?
  
  I have an HMM output file that contains about 20 fields. There are two sets of IDs, e.g., P006672 and jhhlp\_005678
  
  In a separate file are FASTA-formatted sequences linked to these IDs.
  
  Proposed solution:
  
  1
  
  ```
     a) read in fields containing IDs, lets called them fields 8 and 6; 
  
     b) store field values in an array or dictionary (whatever the proper data structure is for 
    this). Let's called this Fields_8_and_6
  
  ```
  
  2. a) read proteome file containing FASTA-formatted sequences
  
     b) Grep and store as ID:sequence key:value pairs; let's call this ID\_to\_sequence
  3. a) Compare Fields\_8\_and\_6 to ID\_to\_sequence
  
     b) Write ID1:sequence1 ID2:sequence2 as pairs into one file
  
  4. send to ClustalO
  
  **Tags:** bioconductor, python, proteomics
  
  > **Comments:**
  > **username_1**: I'm not sure if this will be helpful to you, but my initial idea would be to use the very helpful pandas module in python to parse the table, then use some sort of regex to recover the required IDs (for example, I might set a regex query to recover 'text between vertical lines' to get P06672, and 'text after =' to get jhhlp_005678). There are tutorials for pandas and regex on the Software Carpentry website.  
  > **username_0**: Got it, I know I've used both biopython and regex to parse the IDs before, and I've used awk to calculate query coverage (e.g., awk '{$1 = ($17-$16)/$6}1' ). Thanks very much for this  
  > **username_2**: pandas will do it, but as pointed out BioPython has an HMM package.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_3 on 2020-08-18. Score: 3
  
  [Biopython can index a fastafile](http://biopython.org/DIST/docs/tutorial/Tutorial.html#sec63) and you can access the sequences by their ID in a dict-like manner.
  
  All that is left for you to do is extract the IDs from your file. ([more Biopython](https://biopython.org/DIST/docs/api/Bio.SearchIO.HmmerIO-module.html))
  
  > **Comments:**
  > **username_0**: I didn't know they supported parsing hmmer outputs, thank you very much  
  > **username_0**: Hi username_3, I merged my drugbank file with my proteome file; I'm getting duplicated because of the drugbank file. Is there a way around this with additional keys or something of that sort?  
  > **username_3**: Hi username_0, open a new question and show your code, input, and expected output so people can help :)  
  > **username_0**: sounds great thank you! This is a really powerful protocol, automating it and getting it on the web would go a long way  
  
  ---
  
  