Beispiel #1
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'])
Beispiel #2
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')
Beispiel #3
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'])
Beispiel #4
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'])
Beispiel #5
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'])
Beispiel #6
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)
Beispiel #7
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'])
Beispiel #8
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'])
Beispiel #9
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)
Beispiel #10
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'])
Beispiel #11
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'])
Beispiel #12
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'])
Beispiel #13
0
def strand_to_enzymes(strand):
    """ Tranlate the strand encoding to enzymes via ribosomes """

    def chunk_strand(strand):
        for idx in range(len(strand) / 2):
            yield strand[idx * 2:idx * 2 + 2]

    # translate the chunks to amino acids or punctuation
    amino_acids = [AminoAcid(TYPOGENETIC_CODE[chunk]) for chunk in chunk_strand(strand.strand)]

    enzymes = []
    current_enzyme = []
    for amino_acid in amino_acids:
        # if there is an AA chunk present, we finish off the current enzyme and start a new one
        if amino_acid.op == 'pun':
            enzymes.append(Enzyme(current_enzyme))
            current_enzyme = []
        else:
            current_enzyme.append(amino_acid)
    enzymes.append(Enzyme(current_enzyme))

    return filter(lambda e: len(e.amino_acids), enzymes)  # filter out any empty enzyimes
Beispiel #14
0
 def test_constructor(self):
     Enzyme([AminoAcid('cut'), AminoAcid('delete')])
Beispiel #15
0
 def test_input_all_amino_acids(self):
     with assert_raises_regexp(InvalidEnzyme,
                               'Must all be of type AminoAcid'):
         Enzyme([AminoAcid('cut'), AminoAcid('delete'), 4])
Beispiel #16
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'])
Beispiel #17
0
 def test_constructor(self):
     AminoAcid('pun')
Beispiel #18
0
 def test_invalid_op(self):
     with assert_raises_regexp(InvalidAminoAcid, 'Not a valid amino acid'):
         AminoAcid('cat')
Beispiel #19
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'])
Beispiel #20
0
 def test_empty_strand(self):
     s = Strand('')
     e = Enzyme([AminoAcid('delete')])
     final_strands = apply_enzyme(s, e)
     assert (final_strands[0] == s)