Example #1
0
 def _initIUPAC(self,consensus):
     """Sets Motif's attributes using an IUPAC motif string."""
     IUPAC.__init__(self,consensus)
     
     def _motil2myMat():
         """Convert motility's matrix data to my format and
         return the PWM/barcode."""
         pwm = {}
         bases = sorted(self.bases)
         for i in range(4):
             baseData = []
             for pos in self.matrix:
                 baseData.append(pos[i])
             pwm[bases[i]] = tuple(baseData)
         bc = hashlib.md5(str(pwm)).hexdigest()
         return pwm,bc
     
     self.consensus = self.motif
     self.pwm,self.barcode = _motil2myMat()
     self._setID()
     self.accession = self.id
Example #2
0
    def test_mismatches(self):
        motif = 'WGATAR'
        motif_obj = IUPAC(motif)

        assert len(motif_obj.find_with_mismatches('NGATAN', 0)) == 0
        assert len(motif_obj.find_with_mismatches('NGATAN', 1)) == 0
        assert len(motif_obj.find_with_mismatches('NGATAN', 2)) == 1
        assert len(motif_obj.find_with_mismatches('NGATAN', 3)) == 1
        assert len(motif_obj.find_with_mismatches('NGATAN',
                                                  4)) == 2  # finds RC

        try:
            motif_obj.find_with_mismatches('NGATAN', 6)
            assert 0
        except Exception, e:
            pass
Example #3
0
    def test_mismatches(self):
        motif = 'WGATAR'
        motif_obj = IUPAC(motif)

        assert len(motif_obj.find_with_mismatches('NGATAN', 0)) == 0
        assert len(motif_obj.find_with_mismatches('NGATAN', 1)) == 0
        assert len(motif_obj.find_with_mismatches('NGATAN', 2)) == 1
        assert len(motif_obj.find_with_mismatches('NGATAN', 3)) == 1
        assert len(motif_obj.find_with_mismatches('NGATAN', 4)) == 2 # finds RC

        try:
            motif_obj.find_with_mismatches('NGATAN', 6)
            assert 0
        except Exception, e:
            pass
Example #4
0
    def test_g(self):
        motif = 'G'
        motif_obj = IUPAC(motif)

        assert len(find_iupac('A', motif)) == 0
        assert len(motif_obj.find('A')) == 0
        assert motif_obj.calc_score('A') == 0

        assert len(find_iupac('C', motif)) == 1
        assert len(motif_obj.find('C')) == 1
        assert motif_obj.calc_score('C') == 0 # DOES NOT do RC

        assert len(find_iupac('G', motif)) == 1
        assert len(motif_obj.find('G')) == 1
        assert motif_obj.calc_score('G') == 1

        assert len(find_iupac('T', motif)) == 0
        assert len(motif_obj.find('T')) == 0
        assert motif_obj.calc_score('T') == 0

        assert len(find_iupac('N', motif)) == 0
        assert len(motif_obj.find('N')) == 0
        assert motif_obj.calc_score('N') == 0
Example #5
0
 def test_min(self):
     for motif in self.misc_motifs:
         motif_obj = IUPAC(motif)
         assert motif_obj.min_score() == motif.count('N')
Example #6
0
 def test_max(self):
     for motif in self.misc_motifs:
         motif_obj = IUPAC(motif)
         assert motif_obj.max_score() == len(motif)
Example #7
0
    def test_n(self):
        motif = 'N'
        motif_obj = IUPAC(motif)

        assert len(find_iupac('A', motif)) == 1
        assert len(motif_obj.find('A')) == 1
        assert motif_obj.calc_score('A') == 1

        assert len(find_iupac('C', motif)) == 1
        assert len(motif_obj.find('C')) == 1
        assert motif_obj.calc_score('C') == 1

        assert len(find_iupac('G', motif)) == 1
        assert len(motif_obj.find('G')) == 1
        assert motif_obj.calc_score('G') == 1

        assert len(find_iupac('T', motif)) == 1
        assert len(motif_obj.find('T')) == 1
        assert motif_obj.calc_score('T') == 1

        assert len(find_iupac('N', motif)) == 1
        assert len(motif_obj.find('N')) == 1
        assert motif_obj.calc_score('N') == 1
Example #8
0
    def test_g(self):
        motif = 'G'
        motif_obj = IUPAC(motif)

        assert len(find_iupac('A', motif)) == 0
        assert len(motif_obj.find('A')) == 0
        assert motif_obj.calc_score('A') == 0

        assert len(find_iupac('C', motif)) == 1
        assert len(motif_obj.find('C')) == 1
        assert motif_obj.calc_score('C') == 0  # DOES NOT do RC

        assert len(find_iupac('G', motif)) == 1
        assert len(motif_obj.find('G')) == 1
        assert motif_obj.calc_score('G') == 1

        assert len(find_iupac('T', motif)) == 0
        assert len(motif_obj.find('T')) == 0
        assert motif_obj.calc_score('T') == 0

        assert len(find_iupac('N', motif)) == 0
        assert len(motif_obj.find('N')) == 0
        assert motif_obj.calc_score('N') == 0
Example #9
0
 def test_min(self):
     for motif in self.misc_motifs:
         motif_obj = IUPAC(motif)
         assert motif_obj.min_score() == motif.count('N')
Example #10
0
 def test_max(self):
     for motif in self.misc_motifs:
         motif_obj = IUPAC(motif)
         assert motif_obj.max_score() == len(motif)
Example #11
0
    def test_n(self):
        motif = 'N'
        motif_obj = IUPAC(motif)

        assert len(find_iupac('A', motif)) == 1
        assert len(motif_obj.find('A')) == 1
        assert motif_obj.calc_score('A') == 1

        assert len(find_iupac('C', motif)) == 1
        assert len(motif_obj.find('C')) == 1
        assert motif_obj.calc_score('C') == 1

        assert len(find_iupac('G', motif)) == 1
        assert len(motif_obj.find('G')) == 1
        assert motif_obj.calc_score('G') == 1

        assert len(find_iupac('T', motif)) == 1
        assert len(motif_obj.find('T')) == 1
        assert motif_obj.calc_score('T') == 1

        assert len(find_iupac('N', motif)) == 1
        assert len(motif_obj.find('N')) == 1
        assert motif_obj.calc_score('N') == 1
Example #12
0
 def test_len(self):
     for motif in self.misc_motifs:
         motif_obj = IUPAC(motif)
         assert len(motif_obj) == len(motif)