Esempio n. 1
0
    def test_preferred_binding(self):
        s = Strand('TAGATCCAGTCCACATCGA')
        e = strand_to_enzymes(s)
        e0 = e[0]
        assert (e0.binding_preference == 'C')

        s = Strand('CGTCATCTACTGGTTAGC')
        e = strand_to_enzymes(s)
        e0 = e[0]
        assert (e0.binding_preference == 'T')
Esempio n. 2
0
    def test_delete(self):
        s = Strand('ACGT')
        e = Enzyme([AminoAcid('delete')])

        final_strands = apply_enzyme(s, e)
        strand_strs = sorted([strand.strand for strand in final_strands])
        assert (strand_strs == ['CGT'])
Esempio n. 3
0
    def test_swi_swi(self):
        """
                     v
        Secondary: ....
        Primary:   ACGT
                     ^
        Copy mode: False
        cop
                     v
        Secondary: ..C.
        Primary:   ACGT
                     ^
        Copy mode: True
        swi
                    v
        Secondary: TGCA
        Primary:   .C..
                    ^
        Copy mode: True
        swi
                     v
        Secondary: ..C.
        Primary:   ACGT
                     ^
        """
        s = Strand('ACGT')
        e = Enzyme([AminoAcid('cop'), AminoAcid('swi'), AminoAcid('swi')])

        final_strands = apply_enzyme(s, e)
        strand_strs = sorted([strand.strand for strand in final_strands])
        assert (strand_strs == ['ACGT', 'C'])
Esempio n. 4
0
    def test_apply_enzyme_ACA(self):
        s = Strand('ACA')
        e = Enzyme([AminoAcid('delete'), AminoAcid('mvr'), AminoAcid('int')])
        final_strands = apply_enzyme(s, e)

        assert (isinstance(final_strands[0], Strand) == True)
        assert (final_strands[0].strand == 'CAT')
Esempio n. 5
0
    def test_del_gap(self):
        """
        delete
                              v
        Secondary: ........CCCC.
        Primary:   ACGTGGGGGG.GG
                              ^
        """
        s = Strand('ACGTGGGGGGGGG')

        e = Enzyme([
            AminoAcid('mvr'),
            AminoAcid('mvr'),
            AminoAcid('mvr'),
            AminoAcid('mvr'),
            AminoAcid('mvr'),
            AminoAcid('mvr'),
            AminoAcid('cop'),
            AminoAcid('mvr'),
            AminoAcid('mvr'),
            AminoAcid('mvr'),
            AminoAcid('mvl'),
            AminoAcid('delete')
        ])
        final_strands = apply_enzyme(s, e)
        strand_strs = sorted([strand.strand for strand in final_strands])
        assert (strand_strs == ['ACGTGGGGGG', 'CCCC', 'GG'])
Esempio n. 6
0
    def test_inc_cop(self):
        """
                   v
        Secondary: ....
        Primary:   ACGT
                   ^
        Copy mode: False
        cop
                   v
        Secondary: T...
        Primary:   ACGT
                   ^
        Copy mode: True
        inc
                   v
        Secondary: TG...
        Primary:   ACCGT
                   ^
        Copy mode: True
        ['ACCGT', 'GT']
        """
        s = Strand('ACGT')
        e = Enzyme([AminoAcid('cop'), AminoAcid('inc')])

        final_strands = apply_enzyme(s, e)
        strand_strs = sorted([strand.strand for strand in final_strands])
        assert (strand_strs == ['ACCGT', 'GT'])
Esempio n. 7
0
    def test_cop_mvl(self):
        """
                     v
        Secondary: ....
        Primary:   ACGT
                     ^
        Copy mode: False
        mvr
                      v
        Secondary: ....
        Primary:   ACGT
                      ^
        Copy mode: False
        cop
                      v
        Secondary: ...A
        Primary:   ACGT
                      ^
        Copy mode: True
        mvl
                     v
        Secondary: ..CA
        Primary:   ACGT
                     ^
        Copy mode: True
        ['AC', 'ACGT']
        """
        s = Strand('ACGT')
        e = Enzyme([AminoAcid('mvr'), AminoAcid('cop'), AminoAcid('mvl')])

        final_strands = apply_enzyme(s, e)
        strand_strs = sorted([strand.strand for strand in final_strands])
        assert (strand_strs == ['AC', 'ACGT'])
Esempio n. 8
0
    def test_punctuation(self):
        s = Strand('CGGATACTAAACCGA')
        e = strand_to_enzymes(s)

        e_known = [Enzyme([AminoAcid('cop'), AminoAcid('ina'), AminoAcid('rpy'), AminoAcid('off')]),
                   Enzyme([AminoAcid('cut'), AminoAcid('cop')])]
        self.assert_enzymes_eq(e, e_known)
Esempio n. 9
0
    def test_mvl_complement_none(self):
        s = Strand('TCCGCAATTT')

        e = strand_to_enzymes(s)[0]
        final_strands = apply_enzyme(s, e)
        strand_strs = sorted([strand.strand for strand in final_strands])
        assert (strand_strs == ['GC', 'TCCGCAATTT'])
Esempio n. 10
0
    def test_strand_to_enzymes(self):
        s = Strand('TAGATCCAGTCCACATCGA')
        e = strand_to_enzymes(s)

        e_known = [Enzyme([AminoAcid('rpy'), AminoAcid('ina'), AminoAcid('rpu'), AminoAcid('mvr'),
                           AminoAcid('int'), AminoAcid('mvl'), AminoAcid('cut'), AminoAcid('swi'),
                           AminoAcid('cop')])]
        self.assert_enzymes_eq(e, e_known)
Esempio n. 11
0
    def test_apply_longer_enzyme(self):
        s = Strand('CAAAGAGAATCCTCTTTGAT')
        e = Enzyme([AminoAcid('rpy'), AminoAcid('cop'), AminoAcid('rpu')])

        final_strands = apply_enzyme(s, e)
        strand_strs = sorted([strand.strand for strand in final_strands])

        assert (strand_strs == ['CAAAGAGAATCCTCTTTGAT', 'CAAAGAGGA'])
Esempio n. 12
0
    def test_ing_cop(self):
        """
                   v
        Secondary: ....
        Primary:   ACGT
                   ^
        Copy mode: False
        cop
           v
        Secondary: T...
        Primary:   ACGT
                   ^
        Copy mode: True
        off
                   v
        Secondary: T...
        Primary:   ACGT
                   ^
        Copy mode: False
        mvr
                    v
        Secondary: T...
        Primary:   ACGT
                    ^
        Copy mode: False
        mvr
                     v
        Secondary: T...
        Primary:   ACGT
                     ^
        Copy mode: False
        cop
                     v
        Secondary: T.C.
        Primary:   ACGT
                     ^
        Copy mode: True
        ing
                     v
        Secondary: T.CC.
        Primary:   ACGGT
                     ^
        Copy mode: True
        ['ACGGT', 'CC', 'T']
        """
        s = Strand('ACGT')
        e = Enzyme([
            AminoAcid('cop'),
            AminoAcid('off'),
            AminoAcid('mvr'),
            AminoAcid('mvr'),
            AminoAcid('cop'),
            AminoAcid('ing')
        ])

        final_strands = apply_enzyme(s, e)
        strand_strs = sorted([strand.strand for strand in final_strands])
        assert (strand_strs == ['ACGGT', 'CC', 'T'])
Esempio n. 13
0
    def test_delete_outofbounds(self):
        s = Strand('ACGT')
        e = Enzyme([
            AminoAcid('mvr'),
            AminoAcid('delete'),
            AminoAcid('delete'),
            AminoAcid('delete'),
            AminoAcid('inc')
        ])

        final_strands = apply_enzyme(s, e)
        strand_strs = sorted([strand.strand for strand in final_strands])
        assert (strand_strs == ['A'])
Esempio n. 14
0
    def test_swi_none(self):
        """
                   v
        Secondary: ....
        Primary:   ACGT
                   ^
        """
        s = Strand('ACGT')
        e = Enzyme([AminoAcid('swi')])

        final_strands = apply_enzyme(s, e)
        strand_strs = sorted([strand.strand for strand in final_strands])
        assert (strand_strs == ['ACGT'])
Esempio n. 15
0
def apply_enzyme(strand, enzyme, verbose=False):
    """ Apply specific enzymes on a strand """

    sm = StrandManipulationBuffer(strand.strand)

    # find an initial binding pair
    while (sm.primary.bound != enzyme.binding_preference):
        try:
            sm.mvr()
        except OutOfStrandException:
            # either couldn't find a binding partner or empty strand
            # in both cases, just return the original strand
            return [strand]

    # log initial state, if desired
    if verbose:
        print sm

    # apply the amino acid operations in order, unless we hit the end of a strand
    for amino_acid in enzyme.amino_acids:
        try:
            # call operator
            sm(amino_acid.op)
            if verbose:
                print amino_acid.op
                print sm
        except OutOfStrandException:
            break

    # collect all of the strands
    strands = []
    sm.primary_strands.append(sm.primary.dump())
    sm.secondary_strands.append(sm.secondary.dump())

    for strand in sm.primary_strands:
        for sub_strand in strand.split(
                PLACEHOLDER
        ):  # in some cases there might be gaps, so split by the null placeholder
            strands.append(sub_strand)

    # the upper strands need to be reversed
    for strand in sm.secondary_strands:
        for sub_strand in strand.split(PLACEHOLDER):
            strands.append(sub_strand[::-1])

    # remove any empty strands/strings
    strands = filter(lambda s: len(s), strands)

    return [Strand(s) for s in strands]
Esempio n. 16
0
    def test_cut(self):
        """
                   v
        Secondary: ....
        Primary:   ACGT
                   ^
        Copy mode: False
        cut
                   v
        Secondary: .
        Primary:   A
                   ^
        Copy mode: False
        ['A', 'CGT']
        """
        s = Strand('ACGT')
        e = Enzyme([AminoAcid('cut')])

        final_strands = apply_enzyme(s, e)
        strand_strs = sorted([strand.strand for strand in final_strands])
        assert (strand_strs == ['A', 'CGT'])
Esempio n. 17
0
    def test_book_example(self):
        s = Strand('TAGATCCAGTCCATCGA')
        e = Enzyme([
            AminoAcid('mvr'),
            AminoAcid('mvr'),
            AminoAcid('mvr'),
            AminoAcid('mvr'),
            AminoAcid('mvr'),
            AminoAcid(
                'mvr'
            ),  # some extra movements to lineup with the known example
            AminoAcid('rpu'),
            AminoAcid('inc'),
            AminoAcid('cop'),
            AminoAcid('mvr'),
            AminoAcid('mvl'),
            AminoAcid('swi'),
            AminoAcid('lpu'),
            AminoAcid('int')
        ])

        final_strands = apply_enzyme(s, e)
        strand_strs = sorted([strand.strand for strand in final_strands])
        assert (strand_strs == ['ATG', 'TAGATCCAGTCCACATCGA'])
Esempio n. 18
0
    def test_null(self):
        s = Strand('AAAAA')
        e = strand_to_enzymes(s)

        e_known = []
        self.assert_enzymes_eq(e, e_known)
Esempio n. 19
0
#!/usr/bin/env python

from typogenetics.strand import Strand
from typogenetics.ribosomes import strand_to_enzymes
from typogenetics.manipulation import apply_enzyme

if __name__ == '__main__':
    # example strand
    strand = Strand('TAGATCCAGTCCACTCGA')

    # apply the ribosomes (which can produce more than one enzyme)
    enzymes = strand_to_enzymes(strand)

    # here, we'll apply all the enzymes to the original strand
    daughter_strands = []
    for enzyme in enzymes:
        print "Next enzyme:"
        print enzyme
        print
        print "Operations:"
        print
        daughter_strands.extend(apply_enzyme(strand, enzyme, verbose=True))

    print
    print "----------"
    print "Resulting strands"
    print "----------"
    print[strand.strand for strand in set(daughter_strands)]
Esempio n. 20
0
 def test_non_base_input(self):
     with assert_raises_regexp(InvalidStrand, 'Strand contains an invalid base unit'):
         Strand('bat')    
Esempio n. 21
0
 def test_str_input(self):
     s = Strand('CATG')
     assert s.strand == 'CATG'
Esempio n. 22
0
 def test_non_str_input(self):
     with assert_raises_regexp(InvalidStrand, 'Wrong type, must be a str'):
         Strand(4)
Esempio n. 23
0
 def test_lowercase(self):
     s = Strand('attag')
     assert s.strand == 'ATTAG'
Esempio n. 24
0
 def test_empty_strand(self):
     s = Strand('')
     e = Enzyme([AminoAcid('delete')])
     final_strands = apply_enzyme(s, e)
     assert (final_strands[0] == s)
Esempio n. 25
0
 def test_apply_empty_enzyme(self):
     s = Strand('ACGT')
     e = Enzyme([])
     final_strands = apply_enzyme(s, e)
     assert (final_strands[0].strand == 'ACGT')
Esempio n. 26
0
 def test_no_binding(self):
     s = Strand('GGG')
     e = strand_to_enzymes(s)[0]
     final_strands = apply_enzyme(s, e)
     assert (final_strands[0] == s)