Skip to content

Commit

Permalink
Support writing EMBL references in SeqIO (see related Bug 2294)
Browse files Browse the repository at this point in the history
  • Loading branch information
peterjc committed Feb 1, 2010
1 parent 6f84816 commit 370e020
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
30 changes: 29 additions & 1 deletion Bio/SeqIO/InsdcIO.py
Expand Up @@ -743,6 +743,33 @@ def _write_the_first_lines(self, record):
self._write_single_line("AC", accession+";")
handle.write("XX\n")


def _write_references(self, record):
number = 0
for ref in record.annotations["references"]:
if not isinstance(ref, SeqFeature.Reference):
continue
number += 1
self._write_single_line("RN","[%i]" % number)
#TODO - support more complex record reference locations?
if ref.location and len(ref.location)==1:
self._write_single_line("RP","%i-%i" % (ref.location[0].nofuzzy_start+1,
ref.location[0].nofuzzy_end))
#TODO - record any DOI or AGRICOLA identifier in the reference object?
if ref.pubmed_id:
self._write_single_line("RX", "PUBMED; %s." % ref.pubmed_id)
if ref.authors:
#We store the AUTHORS data as a single string
self._write_multi_line("RA", ref.authors)
if ref.title:
#We store the title as a single string
self._write_multi_line("RT", '"%s";' % ref.title)
if ref.journal:
#We store this as a single string - holds the journal name,
#volume, year, and page numbers of the citation
self._write_multi_line("RL", ref.journal)
self.handle.write("XX\n")

def _write_comment(self, record):
#This is a bit complicated due to the range of possible
#ways people might have done their annotation...
Expand Down Expand Up @@ -786,7 +813,8 @@ def write_record(self, record):
self._write_multi_line("OC", taxonomy)
handle.write("XX\n")

#TODO - References...
if "references" in record.annotations:
self._write_references(record)

if "comment" in record.annotations:
self._write_comment(record)
Expand Down
8 changes: 6 additions & 2 deletions Tests/test_SeqIO_features.py
Expand Up @@ -77,8 +77,12 @@ def compare_record(old, new, expect_minor_diffs=False):
assert r1.title == r2.title
assert r1.authors == r2.authors
assert r1.journal == r2.journal
assert r1.consrtm == r2.consrtm
assert r1.medline_id == r2.medline_id
if r1.consrtm and r2.consrtm:
#Not held in EMBL files
assert r1.consrtm == r2.consrtm
if r1.medline_id and r2.medline_id:
#Not held in EMBL files
assert r1.medline_id == r2.medline_id
assert r1.pubmed_id == r2.pubmed_id
continue
if repr(old.annotations[key]) != repr(new.annotations[key]):
Expand Down

0 comments on commit 370e020

Please sign in to comment.