Back to index

python-biopython  1.60
Public Member Functions | Public Attributes
test_SeqRecord.SeqRecordMethods Class Reference

List of all members.

Public Member Functions

def setUp
def test_slice_variantes
def test_slice_simple
def test_slice_zero
def test_add_simple
def test_add_seq
def test_add_seqrecord
def test_add_seq_left
def test_slice_add_simple
def test_slice_add_shift

Public Attributes

 record

Detailed Description

Test SeqRecord methods.

Definition at line 63 of file test_SeqRecord.py.


Member Function Documentation

Definition at line 66 of file test_SeqRecord.py.

00066 
00067     def setUp(self) :
00068         f0 = SeqFeature(FeatureLocation(0,26), type="source",
00069                         qualifiers={"mol_type":["fake protein"]})
00070         f1 = SeqFeature(FeatureLocation(0,ExactPosition(10)))
00071         f2 = SeqFeature(FeatureLocation(WithinPosition(12, left=12,right=15),BeforePosition(22)))
00072         f3 = SeqFeature(FeatureLocation(AfterPosition(16),
00073                                         OneOfPosition(26, [ExactPosition(25),AfterPosition(26)])))
00074         self.record = SeqRecord(Seq("ABCDEFGHIJKLMNOPQRSTUVWZYX", generic_protein),
00075                                 id="TestID", name="TestName", description="TestDescr",
00076                                 dbxrefs=["TestXRef"], annotations={"k":"v"},
00077                                 letter_annotations = {"fake":"X"*26},
00078                                 features = [f0,f1,f2,f3])

Simple addition of Seq or string

Definition at line 134 of file test_SeqRecord.py.

00134 
00135     def test_add_seq(self):
00136         """Simple addition of Seq or string"""
00137         for other in [Seq("BIO"), "BIO"] :
00138             rec = self.record + other # will use SeqRecord's __add__ method
00139             self.assertEqual(len(rec), 26+3)
00140             self.assertEqual(str(rec.seq), str(self.record.seq)+"BIO")
00141             self.assertEqual(rec.id, "TestID")
00142             self.assertEqual(rec.name, "TestName")
00143             self.assertEqual(rec.description, "TestDescr")
00144             self.assertEqual(rec.dbxrefs, ["TestXRef"])
00145             self.assertEqual(rec.annotations, {"k":"v"})
00146             self.assertEqual(rec.letter_annotations, {})
00147             self.assertEqual(len(rec.features), len(self.record.features))
00148             self.assertEqual(rec.features[0].type, "source")
00149             self.assertEqual(rec.features[0].location.nofuzzy_start, 0)
00150             self.assertEqual(rec.features[0].location.nofuzzy_end, 26) #not +3

Simple left addition of Seq or string

Definition at line 174 of file test_SeqRecord.py.

00174 
00175     def test_add_seq_left(self):
00176         """Simple left addition of Seq or string"""
00177         for other in [Seq("BIO"), "BIO"] :
00178             rec = other + self.record # will use SeqRecord's __radd__ method
00179             self.assertEqual(len(rec), 26+3)
00180             self.assertEqual(str(rec.seq), "BIO"+str(self.record.seq))
00181             self.assertEqual(rec.id, "TestID")
00182             self.assertEqual(rec.name, "TestName")
00183             self.assertEqual(rec.description, "TestDescr")
00184             self.assertEqual(rec.dbxrefs, ["TestXRef"])
00185             self.assertEqual(rec.annotations, {"k":"v"})
00186             self.assertEqual(rec.letter_annotations, {})
00187             self.assertEqual(len(rec.features), len(self.record.features))
00188             self.assertEqual(rec.features[0].type, "source")
00189             self.assertEqual(rec.features[0].location.nofuzzy_start, 3)
00190             self.assertEqual(rec.features[0].location.nofuzzy_end, 26+3)
            
Simple left addition of SeqRecord from genbank file.

Definition at line 151 of file test_SeqRecord.py.

00151 
00152     def test_add_seqrecord(self):
00153         """Simple left addition of SeqRecord from genbank file."""
00154         other = SeqIO.read("GenBank/dbsource_wrap.gb", "gb")
00155         other.dbxrefs = ["dummy"]
00156         rec = self.record + other
00157         self.assertEqual(len(rec), len(self.record)+len(other))
00158         self.assertEqual(str(rec.seq), str(self.record.seq)+str(other.seq))
00159         self.assertEqual(rec.id, "<unknown id>")
00160         self.assertEqual(rec.name, "<unknown name>")
00161         self.assertEqual(rec.description, "<unknown description>")
00162         self.assertEqual(rec.dbxrefs, ["TestXRef", "dummy"])
00163         self.assertEqual(len(rec.annotations), 0)
00164         self.assertEqual(len(rec.letter_annotations),0)
00165         self.assertEqual(len(rec.features),
00166                          len(self.record.features) + len(other.features))
00167         self.assertEqual(rec.features[0].type, "source")
00168         self.assertEqual(rec.features[0].location.nofuzzy_start, 0)
00169         self.assertEqual(rec.features[0].location.nofuzzy_end, len(self.record)) #not +3
00170         i = len(self.record.features)
00171         self.assertEqual(rec.features[i].type, "source")
00172         self.assertEqual(rec.features[i].location.nofuzzy_start, len(self.record))
00173         self.assertEqual(rec.features[i].location.nofuzzy_end, len(rec))

Simple addition

Definition at line 122 of file test_SeqRecord.py.

00122 
00123     def test_add_simple(self):
00124         """Simple addition"""
00125         rec = self.record + self.record
00126         self.assertEqual(len(rec), 52)
00127         self.assertEqual(rec.id, "TestID")
00128         self.assertEqual(rec.name, "TestName")
00129         self.assertEqual(rec.description, "TestDescr")
00130         self.assertEqual(rec.dbxrefs, ["TestXRef"])
00131         self.assertEqual(rec.annotations, {"k":"v"})
00132         self.assertEqual(rec.letter_annotations, {"fake":"X"*52})
00133         self.assertEqual(len(rec.features), 2*len(self.record.features))

Simple slice and add to shift

Definition at line 205 of file test_SeqRecord.py.

00205 
00206     def test_slice_add_shift(self):
00207         """Simple slice and add to shift"""
00208         for cut in range(27) :
00209             rec = self.record[cut:] + self.record[:cut]
00210             self.assertEqual(str(rec.seq), str(self.record.seq[cut:] + self.record.seq[:cut]))
00211             self.assertEqual(len(rec), 26)
00212             self.assertEqual(rec.id, "TestID")
00213             self.assertEqual(rec.name, "TestName")
00214             self.assertEqual(rec.description, "TestDescr")
00215             self.assertEqual(rec.dbxrefs, []) # May change this...
00216             self.assertEqual(rec.annotations, {}) # May change this...
00217             self.assertEqual(rec.letter_annotations, {"fake":"X"*26})
00218             self.assertTrue(len(rec.features) <= len(self.record.features))
            
Simple slice and add

Definition at line 191 of file test_SeqRecord.py.

00191 
00192     def test_slice_add_simple(self):
00193         """Simple slice and add"""
00194         for cut in range(27) :
00195             rec = self.record[:cut] + self.record[cut:]
00196             self.assertEqual(str(rec.seq), str(self.record.seq))
00197             self.assertEqual(len(rec), 26)
00198             self.assertEqual(rec.id, "TestID")
00199             self.assertEqual(rec.name, "TestName")
00200             self.assertEqual(rec.description, "TestDescr")
00201             self.assertEqual(rec.dbxrefs, []) # May change this...
00202             self.assertEqual(rec.annotations, {}) # May change this...
00203             self.assertEqual(rec.letter_annotations, {"fake":"X"*26})
00204             self.assertTrue(len(rec.features) <= len(self.record.features))

Simple slice

Definition at line 91 of file test_SeqRecord.py.

00091 
00092     def test_slice_simple(self):
00093         """Simple slice"""
00094         rec = self.record
00095         self.assertEqual(len(rec), 26)
00096         left = rec[:10]
00097         self.assertEqual(str(left.seq), str(rec.seq[:10]))
00098         right = rec[-10:]
00099         self.assertEqual(str(right.seq), str(rec.seq[-10:]))
00100         mid = rec[12:22]
00101         self.assertEqual(str(mid.seq), str(rec.seq[12:22]))
00102         for sub in [left, right, mid] :
00103             self.assertEqual(len(sub), 10)
00104             self.assertEqual(sub.id, "TestID")
00105             self.assertEqual(sub.name, "TestName")
00106             self.assertEqual(sub.description, "TestDescr")
00107             self.assertEqual(sub.letter_annotations, {"fake":"X"*10})
00108             self.assertEqual(sub.dbxrefs, []) # May change this...
00109             self.assertEqual(sub.annotations, {}) # May change this...
00110             self.assertEqual(len(sub.features), 1)
00111             #By construction, each feature matches the full sliced region:
00112             self.assertEqual(str(sub.features[0].extract(sub.seq)), str(sub.seq))
00113             self.assertEqual(sub.features[0].extract(str(sub.seq)), str(sub.seq))

Here is the call graph for this function:

Simple slices using different start/end values

Definition at line 79 of file test_SeqRecord.py.

00079 
00080     def test_slice_variantes(self):
00081         """Simple slices using different start/end values"""
00082         for start in range(-30,30)+[None] :
00083             for end in range(-30,30)+[None] :
00084                 if start is None and end is None : continue
00085                 rec = self.record[start:end]
00086                 seq = self.record.seq[start:end]
00087                 seq_str = str(self.record.seq)[start:end]
00088                 self.assertEqual(seq_str, str(seq))
00089                 self.assertEqual(seq_str, str(rec.seq))
00090                 self.assertEqual("X"*len(seq_str), rec.letter_annotations["fake"])

Zero slice

Definition at line 114 of file test_SeqRecord.py.

00114 
00115     def test_slice_zero(self):
00116         """Zero slice"""
00117         rec = self.record
00118         self.assertEqual(len(rec), 26)
00119         self.assertEqual(len(rec[2:-2]), 22)
00120         self.assertEqual(len(rec[5:2]), 0)
00121         self.assertEqual(len(rec[5:2][2:-2]), 0)


Member Data Documentation

Definition at line 73 of file test_SeqRecord.py.


The documentation for this class was generated from the following file: