Back to index

python-biopython  1.60
Public Member Functions
test_SeqIO_features.SeqFeatureExtractionWritingReading Class Reference

List of all members.

Public Member Functions

def check
def test_simple_rna
def test_simple_dna
def test_single_letter_dna
def test_zero_len_dna
def test_zero_len_dna_end
def test_simple_dna_strand0
def test_simple_dna_strand_none
def test_simple_dna_strand1
def test_simple_dna_strand_minus
def test_simple_dna_join
def test_simple_dna_join
def test_simple_dna_join
def test_simple_dna_join_after
def test_mixed_strand_dna_join
def test_mixed_strand_dna_multi_join
def test_protein_simple
def test_protein_join
def test_protein_join_fuzzy
def test_protein_multi_join
def test_protein_between
def test_protein_oneof

Detailed Description

Tests for SeqFeature sequence extract method, writing, and reading.

Definition at line 200 of file test_SeqIO_features.py.


Member Function Documentation

def test_SeqIO_features.SeqFeatureExtractionWritingReading.check (   self,
  parent_seq,
  feature,
  answer_str,
  location_str 
)

Definition at line 203 of file test_SeqIO_features.py.

00203 
00204     def check(self, parent_seq, feature, answer_str, location_str):
00205         self.assertEqual(location_str,
00206             _insdc_feature_location_string(feature,len(parent_seq)))
00207 
00208         new = feature.extract(parent_seq)
00209         self.assertTrue(isinstance(new, Seq))
00210         self.assertEqual(str(new), answer_str)
00211 
00212         if not feature.sub_features:
00213             new = parent_seq[feature.location.start:feature.location.end]
00214             if feature.strand == -1:
00215                 new = reverse_complement(new)
00216             self.assertEqual(str(new), answer_str)
00217 
00218         new = feature.extract(str(parent_seq))
00219         self.assertTrue(isinstance(new, str))
00220         self.assertEqual(new, answer_str)
00221 
00222         new = feature.extract(parent_seq.tomutable())
00223         self.assertTrue(isinstance(new, Seq)) #Not MutableSeq!
00224         self.assertEqual(str(new), answer_str)
00225 
00226         new = feature.extract(UnknownSeq(len(parent_seq), parent_seq.alphabet))
00227         self.assertTrue(isinstance(new, UnknownSeq))
00228         self.assertEqual(len(new), len(answer_str))
00229         
00230         if _insdc_feature_location_string(feature, 1326) != location_str:
00231             #This is to avoid issues with the N^1 between feature which only
00232             #makes sense at the end of the sequence
00233             return
00234         #This template is DNA, but that will still be OK for protein features
00235         #as they have no strand information... but see below for strand fun
00236         rec = SeqIO.read(StringIO(gbk_template % location_str), "gb")
00237         self.assertEqual(1326, len(rec))
00238         self.assertEqual(2, len(rec.features))
00239         self.assertEqual(rec.features[0].type, "source")
00240         self.assertEqual(rec.features[1].type, "misc_feature")
00241         new_f = rec.features[1]
00242         self.assertEqual(location_str,
00243                          _insdc_feature_location_string(new_f,1326))
00244 
00245         #Checking the strand is tricky - on parsing a GenBank file
00246         #strand +1 is assumed, but our constructed features for the
00247         #unit test have mostly defaulted to strand None.
00248         self.assertEqual(len(feature.sub_features), len(new_f.sub_features))
00249         for f1, f2 in zip(feature.sub_features, new_f.sub_features):
00250             f1.type = "misc_feature" #hack as may not be misc_feature
00251             if f1.strand is None:
00252                 f1.strand = f2.strand #hack as described above
00253             self.assertEqual(f1.strand, f2.strand)
00254             self.assertTrue(compare_feature(f1,f2))
00255         feature.type = "misc_feature" #hack as may not be misc_feature
00256         if not feature.strand:
00257             feature.strand = new_f.strand #hack as above
00258         self.assertEqual(feature.strand, new_f.strand)
00259         self.assertTrue(compare_feature(feature, new_f))
00260         
00261         #Some feature method tests
00262         parent = "ACGT"*250
00263         s = feature.extract(parent)
00264         self.assertEqual(len(feature), len(s))
00265         for i in feature:
00266             self.assertTrue(i in feature)
00267         self.assertEqual(set(feature),
00268                          set(i for i in range(1000) if i in feature))
00269         if feature.strand == +1:
00270             self.assertEqual(s, "".join(parent[i] for i in feature))
00271             

Here is the call graph for this function:

Feature on DNA (join, mixed strand)

Definition at line 367 of file test_SeqIO_features.py.

00367 
00368     def test_mixed_strand_dna_join(self):
00369         """Feature on DNA (join, mixed strand)"""
00370         s = Seq("AAAAACCCCCTTTTTGGGGG", generic_dna)
00371         f1 = SeqFeature(FeatureLocation(5,10), strand=+1)
00372         f2 = SeqFeature(FeatureLocation(12,15), strand=-1)
00373         f = make_join_feature([f1,f2])
00374         self.check(s, f, "CCCCC"+reverse_complement("TTT"),
00375                    "join(6..10,complement(13..15))")

Here is the call graph for this function:

Feature on DNA (multi-join, mixed strand)

Definition at line 376 of file test_SeqIO_features.py.

00376 
00377     def test_mixed_strand_dna_multi_join(self):
00378         """Feature on DNA (multi-join, mixed strand)"""
00379         s = Seq("AAAAACCCCCTTTTTGGGGG", generic_dna)
00380         f1 = SeqFeature(FeatureLocation(5,10), strand=+1)
00381         f2 = SeqFeature(FeatureLocation(12,15), strand=-1)
00382         f3 = SeqFeature(FeatureLocation(BeforePosition(0),5), strand=+1)
00383         f = make_join_feature([f1,f2,f3])
00384         self.check(s, f, "CCCCC"+reverse_complement("TTT")+"AAAAA",
00385                    "join(6..10,complement(13..15),<1..5)")

Here is the call graph for this function:

Feature on protein (between location, zero length)

Definition at line 424 of file test_SeqIO_features.py.

00424 
00425     def test_protein_between(self):
00426         """Feature on protein (between location, zero length)"""
00427         s = Seq("ABCDEFGHIJKLMNOPQRSTUVWXYZ", generic_protein)
00428         f = SeqFeature(FeatureLocation(5,5))
00429         self.check(s, f, "", "5^6")

Here is the call graph for this function:

Feature on protein (join)

Definition at line 392 of file test_SeqIO_features.py.

00392 
00393     def test_protein_join(self):
00394         """Feature on protein (join)"""
00395         s = Seq("ABCDEFGHIJKLMNOPQRSTUVWXYZ", generic_protein)
00396         f1 = SeqFeature(FeatureLocation(5,10))
00397         f2 = SeqFeature(FeatureLocation(15,20))
00398         f = make_join_feature([f1,f2])
00399         self.check(s, f, "FGHIJ"+"PQRST", "join(6..10,16..20)")

Here is the call graph for this function:

Feature on protein (fuzzy join)

Definition at line 400 of file test_SeqIO_features.py.

00400 
00401     def test_protein_join_fuzzy(self):
00402         """Feature on protein (fuzzy join)"""
00403         s = Seq("ABCDEFGHIJKLMNOPQRSTUVWXYZ", generic_protein)
00404         f1 = SeqFeature(FeatureLocation(BeforePosition(5),10))
00405         f2 = SeqFeature(FeatureLocation(OneOfPosition(15, (ExactPosition(15),
00406                                                            ExactPosition(16))),
00407                                         AfterPosition(20)))
00408         f = make_join_feature([f1,f2])
00409         self.check(s, f, "FGHIJ"+"PQRST", "join(<6..10,one-of(16,17)..>20)")

Here is the call graph for this function:

Feature on protein (multi-join)

Definition at line 410 of file test_SeqIO_features.py.

00410 
00411     def test_protein_multi_join(self):
00412         """Feature on protein (multi-join)"""
00413         s = Seq("ABCDEFGHIJKLMNOPQRSTUVWXYZ", generic_protein)
00414         f1 = SeqFeature(FeatureLocation(1,2))
00415         f2 = SeqFeature(FeatureLocation(8,9))
00416         f3 = SeqFeature(FeatureLocation(14,16))
00417         f4 = SeqFeature(FeatureLocation(24,25))
00418         f5 = SeqFeature(FeatureLocation(19,20))
00419         f6 = SeqFeature(FeatureLocation(7,8))
00420         f7 = SeqFeature(FeatureLocation(14,15))
00421         f8 = SeqFeature(FeatureLocation(13,14))
00422         f = make_join_feature([f1,f2,f3,f4,f5,f6,f7,f8])
00423         self.check(s, f, "BIOPYTHON", "join(2,9,15..16,25,20,8,15,14)")

Here is the call graph for this function:

Feature on protein (one-of positions)

Definition at line 430 of file test_SeqIO_features.py.

00430 
00431     def test_protein_oneof(self):
00432         """Feature on protein (one-of positions)"""
00433         s = Seq("ABCDEFGHIJKLMNOPQRSTUVWXYZ", generic_protein)
00434         start = OneOfPosition(5, (ExactPosition(5),ExactPosition(7)))
00435         end = OneOfPosition(11, (ExactPosition(10),ExactPosition(11)))
00436         f = SeqFeature(FeatureLocation(start,10))
00437         self.check(s, f, "FGHIJ", "one-of(6,8)..10")
00438         f = SeqFeature(FeatureLocation(start,end))
00439         self.check(s, f, "FGHIJK", "one-of(6,8)..one-of(10,11)")
00440         f = SeqFeature(FeatureLocation(5,end))
00441         self.check(s, f, "FGHIJK", "6..one-of(10,11)")
00442 

Here is the call graph for this function:

Feature on protein (simple)

Definition at line 386 of file test_SeqIO_features.py.

00386 
00387     def test_protein_simple(self):
00388         """Feature on protein (simple)"""
00389         s = Seq("ABCDEFGHIJKLMNOPQRSTUVWXYZ", generic_protein)
00390         f = SeqFeature(FeatureLocation(5,10))
00391         self.check(s, f, "FGHIJ", "6..10")

Here is the call graph for this function:

Feature on DNA (simple, default strand)

Definition at line 280 of file test_SeqIO_features.py.

00280 
00281     def test_simple_dna(self):
00282         """Feature on DNA (simple, default strand)"""
00283         s = Seq("GATCRYWSMKHBVDN", generic_dna)
00284         f = SeqFeature(FeatureLocation(5,10))
00285         self.check(s, f, "YWSMK", "6..10")

Here is the call graph for this function:

Feature on DNA (join, strand +1)

Definition at line 332 of file test_SeqIO_features.py.

00332 
00333     def test_simple_dna_join(self):
00334         """Feature on DNA (join, strand +1)"""
00335         s = Seq("GATCRYWSMKHBVDN", generic_dna)
00336         f1 = SeqFeature(FeatureLocation(5,10), strand=1)
00337         f2 = SeqFeature(FeatureLocation(12,15), strand=1)
00338         f = make_join_feature([f1,f2])
00339         self.check(s, f, "YWSMKVDN", "join(6..10,13..15)")

Here is the call graph for this function:

Here is the caller graph for this function:

Feature on DNA (join, strand -1)

Definition at line 340 of file test_SeqIO_features.py.

00340 
00341     def test_simple_dna_join(self):
00342         """Feature on DNA (join, strand -1)"""
00343         s = Seq("AAAAACCCCCTTTTTGGGGG", generic_dna)
00344         f1 = SeqFeature(FeatureLocation(5,10), strand=-1)
00345         f2 = SeqFeature(FeatureLocation(12,15), strand=-1)
00346         f = make_join_feature([f1,f2])
00347         self.check(s, f, reverse_complement("CCCCC"+"TTT"),
00348                    "complement(join(6..10,13..15))")

Here is the call graph for this function:

Feature on DNA (join, strand -1, before position)

Definition at line 349 of file test_SeqIO_features.py.

00349 
00350     def test_simple_dna_join(self):
00351         """Feature on DNA (join, strand -1, before position)"""
00352         s = Seq("AAAAACCCCCTTTTTGGGGG", generic_dna)
00353         f1 = SeqFeature(FeatureLocation(BeforePosition(5),10), strand=-1)
00354         f2 = SeqFeature(FeatureLocation(12,15), strand=-1)
00355         f = make_join_feature([f1,f2])
00356         self.check(s, f, reverse_complement("CCCCC"+"TTT"),
00357                    "complement(join(<6..10,13..15))")

Here is the call graph for this function:

Feature on DNA (join, strand -1, after position)

Definition at line 358 of file test_SeqIO_features.py.

00358 
00359     def test_simple_dna_join_after(self):
00360         """Feature on DNA (join, strand -1, after position)"""
00361         s = Seq("AAAAACCCCCTTTTTGGGGG", generic_dna)
00362         f1 = SeqFeature(FeatureLocation(5,10), strand=-1)
00363         f2 = SeqFeature(FeatureLocation(12,AfterPosition(15)), strand=-1)
00364         f = make_join_feature([f1,f2])
00365         self.check(s, f, reverse_complement("CCCCC"+"TTT"),
00366                    "complement(join(6..10,13..>15))")

Here is the call graph for this function:

Feature on DNA (simple, strand 0)

Definition at line 304 of file test_SeqIO_features.py.

00304 
00305     def test_simple_dna_strand0(self):
00306         """Feature on DNA (simple, strand 0)"""
00307         s = Seq("GATCRYWSMKHBVDN", generic_dna)
00308         f = SeqFeature(FeatureLocation(5,10), strand=0)
00309         self.check(s, f, "YWSMK", "6..10")

Here is the call graph for this function:

Feature on DNA (simple, strand +1)

Definition at line 316 of file test_SeqIO_features.py.

00316 
00317     def test_simple_dna_strand1(self):
00318         """Feature on DNA (simple, strand +1)"""
00319         s = Seq("GATCRYWSMKHBVDN", generic_dna)
00320         f = SeqFeature(FeatureLocation(5,10), strand=1)
00321         self.assertEqual(f.strand, +1)
00322         self.assertEqual(f.location.strand, +1)
00323         self.check(s, f, "YWSMK", "6..10")
        

Here is the call graph for this function:

Feature on DNA (simple, strand -1)

Definition at line 324 of file test_SeqIO_features.py.

00324 
00325     def test_simple_dna_strand_minus(self):
00326         """Feature on DNA (simple, strand -1)"""
00327         s = Seq("GATCRYWSMKHBVDN", generic_dna)
00328         f = SeqFeature(FeatureLocation(5,10), strand=-1)
00329         self.assertEqual(f.strand, -1)
00330         self.assertEqual(f.location.strand, -1)
00331         self.check(s, f, "MKSWR", "complement(6..10)")

Here is the call graph for this function:

Feature on DNA (simple, strand None)

Definition at line 310 of file test_SeqIO_features.py.

00310 
00311     def test_simple_dna_strand_none(self):
00312         """Feature on DNA (simple, strand None)"""
00313         s = Seq("GATCRYWSMKHBVDN", generic_dna)
00314         f = SeqFeature(FeatureLocation(5,10), strand=None)
00315         self.check(s, f, "YWSMK", "6..10")

Here is the call graph for this function:

Feature on RNA (simple, default strand)

Definition at line 272 of file test_SeqIO_features.py.

00272 
00273     def test_simple_rna(self):
00274         """Feature on RNA (simple, default strand)"""
00275         s = Seq("GAUCRYWSMKHBVDN", generic_rna)
00276         f = SeqFeature(FeatureLocation(5,10))
00277         self.assertEqual(f.strand, None)
00278         self.assertEqual(f.location.strand, None)
00279         self.check(s, f, "YWSMK", "6..10")

Here is the call graph for this function:

Feature on DNA (single letter, default strand)

Definition at line 286 of file test_SeqIO_features.py.

00286 
00287     def test_single_letter_dna(self):
00288         """Feature on DNA (single letter, default strand)"""
00289         s = Seq("GATCRYWSMKHBVDN", generic_dna)
00290         f = SeqFeature(FeatureLocation(5,6))
00291         self.check(s, f, "Y", "6")

Here is the call graph for this function:

Feature on DNA (between location, zero length, default strand)

Definition at line 292 of file test_SeqIO_features.py.

00292 
00293     def test_zero_len_dna(self):
00294         """Feature on DNA (between location, zero length, default strand)"""
00295         s = Seq("GATCRYWSMKHBVDN", generic_dna)
00296         f = SeqFeature(FeatureLocation(5,5))
00297         self.check(s, f, "", "5^6")

Here is the call graph for this function:

Feature on DNA (between location at end, zero length, default strand)

Definition at line 298 of file test_SeqIO_features.py.

00298 
00299     def test_zero_len_dna_end(self):
00300         """Feature on DNA (between location at end, zero length, default strand)"""
00301         s = Seq("GATCRYWSMKHBVDN", generic_dna)
00302         f = SeqFeature(FeatureLocation(15,15))
00303         self.check(s, f, "", "15^1")

Here is the call graph for this function:


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