Beispiel #1
0
    def test_single(self):
        """RdbParser should read single record as (header,seq) tuple"""
        res = list(RdbParser(self.oneseq))
        self.assertEqual(len(res), 1)
        first = res[0]
        self.assertEqual(first, Sequence('AGUCAUCUAGAUHCAUHC'))
        self.assertEqual(first.Info, Info({'Species':'H.Sapiens',\
            'OriginalSeq':'AGUCAUCUAGAUHCAUHC'}))

        res = list(RdbParser(self.multiline))
        self.assertEqual(len(res), 1)
        first = res[0]
        self.assertEqual(first, Sequence('AGUCAUUAGAUHCAUHC'))
        self.assertEqual(first.Info, Info({'Species':'H.Sapiens',\
            'OriginalSeq':'AGUCAUUAGAUHCAUHC'}))
Beispiel #2
0
    def toSeq(self, Bases=True, truncate=True):
        """Translates flowgram to sequence and returns sequence object
            if Bases is True then a sequence object will be made using
            self.Bases instead of translating the flowgram
        
            truncate: if True strip off lowercase chars (low quality bases)
            """
        if Bases and hasattr(self, "Bases"):
            seq = self.Bases
        else:
            seq = []
            if self.floworder is None:
                raise ValueError, "must have self.floworder set"
            key = FakeRandom(self.floworder, True)

            flows_since_last = 0
            for n in self.flowgram:
                signal = int(round(n))
                seq.extend([key()] * signal)
                if (signal > 0):
                    flows_since_last = 0
                else:
                    flows_since_last += 1
                    if (flows_since_last == 4):
                        seq.extend('N')
                        flows_since_last = 0
            seq = ''.join(seq)
            #cache the result for next time
            self.Bases = seq

        if (truncate):
            seq = str(seq)
            seq = seq.rstrip("acgtn")
            seq = seq.lstrip("actgn")
        return Sequence(seq, Name=self.Name)
Beispiel #3
0
 def test_init_other_seq(self):
     """Sequence init with other seq should preserve name and info."""
     r = self.RNA('UCAGG', Name='x', Info={'z': 3})
     s = Sequence(r)
     self.assertEqual(s._seq, 'UCAGG')
     self.assertEqual(s.Name, 'x')
     self.assertEqual(s.Info.z, 3)
Beispiel #4
0
 def test_gapped_to_ungapped_general_seq(self):
     """gapped_to_ungapped: when input is Sequence obj, treat as string
     """
     s = Sequence(self.gapped)
     p = self.simple_g
     obs_seq, obs_pairs = gapped_to_ungapped(s, p)
     self.assertEqual(obs_seq, self.ungapped)
     self.assertEqualItems(obs_pairs, self.simple)
     #assert not isinstance(obs_seq, Sequence)
     #assert isinstance(obs_seq, str)
     assert isinstance(obs_seq, Sequence)
     assert isinstance(obs_pairs, Pairs)