Answers.Body: <p>I believe the attribute you should be looking for is <code>dbxrefs</code>:</p>
  
  <pre><code>[x for x in record.dbxrefs if x.startswith('GO:')]
  </code></pre>
  
  <p>Apparently <code>SeqIO</code> handles uniprot text files differently than the <code>SwissProt</code> module:</p>
  
  <pre><code>from Bio import SwissProt
  record = SwissProt.read(open('single_record_from_uniprot.txt'))
  record.cross_references
  </code></pre>
  
  <p>So you should change you code to use the <code>SwissProt</code> module to get the behavior you expect</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-06T15:44:21.613Z
Answers.LastActivityDate: 2019-05-06T15:44:21.613Z
Answers.UserDisplayName: mgalardini
Body: <p>I am struggling to use biopython to gather cross references such as GO annotation from Uniprot/swissprot text files ("<code>DR</code>" in the .txt files) using biopython.</p>
  
  <p>From the <a href="https://biopython.org/DIST/docs/api/Bio.SwissProt-pysrc.html" rel="nofollow noreferrer">source code</a>:</p>
  
  <pre><code>def _read_dr(record, value): 
      cols = value.rstrip(".").split('; ') 
      record.cross_references.append(tuple(cols)) 
  </code></pre>
  
  <p>This leads me to think that the following code should work, as this is how other features like annotation and features work.</p>
  
  <pre><code>for record in SeqIO.parse(filename, "swiss"):
      print(record.cross_references) #does not work, should return a list of DR rows
      print(record.features) #works, returns a list of parsed FT rows
  </code></pre>
  
Tags: <python><uniprot>
Title: How to get Uniprot and swissprot cross references using Biopython
ThreadText: # How to get Uniprot and swissprot cross references using Biopython
  
  (Asked by: username_0 on 2019-04-30)
  
  I am struggling to use biopython to gather cross references such as GO annotation from Uniprot/swissprot text files ("`DR`" in the .txt files) using biopython.
  
  From the [source code](https://biopython.org/DIST/docs/api/Bio.SwissProt-pysrc.html):
  
  ```
  def _read_dr(record, value): 
      cols = value.rstrip(".").split('; ') 
      record.cross_references.append(tuple(cols)) 
  
  ```
  
  This leads me to think that the following code should work, as this is how other features like annotation and features work.
  
  ```
  for record in SeqIO.parse(filename, "swiss"):
      print(record.cross_references) #does not work, should return a list of DR rows
      print(record.features) #works, returns a list of parsed FT rows
  
  ```
  
  **Tags:** python, uniprot
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-05-06. Score: 3
  
  I believe the attribute you should be looking for is `dbxrefs`:
  
  ```
  [x for x in record.dbxrefs if x.startswith('GO:')]
  
  ```
  
  Apparently `SeqIO` handles uniprot text files differently than the `SwissProt` module:
  
  ```
  from Bio import SwissProt
  record = SwissProt.read(open('single_record_from_uniprot.txt'))
  record.cross_references
  
  ```
  
  So you should change you code to use the `SwissProt` module to get the behavior you expect
  
  
  ---
  
  