def test_transcription():
    test_dna = DNA('ATGATGGGCAGTGTCGAATTAAATCTGCGTGAGACAGAATTGTGTT' +
                   'TGGGACTACCAGGCGGTGATACAGTTGCACCAGTAACAGGAAACAA' +
                   'AAGAGGATTCTCTGAAACAGTAGATTTGAAACTTAATTTGAACAAT' +
                   'GAGCCAGCCAACAAGGAAGGTTCCACCACTCATGACGTCGTCACAT' +
                   'TTGATAGTAAAGAAAAGAGTGCGTGTCCAAAAGATCCAGCTAAGCC' +
                   'ACCTGCCAAGGCTCAAGTCGTCGGATGGCCACCTGTGAGATCTTAT' +
                   'AGAAAGAACGTAATGGTTTCTTGTCAGAAGTCCAGTGGTGGTCCTG' +
                   'AAGCAGCGGCTtgaaaa')
    reference_rna = RNA('AUGAUGGGCAGUGUCGAAUUAAAUCUGCGUGAGACAGAAUU' +
                        'GUGUUUGGGACUACCAGGCGGUGAUACAGUUGCACCAGUAA' +
                        'CAGGAAACAAAAGAGGAUUCUCUGAAACAGUAGAUUUGAAA' +
                        'CUUAAUUUGAACAAUGAGCCAGCCAACAAGGAAGGUUCCAC' +
                        'CACUCAUGACGUCGUCACAUUUGAUAGUAAAGAAAAGAGUG' +
                        'CGUGUCCAAAAGAUCCAGCUAAGCCACCUGCCAAGGCUCAA' +
                        'GUCGUCGGAUGGCCACCUGUGAGAUCUUAUAGAAAGAACGU' +
                        'AAUGGUUUCUUGUCAGAAGUCCAGUGGUGGUCCUGAAGCAG' +
                        'CGGCUugaaaa')
    # Basic transcription should work
    transcription_output = reaction.transcribe(test_dna)
    assert_equal(transcription_output, reference_rna)

    # Coding RNA should exclude anything after a stop codon
    coding_rna_output = reaction.coding_sequence(transcription_output)
    assert_equal(coding_rna_output, reference_rna[:-3])

    # Should fail is sequence lacks start codon or stop codon
    assert_raises(ValueError, reaction.coding_sequence,
                  reaction.transcribe(DNA('aaatag')))
    assert_raises(ValueError, reaction.coding_sequence,
                  reaction.transcribe(DNA('atgaaa')))
Beispiel #2
0
def test_multiple_priming():
    ''' test multiple binding sites '''

    current_path = os.path.dirname(__file__)
    template = seqio.read_dna(os.path.join(current_path,
                                           "pMODKan-HO-pACT1GEV.ape"))
    template = template.circularize()
    seq = DNA('cgccagggttttcccagtcacgac')
    template = template.linearize()
    template = template + seq + DNA("AGGCGTATGC") + seq
    template = (template + DNA("GGGGGGG") + seq.reverse_complement() +
                DNA("GGAAAG"))
    template = template.circularize()
    primer = Primer(seq, 50.6)
    matches = analysis.anneal(template, primer)
    fwd_matches, rev_matches = matches
    fwd_indices = [match[0] for match in fwd_matches]
    rev_indices = [match[0] for match in rev_matches]

    loc = template.locate(seq)

    assert_true(len(fwd_matches) == len(loc[0]))
    assert_true(len(rev_matches) == len(loc[1]))
    for match in loc[0]:
        assert_true(match + len(seq) in fwd_indices)
    for match in loc[1]:
        assert_true(match + len(seq) in rev_indices)
Beispiel #3
0
 def test_psti_cut(self):
     '''Test 3\' cutter.'''
     psti = RestrictionSite(DNA('CTGCAG'), (5, 1), name='PstI')
     assert_equal(
         reaction.digest(DNA('ACTGCAGA'), psti),
         [DNA('ACTGCA', bottom='----GT'),
          DNA('----GA', bottom='TCTGCA')])
Beispiel #4
0
class TestFeatures(object):
    '''Test features model using DNA object.'''
    def __init__(self):
        self.dna = DNA('ATGC') * 50
        self.apply_features()

    def apply_features(self):
        misc_feature = Feature('Misc Feature', 1, 20, 'misc_feature')
        misc_1_feature = Feature('Misc Feature', 1, 20, 'misc_feature',
                                 strand=1)
        coding_feature = Feature('Coding Feature', 21, 40, 'CDS')
        primer_feature = Feature('Primer Feature', 41, 60, 'primer_bind')
        promoter_feature = Feature('Promoter Feature', 61, 80, 'promoter')
        terminator_feature = Feature('Terminator Feature', 81, 100,
                                     'terminator')
        rbs_feature = Feature('RBS Feature', 101, 120, 'RBS')
        origin_feature = Feature('Origin Feature', 121, 140, 'rep_origin')
        utr3_feature = Feature("3'UTR Feature", 141, 160, "3'UTR")
        origin_feature2 = Feature('Origin Feature', 161, 180, 'rep_origin')

        input_features = [misc_feature, misc_1_feature, coding_feature,
                          primer_feature, promoter_feature, terminator_feature,
                          rbs_feature, origin_feature, utr3_feature,
                          origin_feature2]
        self.dna.features = input_features

    def test_good_features(self):
        for feature in self.dna.features:
            assert_true(feature.copy() in self.dna.features)

    def test_rev_comp(self):
        rev = self.dna.reverse_complement()
        for feature, rev_feature in zip(self.dna.features, rev.features):
            assert_not_equal(feature.strand, rev_feature.strand)
            assert_equal(len(self.dna) - feature.start, rev_feature.stop)
            assert_equal(len(self.dna) - feature.stop, rev_feature.start)

    def test_extract(self):
        test_utr3_feature = [feature for feature in self.dna.features if
                            feature.name == "3'UTR Feature"][0]
        extracted = self.dna.extract(test_utr3_feature)
        assert_equal(str(extracted), 'TGCATGCATGCATGCATGC')

    def test_getitem(self):
        subsequence = self.dna[30:100]
        remaining_features = [Feature('Primer Feature', 11, 30, 'primer_bind'),
                              Feature('Promoter Feature', 31, 50, 'promoter'),
                              Feature('Terminator Feature', 51, 70,
                                      'terminator')]

        assert_equal(subsequence.features, remaining_features)
        assert_false(self.dna[10].features)
        new_seq = DNA('ATGC', features=[Feature('A', 0, 0, 'misc_feature')])
        assert_equal(new_seq[0].features[0],
                     Feature('A', 0, 0, 'misc_feature'))

    def test_ne(self):
        '''Test != operator'''
        assert_true(self.dna.features[0] != self.dna.features[4])
        assert_false(self.dna.features[0] != self.dna.features[0])
Beispiel #5
0
 def test_ncoi_cut(self):
     '''Test standard TypeII cutter.'''
     ncoi = RestrictionSite(DNA('CCATGG'), (1, 5), name='NcoI')
     assert_equal(reaction.digest(self.dna, ncoi), [
         DNA('TGAC----', bottom='CATGGTCA'),
         DNA('CATGGAAA', bottom='TTTC----')
     ])
     assert_equal(reaction.digest(self.dna.circularize(), ncoi),
                  [DNA('CATGGAAATGAC----', bottom='CATGGTCATTTC----')])
Beispiel #6
0
 def test_palindrome(self):
     palindromic_seq_even = DNA('ATGCGCAT')
     nonpalindromic_seq_even = DNA('ATGCGCAA')
     almost_palindrome_odd = DNA('ATGCCAT')
     assert_true(palindromic_seq_even.is_palindrome())
     assert_false(nonpalindromic_seq_even.is_palindrome())
     assert_false(almost_palindrome_odd.is_palindrome())
Beispiel #7
0
def test_dimers():
    '''Test dimers function.'''
    anneal_f = DNA('gatcgatcgatacgatcgatatgcgat', stranded='ss')
    tm_f = 71.86183729637946
    primer_f = Primer(anneal_f, tm_f)

    anneal_r = DNA('atatcgatcatatcgcatatcgatcgtatcgat', stranded='ss')
    tm_r = 72.14300162714233
    primer_r = Primer(anneal_r, tm_r)

    dimer_output = analysis.dimers(primer_f, primer_r)

    assert_equal(dimer_output, 0.8529446)
Beispiel #8
0
def test_min_tm():
    current_path = os.path.dirname(__file__)
    template = seqio.read_dna(os.path.join(current_path,
                                           "pMODKan-HO-pACT1GEV.ape"))

    # Test forward priming
    # Tm should be ~40 C
    seq = DNA('CTTCTATCGAACAA')
    primer = Primer(seq, seq.tm())
    matches = analysis.anneal(template, primer, min_tm=60.0)
    assert_true(len(matches[0]) == 0)
    matches = analysis.anneal(template, primer, min_tm=30.0)
    assert_true(len(matches[0]) > 0)
Beispiel #9
0
def test_min_tm():
    current_path = os.path.dirname(__file__)
    template = seqio.read_dna(
        os.path.join(current_path, "pMODKan-HO-pACT1GEV.ape"))

    # Test forward priming
    # Tm should be ~40 C
    seq = DNA('CTTCTATCGAACAA')
    primer = Primer(seq, seq.tm())
    matches = analysis.anneal(template, primer, min_tm=60.0)
    assert_true(len(matches[0]) == 0)
    matches = analysis.anneal(template, primer, min_tm=30.0)
    assert_true(len(matches[0]) > 0)
Beispiel #10
0
def test_primers():
    '''Test primers function.'''
    seq = 'ATGGTGAGCAAGGGCGAGGAGCTGTTCACCGGGGTGGTGCCCATCCTGGTCGAGCTGGACGGC' + \
          'GACGTAAACGGCCACAAGTTCAGCGTGTCCGGCGAGGGCGAGGGCGATGCCACCTACGGCAAG' + \
          'CTGACCCTGAAGTTCATCTGCACCACCGGCAAGCTGCCCGTGCCCTGGCCCACCCTCGTGACC' + \
          'ACCTTCGGCTACGGCCTGCAGTGCTTCGCCCGCTACCCCGACCACATGAAGCAGCACGACTTC' + \
          'TTCAAGTCCGCCATGCCCGAAGGCTACGTCCAGGAGCGCACCATCTTCTTCAAGGACGACGGC' + \
          'AACTACAAGACCCGCGCCGAGGTGAAGTTCGAGGGCGACACCCTGGTGAACCGCATCGAGCTG' + \
          'AAGGGCATCGACTTCAAGGAGGACGGCAACATCCTGGGGCACAAGCTGGAGTACAACTACAAC' + \
          'AGCCACAACGTCTATATCATGGCCGACAAGCAGAAGAACGGCATCAAGGTGAACTTCAAGATC' + \
          'CGCCACAACATCGAGGACGGCAGCGTGCAGCTCGCCGACCACTACCAGCAGAACACCCCCATC' + \
          'GGCGACGGCCCCGTGCTGCTGCCCGACAACCACTACCTGAGCTACCAGTCCGCCCTGAGCAAA' + \
          'GACCCCAACGAGAAGCGCGATCACATGGTCCTGCTGGAGTTCGTGACCGCCGCCGGGATCACT' + \
          'CTCGGCATGGACGAGCTGTACAAGTAA'
    dna_seq = DNA(seq)
    primers_list = design.primers(dna_seq,
                                  tm=72,
                                  min_len=10,
                                  tm_undershoot=1,
                                  tm_overshoot=3,
                                  end_gc=False,
                                  tm_parameters='cloning',
                                  overhangs=None)
    primers = [str(x.primer()) for x in primers_list]
    assert_equals(primers,
                  ['ATGGTGAGCAAGGGCGAGGAG', 'TTACTTGTACAGCTCGTCCATGCCG'])
Beispiel #11
0
def test_find_repeats():
    input_sequence = DNA('atgatgccccgatagtagtagtag')
    expected = [('ATG', 2), ('GTA', 3), ('GAT', 2), ('AGT', 3), ('CCC', 2),
                ('TAG', 4)]

    output = analysis.repeats(input_sequence, 3)
    assert_equal(output, expected)
Beispiel #12
0
def test_near_index():
    '''Test binding near index for circular templates.'''
    current_path = os.path.dirname(__file__)
    template = seqio.read_dna(
        os.path.join(current_path, "pMODKan-HO-pACT1GEV.ape"))
    template = template.circularize()
    seq = DNA('aggccctttcgtctcgcgcgttt')
    primer = Primer(seq, 50.6)
    matches = analysis.anneal(template, primer)
    fwd_matches, rev_matches = matches
    fwd_indices = [match[0] for match in fwd_matches]
    rev_indices = [match[0] for match in rev_matches]

    loc = template.locate(seq)

    print fwd_matches
    print loc[0]
    print loc[1]
    assert_true(len(fwd_matches) == len(loc[0]))
    assert_true(len(rev_matches) == len(loc[1]))
    for match in loc[0]:
        expected = match + len(seq)
        if expected > len(template):
            expected -= len(template)
        assert_true(expected in fwd_indices)
    for match in loc[1]:
        expected = match + len(seq)
        if expected > len(template):
            expected -= len(template)
        assert_true(expected in rev_indices)
Beispiel #13
0
class TestDigest(object):
    '''Test digest function.'''
    def __init__(self):
        # Contains NcoI site
        self.dna = DNA('TGACCATGGAAA')

    def test_not_found(self):
        '''If site not found, should return input sequence in list.'''
        ecorv = RestrictionSite(DNA('GATATC'), (3, 3), name='EcoRV')
        assert_equal(self.dna, reaction.digest(self.dna, ecorv)[0])

    def test_ncoi_cut(self):
        '''Test standard TypeII cutter.'''
        ncoi = RestrictionSite(DNA('CCATGG'), (1, 5), name='NcoI')
        assert_equal(reaction.digest(self.dna, ncoi),
                     [DNA('TGAC----', bottom='CATGGTCA'),
                      DNA('CATGGAAA', bottom='TTTC----')])
        assert_equal(reaction.digest(self.dna.circularize(), ncoi),
                     [DNA('CATGGAAATGAC----', bottom='CATGGTCATTTC----')])

    def test_ecorv_cut(self):
        '''Test blunt-end cutter.'''
        ecorv = RestrictionSite(DNA('GATATC'), (3, 3), name='EcoRV')
        assert_equal(reaction.digest(DNA('GATATC'), ecorv),
                     [DNA('GAT'), DNA('ATC')])

    def test_psti_cut(self):
        '''Test 3\' cutter.'''
        psti = RestrictionSite(DNA('CTGCAG'), (5, 1), name='PstI')
        assert_equal(reaction.digest(DNA('ACTGCAGA'), psti),
                     [DNA('ACTGCA', bottom='----GT'),
                      DNA('----GA', bottom='TCTGCA')])
Beispiel #14
0
class TestDigest(object):
    '''Test digest function.'''
    def __init__(self):
        # Contains NcoI site
        self.dna = DNA('TGACCATGGAAA')

    def test_not_found(self):
        '''If site not found, should return input sequence in list.'''
        ecorv = RestrictionSite(DNA('GATATC'), (3, 3), name='EcoRV')
        assert_equal(self.dna, reaction.digest(self.dna, ecorv)[0])

    def test_ncoi_cut(self):
        '''Test standard TypeII cutter.'''
        ncoi = RestrictionSite(DNA('CCATGG'), (1, 5), name='NcoI')
        assert_equal(reaction.digest(self.dna, ncoi), [
            DNA('TGAC----', bottom='CATGGTCA'),
            DNA('CATGGAAA', bottom='TTTC----')
        ])
        assert_equal(reaction.digest(self.dna.circularize(), ncoi),
                     [DNA('CATGGAAATGAC----', bottom='CATGGTCATTTC----')])

    def test_ecorv_cut(self):
        '''Test blunt-end cutter.'''
        ecorv = RestrictionSite(DNA('GATATC'), (3, 3), name='EcoRV')
        assert_equal(reaction.digest(DNA('GATATC'), ecorv),
                     [DNA('GAT'), DNA('ATC')])

    def test_psti_cut(self):
        '''Test 3\' cutter.'''
        psti = RestrictionSite(DNA('CTGCAG'), (5, 1), name='PstI')
        assert_equal(
            reaction.digest(DNA('ACTGCAGA'), psti),
            [DNA('ACTGCA', bottom='----GT'),
             DNA('----GA', bottom='TCTGCA')])
Beispiel #15
0
def test_overhang():
    ''' test forward priming '''
    current_path = os.path.dirname(__file__)
    template = seqio.read_dna(
        os.path.join(current_path, "pMODKan-HO-pACT1GEV.ape"))
    seq = DNA('cgccagggttttcccagtcacgac')
    overhang = DNA('ggggggg')
    seq2 = overhang + seq
    primer = Primer(seq2, 50.6)
    matches = analysis.anneal(template, primer)
    fwd_matches, rev_matches = matches

    fwd_indices = [match[0] for match in fwd_matches]
    rev_indices = [match[0] for match in rev_matches]

    loc = template.locate(seq)

    assert_true(len(fwd_indices) == len(loc[0]))
    assert_true(len(rev_indices) == len(loc[1]))
    # FIXME: Add match length check for all these cases.
    for match in loc[0]:
        assert_true(match + len(seq) in fwd_indices)
    for match in loc[1]:
        assert_true(match + len(seq) in rev_indices)

    # Test forward priming.
    current_path = os.path.dirname(__file__)
    template = seqio.read_dna(
        os.path.join(current_path, "pMODKan-HO-pACT1GEV.ape"))
    seq = DNA('ACAAGAGAGATTGGGAAGGAAAGGATCA')
    overhang = DNA('ggggggg')
    seq2 = overhang + seq
    primer = Primer(seq2, 50.6)
    matches = analysis.anneal(template, primer)
    fwd_matches, rev_matches = matches
    fwd_indices = [match[0] for match in fwd_matches]
    rev_indices = [match[0] for match in rev_matches]

    loc = template.locate(seq)

    assert_true(len(fwd_indices) == len(loc[0]))
    assert_true(len(rev_indices) == len(loc[1]))

    for match in loc[0]:
        assert_true(match + len(seq) in fwd_indices)
    for match in loc[1]:
        assert_true(match + len(seq) in rev_indices)
Beispiel #16
0
def test_finnzymes():
    '''
    Tests finnzymes method output.

    '''

    melt = analysis.tm(DNA('ATGCGATAGCGATAGC'), parameters='cloning')
    assert_equal(melt, 55.2370030020752)
Beispiel #17
0
def test_utils():
    test_DNA = DNA('ATAGCGATACGAT')
    test_RNA = RNA('AUGCGAUAGCGAU')
    test_peptide = Peptide('msvkkkpvqg')
    test_str = 'msvkkkpvgq'

    assert_equal(analysis.utils.sequence_type(test_DNA), 'dna')
    assert_equal(analysis.utils.sequence_type(test_RNA), 'rna')
    assert_equal(analysis.utils.sequence_type(test_peptide), 'peptide')
    assert_raises(Exception, analysis.utils.sequence_type, test_str)
Beispiel #18
0
def test_basic():
    current_path = os.path.dirname(__file__)
    template = seqio.read_dna(
        os.path.join(current_path, "pMODKan-HO-pACT1GEV.ape"))
    # Test forward priming.
    seq = DNA('cgccagggttttcccagtcacgac')
    primer = Primer(seq, 50.6)
    matches = analysis.anneal(template, primer)
    fwd_matches, rev_matches = matches
    fwd_indices = [match[0] for match in fwd_matches]
    # fwd_lens = [match[1] for match in fwd_matches]
    rev_indices = [match[0] for match in rev_matches]
    # rev_lens = [match[1] for match in rev_matches]

    loc = template.locate(seq)

    assert_true(len(fwd_matches) == len(loc[0]))
    assert_true(len(rev_matches) == len(loc[1]))

    # Top strand matches
    for match in loc[0]:
        assert_true(match + len(seq) in fwd_indices)
    # Top strand matches
    for match in loc[1]:
        assert_true(match + len(seq) in rev_indices)

    # Test reverse priming
    seq = DNA('ACAAGAGAGATTGGGAAGGAAAGGATCA')
    primer = Primer(seq, 50.6)
    matches = analysis.anneal(template, primer)
    fwd_matches, rev_matches = matches
    fwd_indices = [match[0] for match in fwd_matches]
    rev_indices = [match[0] for match in rev_matches]

    loc = template.locate(seq)

    assert_true(len(fwd_indices) == len(loc[0]))
    assert_true(len(rev_indices) == len(loc[1]))
    for match in loc[0]:
        assert_true(match + len(seq) in fwd_indices)
    for match in loc[1]:
        assert_true(match + len(seq) in rev_indices)
Beispiel #19
0
    def test_getitem(self):
        subsequence = self.dna[30:100]
        remaining_features = [Feature('Primer Feature', 11, 30, 'primer_bind'),
                              Feature('Promoter Feature', 31, 50, 'promoter'),
                              Feature('Terminator Feature', 51, 70,
                                      'terminator')]

        assert_equal(subsequence.features, remaining_features)
        assert_false(self.dna[10].features)
        new_seq = DNA('ATGC', features=[Feature('A', 0, 0, 'misc_feature')])
        assert_equal(new_seq[0].features[0],
                     Feature('A', 0, 0, 'misc_feature'))
Beispiel #20
0
def test_multiple_priming():
    ''' test multiple binding sites '''

    current_path = os.path.dirname(__file__)
    template = seqio.read_dna(
        os.path.join(current_path, "pMODKan-HO-pACT1GEV.ape"))
    template = template.circularize()
    seq = DNA('cgccagggttttcccagtcacgac')
    template = template.linearize()
    template = template + seq + DNA("AGGCGTATGC") + seq
    template = (template + DNA("GGGGGGG") + seq.reverse_complement() +
                DNA("GGAAAG"))
    template = template.circularize()
    primer = Primer(seq, 50.6)
    matches = analysis.anneal(template, primer)
    fwd_matches, rev_matches = matches
    fwd_indices = [match[0] for match in fwd_matches]
    rev_indices = [match[0] for match in rev_matches]

    loc = template.locate(seq)

    assert_true(len(fwd_matches) == len(loc[0]))
    assert_true(len(rev_matches) == len(loc[1]))
    for match in loc[0]:
        assert_true(match + len(seq) in fwd_indices)
    for match in loc[1]:
        assert_true(match + len(seq) in rev_indices)
Beispiel #21
0
 def test_palindrome(self):
     palindromic_seq_even = DNA('ATGCGCAT')
     nonpalindromic_seq_even = DNA('ATGCGCAA')
     almost_palindrome_odd = DNA('ATGCCAT')
     assert_true(palindromic_seq_even.is_palindrome())
     assert_false(nonpalindromic_seq_even.is_palindrome())
     assert_false(almost_palindrome_odd.is_palindrome())
Beispiel #22
0
def test_convert_sequence():
    '''Tests DNA translation function.'''

    seq = 'ATGGTGAGCAAGGGCGAGGAGCTGTTCACCGGGGTGGTGCCCATCCTGGTCGAGCTGGACGGC' + \
          'GACGTAAACGGCCACAAGTTCAGCGTGTCCGGCGAGGGCGAGGGCGATGCCACCTACGGCAAG' + \
          'CTGACCCTGAAGTTCATCTGCACCACCGGCAAGCTGCCCGTGCCCTGGCCCACCCTCGTGACC' + \
          'ACCTTCGGCTACGGCCTGCAGTGCTTCGCCCGCTACCCCGACCACATGAAGCAGCACGACTTC' + \
          'TTCAAGTCCGCCATGCCCGAAGGCTACGTCCAGGAGCGCACCATCTTCTTCAAGGACGACGGC' + \
          'AACTACAAGACCCGCGCCGAGGTGAAGTTCGAGGGCGACACCCTGGTGAACCGCATCGAGCTG' + \
          'AAGGGCATCGACTTCAAGGAGGACGGCAACATCCTGGGGCACAAGCTGGAGTACAACTACAAC' + \
          'AGCCACAACGTCTATATCATGGCCGACAAGCAGAAGAACGGCATCAAGGTGAACTTCAAGATC' + \
          'CGCCACAACATCGAGGACGGCAGCGTGCAGCTCGCCGACCACTACCAGCAGAACACCCCCATC' + \
          'GGCGACGGCCCCGTGCTGCTGCCCGACAACCACTACCTGAGCTACCAGTCCGCCCTGAGCAAA' + \
          'GACCCCAACGAGAAGCGCGATCACATGGTCCTGCTGGAGTTCGTGACCGCCGCCGGGATCACT' + \
          'CTCGGCATGGACGAGCTGTACAAGTAA'
    dna = DNA(seq)
    prot = 'MVSKGEELFTGVVPILVELDGDVNGHKFSVSGEGEGDATYGKLTLKFICTTGKLPVPWPTLV' + \
           'TTFGYGLQCFARYPDHMKQHDFFKSAMPEGYVQERTIFFKDDGNYKTRAEVKFEGDTLVNRI' + \
           'ELKGIDFKEDGNILGHKLEYNYNSHNVYIMADKQKNGIKVNFKIRHNIEDGSVQLADHYQQN' + \
           'TPIGDGPVLLPDNHYLSYQSALSKDPNEKRDHMVLLEFVTAAGITLGMDELYK'
    rna = reaction.utils.convert_sequence(dna, 'rna')
    r_trans = reaction.utils.convert_sequence(rna, 'dna')
    trans = reaction.utils.convert_sequence(rna, 'peptide')
    assert_equal(str(trans), prot)
    assert_equal(str(r_trans), seq)
    assert_raises(ValueError, reaction.utils.convert_sequence, seq, 'rna')

    # Gapped sequence shouldfail
    assert_raises(ValueError, reaction.utils.convert_sequence, DNA('atg-'),
                  'rna')

    # Sequence without stop codon should still work
    nostop_dna = DNA('atgaaaaaaaaaaaa')
    nostop_rna = reaction.utils.convert_sequence(nostop_dna, 'rna')
    nostop_peptide = reaction.utils.convert_sequence(nostop_rna, 'peptide')
    assert_equal(str(nostop_rna), 'AUGAAAAAAAAAAAA')
    assert_equal(str(nostop_peptide), 'MKKKK')

    assert_raises(ValueError, reaction.utils.convert_sequence, 'duck', 'rna')
Beispiel #23
0
def test_min_primer_length():
    current_path = os.path.dirname(__file__)
    template = seqio.read_dna(
        os.path.join(current_path, "pMODKan-HO-pACT1GEV.ape"))

    # Test forward priming
    seq = DNA('cgccagggttttcccagtcacgac')
    seq = seq[:15]
    primer = Primer(seq, 50.6)
    assert_raises(analysis._sequence.anneal.PrimerLengthError,
                  analysis.anneal,
                  template,
                  primer,
                  min_len=16)
Beispiel #24
0
def test_no_priming():
    ''' test no priming '''

    current_path = os.path.dirname(__file__)
    template = seqio.read_dna(
        os.path.join(current_path, "pMODKan-HO-pACT1GEV.ape"))
    seq = DNA('ggaggagggcggcgaggcgagcgacggaggggga')
    primer = Primer(seq, 50.6)
    matches = analysis.anneal(template, primer)
    fwd_matches, rev_matches = matches
    loc = template.locate(seq)
    assert_true(len(fwd_matches) == len(loc[0]))
    assert_true(len(rev_matches) == len(loc[1]))
    for match in loc[0]:
        assert_true(match + len(seq) in fwd_matches)
    for match in loc[1]:
        assert_true(match + len(seq) in rev_matches)
Beispiel #25
0
def test_overlapping_overlaps():
    '''
    Sometimes, an assembly produces a result with 'overlapping overlaps' -
    not ideal. This should eventually be replaced by a catchable exception or
    prevented outright.

    '''

    test_seq = DNA('ATCAATACTTATTACGATATATATAT' * 34)
    oligo_n_assembly = design.OligoAssembly(test_seq,
                                            tm=65,
                                            length_range=(80, 150),
                                            require_even=True,
                                            start_5=True,
                                            overlap_min=20,
                                            oligo_number=10)
    oligo_n_assembly.design_assembly()
    assert_true(type(oligo_n_assembly.warning) == str)
Beispiel #26
0
def test_reverse_transcription():
    test_rna = RNA('AUGAUGGGCAGUGUCGAAUUAAAUCUGCGUGAGACAGAAUU' +
                   'GUGUUUGGGACUACCAGGCGGUGAUACAGUUGCACCAGUAA' +
                   'CAGGAAACAAAAGAGGAUUCUCUGAAACAGUAGAUUUGAAA' +
                   'CUUAAUUUGAACAAUGAGCCAGCCAACAAGGAAGGUUCCAC' +
                   'CACUCAUGACGUCGUCACAUUUGAUAGUAAAGAAAAGAGUG' +
                   'CGUGUCCAAAAGAUCCAGCUAAGCCACCUGCCAAGGCUCAA' +
                   'GUCGUCGGAUGGCCACCUGUGAGAUCUUAUAGAAAGAACGU' +
                   'AAUGGUUUCUUGUCAGAAGUCCAGUGGUGGUCCUGAAGCAG' + 'CGGCUugaaaa')
    ref_dna = DNA('ATGATGGGCAGTGTCGAATTAAATCTGCGTGAGACAGAATTGTGTT' +
                  'TGGGACTACCAGGCGGTGATACAGTTGCACCAGTAACAGGAAACAA' +
                  'AAGAGGATTCTCTGAAACAGTAGATTTGAAACTTAATTTGAACAAT' +
                  'GAGCCAGCCAACAAGGAAGGTTCCACCACTCATGACGTCGTCACAT' +
                  'TTGATAGTAAAGAAAAGAGTGCGTGTCCAAAAGATCCAGCTAAGCC' +
                  'ACCTGCCAAGGCTCAAGTCGTCGGATGGCCACCTGTGAGATCTTAT' +
                  'AGAAAGAACGTAATGGTTTCTTGTCAGAAGTCCAGTGGTGGTCCTG' +
                  'AAGCAGCGGCTtgaaaa')

    # Basic transcription should work
    r_transcription = reaction.reverse_transcribe(test_rna)
    assert_equal(r_transcription, ref_dna)
Beispiel #27
0
def test_gibson_primers():
    '''Test gibson_primers function.'''
    # Fuse tdh3 promoter sequence to yfp (trimmed for readability)
    tdh3_3prime = DNA('aaccagttccctgaaattattcccctacttgactaataagtat' +
                      'ataaagacggtaggtattgattgtaattctgtaaatctatttc' +
                      'ttaaacttc')
    yfp_nterm = DNA('atggtgagcaagggcgaggagctgttcaccggggtggtgcccatc' +
                    'ctggtcgagctggacggcgacgtaaacggccacaagttcagcgtg' +
                    'tccggcgagggcgagggcgatgccacctacggcaagctgaccctg' + 'aag')
    # Expected annealing sequences and their Tms
    fwd_anneal = DNA('atggtgagcaagggcg')
    fwd_tm = 64.64172107821065
    rev_anneal = DNA('gaagtttaagaaatagatttacagaattacaatcaatac')
    rev_tm = 64.24536287254085
    # Expected overlaps
    all_right = DNA('TCGCCCTTGCTCACCAT')
    all_left = DNA('GGTATTGATTGTAATTCTGTAAATCTATTTCTTAAACTTC')
    mixed_fwd = DNA('TTCTTAAACTTC')
    mixed_rev = DNA('CCTTGCTCACCAT')
    # Design primers - with homology all on left side, right side, or mixed
    # All on the 'right' - i.e. fwd primer
    right = design.gibson_primers(tdh3_3prime, yfp_nterm, 'right')
    right_rev = Primer(rev_anneal, tm=rev_tm, overhang=all_right)
    right_fwd = Primer(fwd_anneal, tm=fwd_tm)
    assert_equal(right, (right_rev, right_fwd))
    # All on the 'left' - i.e. rev primer
    left = design.gibson_primers(tdh3_3prime, yfp_nterm, 'left')
    left_rev = Primer(rev_anneal, tm=rev_tm)
    left_fwd = Primer(fwd_anneal, tm=fwd_tm, overhang=all_left)
    assert_equal(left, (left_rev, left_fwd))
    # On both primers
    mixed = design.gibson_primers(tdh3_3prime, yfp_nterm, 'mixed')
    mixed_primer1 = Primer(rev_anneal, tm=rev_tm, overhang=mixed_rev)
    mixed_primer2 = Primer(fwd_anneal, tm=fwd_tm, overhang=mixed_fwd)
    assert_equal(mixed, (mixed_primer1, mixed_primer2))

    assert_raises(ValueError, design.gibson_primers, tdh3_3prime, yfp_nterm,
                  'duck')
def test_structure_windows():
    '''Tests StructureWindows class in structure_windows.'''

    seq = 'atggtgagcaagggcgaggagctgttcaccggggtggtgcccatcctggtcgagctggacggc' + \
          'gacgtaaacggccacaagttcagcgtgtccggcgagggcgagggcgatgccacctacggcaag' + \
          'ctgaccctgaagttcatctgcaccaccggcaagctgcccgtgccctggcccaccctcgtgacc' + \
          'accttcggctacggcctgcagtgcttcgcccgctaccccgaccacatgaagcagcacgacttc' + \
          'ttcaagtccgccatgcccgaaggctacgtccaggagcgcaccatcttcttcaaggacgacggc' + \
          'aactacaagacccgcgccgaggtgaagttcgagggcgacaccctggtgaaccgcatcgagctg' + \
          'aagggcatcgacttcaaggaggacggcaacatcctggggcacaagctggagtacaactacaac' + \
          'agccacaacgtctatatcatggccgacaagcagaagaacggcatcaaggtgaacttcaagatc' + \
          'cgccacaacatcgaggacggcagcgtgcagctcgccgaccactaccagcagaacacccccatc' + \
          'ggcgacggccccgtgctgctgcccgacaaccactacctgagctaccagtccgccctgagcaaa' + \
          'gaccccaacgagaagcgcgatcacatggtcctgctggagttcgtgaccgccgccgggatcact' + \
          'ctcggcatggacgagctgtacaagtaa'
    dna_seq = DNA(seq)
    walker = analysis.StructureWindows(dna_seq)
    walker.windows(window_size=60, context_len=90, step=10)
    assert_equal(walker.scores,
                 (0.578570075,
                  0.5928413833333335,
                  0.5535072916666667,
                  0.5425574666666667,
                  0.6028716333333335,
                  0.5907444666666667,
                  0.5532209166666666,
                  0.5882098916666667,
                  0.6471799,
                  0.6957834999999999,
                  0.6209094583333334,
                  0.5929873583333332,
                  0.6117790833333332,
                  0.6116499166666667,
                  0.5987705999999998,
                  0.6439044999999999,
                  0.6817365833333334,
                  0.6488576499999998,
                  0.6900404249999998,
                  0.6657639999999999,
                  0.7083993333333333,
                  0.6360369916666666,
                  0.6452116666666665,
                  0.6395126666666666,
                  0.6288818333333333,
                  0.6351839999999999,
                  0.6463396666666666,
                  0.6717609166666665,
                  0.67853025,
                  0.7012450833333332,
                  0.6620117499999998,
                  0.7250783333333332,
                  0.6995034166666668,
                  0.7386933333333333,
                  0.7494905833333333,
                  0.7247731666666668,
                  0.7510857500000001,
                  0.7458025000000003,
                  0.7434455,
                  0.6702263583333334,
                  0.6390452499999999,
                  0.6503500249999998,
                  0.646285175,
                  0.606586825,
                  0.5707148,
                  0.644573625,
                  0.6644399750000001,
                  0.6716777749999999,
                  0.6807071583333334))
Beispiel #29
0
class TestDNA(object):
    '''Testing class for DNA'''
    def __init__(self):
        self.test_dna = DNA('atgc')

    def test_reverse_complement(self):
        assert_equal(str(self.test_dna.reverse_complement()), 'GCAT')

    def test_linearize(self):
        circ_dna = self.test_dna.circularize()
        assert_equal(str(circ_dna.linearize()), 'ATGC')
        assert_equal(str(circ_dna.linearize(0)), 'ATGC')
        assert_equal(str(circ_dna.linearize(1)), 'TGCA')
        assert_equal(str(circ_dna.linearize(2)), 'GCAT')
        assert_equal(str(circ_dna.linearize(3)), 'CATG')
        assert_equal(str(circ_dna.linearize(-1)), 'CATG')
        assert_raises(ValueError, circ_dna.linearize().linearize)

    def test_to_ss_ds(self):
        assert_equal(self.test_dna.to_ds(), self.test_dna)
        ss_dna = self.test_dna.to_ss()
        assert_equal(ss_dna.stranded, 'ss')
        ds_dna = self.test_dna.to_ds()
        assert_equal(ds_dna.stranded, 'ds')
        assert_equal(ds_dna.top(), str(ss_dna))

        ds_to_ss_to_ds = self.test_dna.to_ss().to_ds()
        assert_equal(self.test_dna, ds_to_ss_to_ds)

        empty_top = reaction.three_resect(self.test_dna, 400)
        assert_equal(empty_top.to_ds(), self.test_dna)

    def test_locate(self):
        assert_equal(self.test_dna.locate('a'), [[0], [2]])
        assert_equal(self.test_dna.locate('at'), [[0], [2]])
        assert_equal(self.test_dna.locate('gc'), [[2], [0]])
        assert_equal(self.test_dna.locate('atgg'), [[], []])
        # Circular DNA tests
        assert_equal(self.test_dna.circularize().locate('a'), [[0], [2]])
        assert_equal(self.test_dna.circularize().locate('at'), [[0], [2]])
        assert_equal(self.test_dna.circularize().locate('gc'), [[2], [0]])
        assert_equal(self.test_dna.circularize().locate('atgg'), [[], []])

    def test_copy(self):
        assert_equal(self.test_dna, self.test_dna.copy())

    def test_palindrome(self):
        palindromic_seq_even = DNA('ATGCGCAT')
        nonpalindromic_seq_even = DNA('ATGCGCAA')
        almost_palindrome_odd = DNA('ATGCCAT')
        assert_true(palindromic_seq_even.is_palindrome())
        assert_false(nonpalindromic_seq_even.is_palindrome())
        assert_false(almost_palindrome_odd.is_palindrome())

    def test_getitem(self):
        assert_equal(str(self.test_dna[0]), 'A')
        assert_equal(str(self.test_dna[1]), 'T')
        assert_equal(str(self.test_dna[2]), 'G')
        assert_equal(str(self.test_dna[3]), 'C')
        assert_equal(str(self.test_dna[-1]), 'C')

    def test_delitem(self):
        copy0 = self.test_dna.copy()
        del copy0[0]
        assert_equal(str(copy0), 'TGC')
        copy1 = self.test_dna.copy()
        del copy1[1]
        assert_equal(str(copy1), 'AGC')
        copy2 = self.test_dna.copy()
        del copy2[2]
        assert_equal(str(copy2), 'ATC')
        copy3 = self.test_dna.copy()
        del copy3[3]
        assert_equal(str(copy3), 'ATG')
        copy_1 = self.test_dna.copy()
        del copy_1[-1]
        assert_equal(str(copy_1), 'ATG')

    def test_setitem(self):
        copy0 = self.test_dna.copy()
        copy0[0] = 't'
        assert_equal(str(copy0), 'TTGC')
        copy1 = self.test_dna.copy()
        copy1[1] = 'a'
        assert_equal(str(copy1), 'AAGC')
        copy2 = self.test_dna.copy()
        copy2[2] = 'a'
        assert_equal(str(copy2), 'ATAC')
        copy3 = self.test_dna.copy()
        copy3[3] = 'a'
        assert_equal(str(copy3), 'ATGA')
        copy_1 = self.test_dna.copy()
        copy_1[-1] = 'a'
        assert_equal(str(copy_1), 'ATGA')

        def set_gap(seq):
            seq[2] = '-'

        assert_raises(ValueError, set_gap, self.test_dna)

    def test_repr(self):
        expected_repr = 'linear dsDNA:\nATGC\nTACG'
        assert_equal(repr(self.test_dna), expected_repr)

        expected_circ_repr = 'circular dsDNA:\nATGC\nTACG'
        assert_equal(repr(self.test_dna.circularize()), expected_circ_repr)

        repr_1 = 'linear dsDNA:\nATGCATGCATGCATGCATGCATGCATGCATGCATGCATGC ... '
        repr_2 = 'ATGCATGCATGCATGCATGCATGCATGCATGCATGCATGC\n'
        repr_3 = 'TACGTACGTACGTACGTACGTACGTACGTACGTACGTACG ... '
        repr_4 = 'TACGTACGTACGTACGTACGTACGTACGTACGTACGTACG'
        expected_long_repr = repr_1 + repr_2 + repr_3 + repr_4
        assert_equal(repr(self.test_dna * 50), expected_long_repr)

    def test_str(self):
        assert_equal(str(self.test_dna), 'ATGC')

    def test_len(self):
        assert_equal(len(self.test_dna), 4)

    def test_add(self):
        assert_equal(str(self.test_dna + self.test_dna), 'ATGCATGC')
        assert_equal(str(self.test_dna.to_ss() + self.test_dna.to_ss()),
                     'ATGCATGC')

    def test_radd(self):
        assert_equal(str(sum([self.test_dna, self.test_dna])), 'ATGCATGC')

        def radd_800(seq):
            return 800 + seq

        assert_raises(TypeError, radd_800, self.test_dna)

    def test_mul(self):
        assert_equal(str(self.test_dna * 4), 'ATGCATGCATGCATGC')

        def mul_float(seq):
            return seq * 7.56

        assert_raises(TypeError, mul_float, self.test_dna)

        # TODO: reimplement this test using manual sequence input
        # def mul_incompatible(seq):
        #     return seq * 3

        # incompatible_seq = self.test_dna.copy()
        # incompatible_seq = incompatible_seq.five_resect(1)
        # incompatible_seq = incompatible_seq.reverse_complement()
        # incompatible_seq = incompatible_seq.five_resect(1)
        # incompatible_seq = incompatible_seq.reverse_complement()
        # assert_raises(Exception, mul_incompatible, incompatible_seq)

    def test_eq(self):
        assert_true(self.test_dna == DNA('atgc'))

    def test_ne(self):
        assert_true(self.test_dna != DNA('aagc'))

    def test_contains(self):
        assert_true('a' in self.test_dna)
        assert_true('t' in self.test_dna)
        assert_true('g' in self.test_dna)
        assert_true('c' in self.test_dna)
        assert_false('u' in self.test_dna)

    def test_flip(self):
        flipped = self.test_dna.flip()
        assert_equal(str(self.test_dna), flipped._bottom)
        assert_equal(self.test_dna._bottom, str(flipped))
Beispiel #30
0
 def __init__(self):
     self.test_dna = DNA('atgc')
Beispiel #31
0
 def __init__(self):
     self.ecorv = RestrictionSite(DNA('GATATC'), (3, 3), name='EcoRV')
     self.foki = RestrictionSite(DNA('GGATG'), (14, 18), name='FokI')
Beispiel #32
0
 def __init__(self):
     # Contains NcoI site
     self.dna = DNA('TGACCATGGAAA')
Beispiel #33
0
class TestFeatures(object):
    '''Test features model using DNA object.'''
    def __init__(self):
        self.dna = DNA('ATGC') * 50
        self.apply_features()

    def apply_features(self):
        misc_feature = Feature('Misc Feature', 1, 20, 'misc_feature')
        misc_1_feature = Feature('Misc Feature',
                                 1,
                                 20,
                                 'misc_feature',
                                 strand=1)
        coding_feature = Feature('Coding Feature', 21, 40, 'CDS')
        primer_feature = Feature('Primer Feature', 41, 60, 'primer_bind')
        promoter_feature = Feature('Promoter Feature', 61, 80, 'promoter')
        terminator_feature = Feature('Terminator Feature', 81, 100,
                                     'terminator')
        rbs_feature = Feature('RBS Feature', 101, 120, 'RBS')
        origin_feature = Feature('Origin Feature', 121, 140, 'rep_origin')
        utr3_feature = Feature("3'UTR Feature", 141, 160, "3'UTR")
        origin_feature2 = Feature('Origin Feature', 161, 180, 'rep_origin')

        input_features = [
            misc_feature, misc_1_feature, coding_feature, primer_feature,
            promoter_feature, terminator_feature, rbs_feature, origin_feature,
            utr3_feature, origin_feature2
        ]
        self.dna.features = input_features

    def test_good_features(self):
        for feature in self.dna.features:
            assert_true(feature.copy() in self.dna.features)

    def test_rev_comp(self):
        rev = self.dna.reverse_complement()
        for feature, rev_feature in zip(self.dna.features, rev.features):
            assert_not_equal(feature.strand, rev_feature.strand)
            assert_equal(len(self.dna) - feature.start, rev_feature.stop)
            assert_equal(len(self.dna) - feature.stop, rev_feature.start)

    def test_extract(self):
        test_utr3_feature = [
            feature for feature in self.dna.features
            if feature.name == "3'UTR Feature"
        ][0]
        extracted = self.dna.extract(test_utr3_feature)
        assert_equal(str(extracted), 'TGCATGCATGCATGCATGC')

    def test_getitem(self):
        subsequence = self.dna[30:100]
        remaining_features = [
            Feature('Primer Feature', 11, 30, 'primer_bind'),
            Feature('Promoter Feature', 31, 50, 'promoter'),
            Feature('Terminator Feature', 51, 70, 'terminator')
        ]

        assert_equal(subsequence.features, remaining_features)
        assert_false(self.dna[10].features)
        new_seq = DNA('ATGC', features=[Feature('A', 0, 0, 'misc_feature')])
        assert_equal(new_seq[0].features[0], Feature('A', 0, 0,
                                                     'misc_feature'))

    def test_ne(self):
        '''Test != operator'''
        assert_true(self.dna.features[0] != self.dna.features[4])
        assert_false(self.dna.features[0] != self.dna.features[0])
Beispiel #34
0
 def __init__(self):
     self.dna = DNA('ATGC') * 50
     self.apply_features()
Beispiel #35
0
def test_stranded_init():
    ss_dna = DNA('atgc', stranded='ss')
    assert_true(all([base == '-' for base in ss_dna.bottom()]))

    ds_dna = DNA('atgc')
    assert_equal(str(ds_dna), ds_dna.reverse_complement().bottom())
Beispiel #36
0
def test_stranded_complemented():
    ss_dna = DNA('atgc', stranded='ss')
    r_ss_dna = ss_dna.reverse_complement()
    assert_equal(r_ss_dna.top(), 'GCAT')
    assert_equal(r_ss_dna.bottom(), '----')
Beispiel #37
0
def test_stranded_init():
    ss_dna = DNA('atgc', stranded='ss')
    assert_true(all([base == '-' for base in ss_dna.bottom()]))

    ds_dna = DNA('atgc')
    assert_equal(str(ds_dna), ds_dna.reverse_complement().bottom())
Beispiel #38
0
 def __init__(self):
     self.test_dna = DNA('atgc')
Beispiel #39
0
class TestDNA(object):
    '''Testing class for DNA'''
    def __init__(self):
        self.test_dna = DNA('atgc')

    def test_reverse_complement(self):
        assert_equal(str(self.test_dna.reverse_complement()), 'GCAT')

    def test_linearize(self):
        circ_dna = self.test_dna.circularize()
        assert_equal(str(circ_dna.linearize()), 'ATGC')
        assert_equal(str(circ_dna.linearize(0)), 'ATGC')
        assert_equal(str(circ_dna.linearize(1)), 'TGCA')
        assert_equal(str(circ_dna.linearize(2)), 'GCAT')
        assert_equal(str(circ_dna.linearize(3)), 'CATG')
        assert_equal(str(circ_dna.linearize(-1)), 'CATG')
        assert_raises(ValueError, circ_dna.linearize().linearize)

    def test_locate(self):
        assert_equal(self.test_dna.locate('a'), [[0], [2]])
        assert_equal(self.test_dna.locate('at'), [[0], [2]])
        assert_equal(self.test_dna.locate('gc'), [[2], [0]])
        assert_equal(self.test_dna.locate('atgg'), [[], []])
        # Circular DNA tests
        assert_equal(self.test_dna.circularize().locate('a'), [[0], [2]])
        assert_equal(self.test_dna.circularize().locate('at'), [[0], [2]])
        assert_equal(self.test_dna.circularize().locate('gc'), [[2], [0]])
        assert_equal(self.test_dna.circularize().locate('atgg'), [[], []])

    def test_copy(self):
        assert_equal(self.test_dna, self.test_dna.copy())

    def test_palindrome(self):
        palindromic_seq_even = DNA('ATGCGCAT')
        nonpalindromic_seq_even = DNA('ATGCGCAA')
        almost_palindrome_odd = DNA('ATGCCAT')
        assert_true(palindromic_seq_even.is_palindrome())
        assert_false(nonpalindromic_seq_even.is_palindrome())
        assert_false(almost_palindrome_odd.is_palindrome())

    def test_getitem(self):
        assert_equal(str(self.test_dna[0]), 'A')
        assert_equal(str(self.test_dna[1]), 'T')
        assert_equal(str(self.test_dna[2]), 'G')
        assert_equal(str(self.test_dna[3]), 'C')
        assert_equal(str(self.test_dna[-1]), 'C')

    def test_delitem(self):
        copy0 = self.test_dna.copy()
        del copy0[0]
        assert_equal(str(copy0), 'TGC')
        copy1 = self.test_dna.copy()
        del copy1[1]
        assert_equal(str(copy1), 'AGC')
        copy2 = self.test_dna.copy()
        del copy2[2]
        assert_equal(str(copy2), 'ATC')
        copy3 = self.test_dna.copy()
        del copy3[3]
        assert_equal(str(copy3), 'ATG')
        copy_1 = self.test_dna.copy()
        del copy_1[-1]
        assert_equal(str(copy_1), 'ATG')

    def test_setitem(self):
        copy0 = self.test_dna.copy()
        copy0[0] = 't'
        assert_equal(str(copy0), 'TTGC')
        copy1 = self.test_dna.copy()
        copy1[1] = 'a'
        assert_equal(str(copy1), 'AAGC')
        copy2 = self.test_dna.copy()
        copy2[2] = 'a'
        assert_equal(str(copy2), 'ATAC')
        copy3 = self.test_dna.copy()
        copy3[3] = 'a'
        assert_equal(str(copy3), 'ATGA')
        copy_1 = self.test_dna.copy()
        copy_1[-1] = 'a'
        assert_equal(str(copy_1), 'ATGA')

        def set_gap(seq):
            seq[2] = '-'
        assert_raises(ValueError, set_gap, self.test_dna)

    def test_repr(self):
        expected_repr = 'ATGC\nTACG'
        assert_equal(repr(self.test_dna), expected_repr)

        expected_circ_repr = 'ATGC\nTACG'
        assert_equal(repr(self.test_dna.circularize()), expected_circ_repr)

        repr_1 = 'ATGCATGCATGCATGCATGCATGCATGCATGCATGCATGC ... '
        repr_2 = 'ATGCATGCATGCATGCATGCATGCATGCATGCATGCATGC\n'
        repr_3 = 'TACGTACGTACGTACGTACGTACGTACGTACGTACGTACG ... '
        repr_4 = 'TACGTACGTACGTACGTACGTACGTACGTACGTACGTACG'
        expected_long_repr = repr_1 + repr_2 + repr_3 + repr_4
        assert_equal(repr(self.test_dna * 50), expected_long_repr)

    def test_str(self):
        assert_equal(str(self.test_dna), 'ATGC')

    def test_len(self):
        assert_equal(len(self.test_dna), 4)

    def test_add(self):
        assert_equal(str(self.test_dna + self.test_dna), 'ATGCATGC')

    def test_radd(self):
        assert_equal(str(sum([self.test_dna, self.test_dna])), 'ATGCATGC')

        def radd_800(seq):
            return 800 + seq

        assert_raises(TypeError, radd_800, self.test_dna)

    def test_mul(self):
        assert_equal(str(self.test_dna * 4), 'ATGCATGCATGCATGC')

        def mul_float(seq):
            return seq * 7.56

        assert_raises(TypeError, mul_float, self.test_dna)

        # TODO: reimplement this test using manual sequence input
        # def mul_incompatible(seq):
        #     return seq * 3

        # incompatible_seq = self.test_dna.copy()
        # incompatible_seq = incompatible_seq.five_resect(1)
        # incompatible_seq = incompatible_seq.reverse_complement()
        # incompatible_seq = incompatible_seq.five_resect(1)
        # incompatible_seq = incompatible_seq.reverse_complement()
        # assert_raises(Exception, mul_incompatible, incompatible_seq)

    def test_eq(self):
        assert_true(self.test_dna == DNA('atgc'))

    def test_ne(self):
        assert_true(self.test_dna != DNA('aagc'))

    def test_contains(self):
        assert_true('a' in self.test_dna)
        assert_true('t' in self.test_dna)
        assert_true('g' in self.test_dna)
        assert_true('c' in self.test_dna)
        assert_false('u' in self.test_dna)

    def test_flip(self):
        flipped = self.test_dna.flip()
        assert_equal(str(self.test_dna), flipped.bottom)
        assert_equal(self.test_dna.bottom, str(flipped))
Beispiel #40
0
def test_stranded_complemented():
    ss_dna = DNA('atgc', stranded='ss')
    r_ss_dna = ss_dna.reverse_complement()
    assert_equal(r_ss_dna.top(), 'GCAT')
    assert_equal(r_ss_dna.bottom(), '----')
Beispiel #41
0
 def __init__(self):
     self.dna = DNA('ATGC') * 50
     self.apply_features()