Skip to content

Commit

Permalink
Move strand & DB ref from SeqFeature to FeatureLocation __str__
Browse files Browse the repository at this point in the history
  • Loading branch information
peterjc committed Oct 10, 2011
1 parent 07c678b commit fed0038
Show file tree
Hide file tree
Showing 5 changed files with 433 additions and 847 deletions.
51 changes: 36 additions & 15 deletions Bio/SeqFeature.py
Expand Up @@ -217,9 +217,6 @@ def __str__(self):
out += "location: %s\n" % self.location
if self.id and self.id != "<unknown id>":
out += "id: %s\n" % self.id
if self.ref or self.ref_db:
out += "ref: %s:%s\n" % (self.ref, self.ref_db)
out += "strand: %s\n" % self.strand
out += "qualifiers: \n"
for qual_key in sorted(self.qualifiers):
out += " Key: %s, Value: %s\n" % (qual_key,
Expand Down Expand Up @@ -404,10 +401,10 @@ def __contains__(self, value):
>>> record = SeqIO.read("GenBank/NC_000932.gb", "gb")
>>> for f in record.features:
... if 1750 in f:
... print f.type, f.strand, f.location
source 1 [0:154478]
gene -1 [1716:4347]
tRNA -1 [1716:4347]
... print f.type, f.location
source [0:154478](+)
gene [1716:4347](-)
tRNA [1716:4347](-)
Note that for a feature defined as a join of several subfeatures (e.g.
the union of several exons) the gaps are not checked (e.g. introns).
Expand All @@ -417,9 +414,9 @@ def __contains__(self, value):
>>> for f in record.features:
... if 1760 in f:
... print f.type, f.strand, f.location
source 1 [0:154478]
gene -1 [1716:4347]
... print f.type, f.location
source [0:154478](+)
gene [1716:4347](-)
Note that additional care may be required with fuzzy locations, for
example just before a BeforePosition:
Expand Down Expand Up @@ -523,18 +520,24 @@ def __init__(self, start, end, strand=None, ref=None, ref_db=None):
i.e. Short form:
>>> from Bio.SeqFeature import FeatureLocation
>>> loc = FeatureLocation(5,10)
>>> loc = FeatureLocation(5, 10, strand=-1)
>>> print loc
[5:10](-)
Explicit form:
>>> from Bio.SeqFeature import FeatureLocation, ExactPosition
>>> loc = FeatureLocation(ExactPosition(5),ExactPosition(10))
>>> loc = FeatureLocation(ExactPosition(5), ExactPosition(10), strand=-1)
>>> print loc
[5:10](-)
Other fuzzy positions are used similarly,
>>> from Bio.SeqFeature import FeatureLocation
>>> from Bio.SeqFeature import BeforePosition, AfterPosition
>>> loc2 = FeatureLocation(BeforePosition(5),AfterPosition(10))
>>> loc2 = FeatureLocation(BeforePosition(5), AfterPosition(10), strand=-1)
>>> print loc2
[<5:>10](-)
For nucleotide features you will also want to specify the strand,
use 1 for the forward (plus) strand, -1 for the reverse (negative)
Expand All @@ -543,14 +546,18 @@ def __init__(self, start, end, strand=None, ref=None, ref_db=None):
proteins.
>>> loc = FeatureLocation(5, 10, strand=+1)
>>> print loc
[5:10](+)
>>> print loc.strand
1
Normally feature locations are given relative to the parent
sequence you are working with, but an explicit accession can
be given with the optional ref and db_ref strings:
>>> loc = FeatureLocation(105172, 108462, ref="AL391218.9")
>>> loc = FeatureLocation(105172, 108462, ref="AL391218.9", strand=1)
>>> print loc
AL391218.9[105172:108462](+)
>>> print loc.ref
AL391218.9
Expand Down Expand Up @@ -588,7 +595,21 @@ def __str__(self):
(zero based counting) which GenBank would call 123..150 (one based
counting).
"""
return "[%s:%s]" % (self._start, self._end)
answer = "[%s:%s]" % (self._start, self._end)
if self.ref and self.ref_db:
answer = "%s:%s%s" % (self.ref_db, self.ref, answer)
elif self.ref:
answer = self.ref + answer
#Is ref_db without ref meaningful?
if self.strand is None:
return answer
elif self.strand == +1:
return answer + "(+)"
elif self.strand == -1:
return answer + "(-)"
else:
#strand = 0, stranded but strand unknown, ? in GFF3
return answer + "(?)"

def __repr__(self):
"""A string representation of the location for debugging."""
Expand Down
6 changes: 2 additions & 4 deletions Bio/SeqRecord.py
Expand Up @@ -1024,17 +1024,15 @@ def reverse_complement(self, id=False, name=False, description=False,
>>> print plasmid.features[1]
type: CDS
location: [1081:1960]
strand: -1
location: [1081:1960](-)
qualifiers:
Key: label, Value: ['araC']
Key: note, Value: ['araC regulator of the arabinose BAD promoter']
Key: vntifkey, Value: ['4']
<BLANKLINE>
>>> print rc_plasmid.features[-2]
type: CDS
location: [2963:3842]
strand: 1
location: [2963:3842](+)
qualifiers:
Key: label, Value: ['araC']
Key: note, Value: ['araC regulator of the arabinose BAD promoter']
Expand Down
13 changes: 4 additions & 9 deletions Doc/Tutorial.tex
Expand Up @@ -1997,8 +1997,7 @@ \section{Slicing a SeqRecord}
\begin{verbatim}
>>> print record.features[20]
type: gene
location: [4342:4780]
strand: 1
location: [4342:4780](+)
qualifiers:
Key: db_xref, Value: ['GeneID:2767712']
Key: gene, Value: ['pim']
Expand All @@ -2009,8 +2008,7 @@ \section{Slicing a SeqRecord}
\begin{verbatim}
>>> print record.features[21]
type: CDS
location: [4342:4780]
strand: 1
location: [4342:4780](+)
qualifiers:
Key: codon_start, Value: ['1']
Key: db_xref, Value: ['GI:45478716', 'GeneID:2767712']
Expand Down Expand Up @@ -2052,8 +2050,7 @@ \section{Slicing a SeqRecord}
\begin{verbatim}
>>> print sub_record.features[0]
type: gene
location: [42:480]
strand: 1
location: [42:480](+)
qualifiers:
Key: db_xref, Value: ['GeneID:2767712']
Key: gene, Value: ['pim']
Expand All @@ -2063,9 +2060,7 @@ \section{Slicing a SeqRecord}
\begin{verbatim}
>>> print sub_record.features[20]
type: CDS
location: [42:480]
ref: None:None
strand: 1
location: [42:480](+)
qualifiers:
Key: codon_start, Value: ['1']
Key: db_xref, Value: ['GI:45478716', 'GeneID:2767712']
Expand Down

0 comments on commit fed0038

Please sign in to comment.