Exemplo n.º 1
0
def clustal_to_phylip(src,dest=None):
    import os
    from Bio.AlignIO.ClustalIO import ClustalIterator
    from Bio.AlignIO.PhylipIO import PhylipWriter
    if dest==None:
        dest = src
    head,tail = os.path.split(dest)
    _dest = os.path.join(head,"."+tail)
    with open(src) as i:
        alignments = list(ClustalIterator(i))
    with open(_dest,"w") as f:
        writer = PhylipWriter(f)
        writer.write_file(alignments)
    os.rename(_dest,dest)
    return dest
Exemplo n.º 2
0
 def __init__(self, input, output=None):
     self._itemp=None
     self.output = output
     if isinstance(input, str):
         assert(os.path.exists(input))
         self.input = input
     elif isinstance(input, list):
         from tempfile import NamedTemporaryFile
         from Bio.AlignIO.PhylipIO import PhylipWriter
         self._itemp = NamedTemporaryFile()
         self.input = self._itemp.name
         writer = PhylipWriter(self._itemp)
         writer.write_alignment(input)
         self._itemp.flush()
     else:
         raise Exception("Unknown input type",input)
Exemplo n.º 3
0
    def test_write_read(self):
        handle = StringIO(phylip_text5a)
        list5 = list(PhylipIterator(handle))
        handle.close()

        handle = StringIO()
        PhylipWriter(handle).write_file(list5)
        handle.seek(0)
        list6 = list(PhylipIterator(handle))

        self.assertEqual(len(list5), len(list6))
        for a1, a2 in zip(list5, list6):
            self.assertEqual(len(a1), len(a2))
            for r1, r2 in zip(a1, a2):
                self.assertEqual(r1.id, r2.id)
                self.assertEqual(str(r1.seq), str(r2.seq))
Exemplo n.º 4
0
    def test_write_read(self):
        path = "Phylip/six.dat"
        with open(path) as handle:
            list5 = list(PhylipIterator(handle))

        handle = StringIO()
        PhylipWriter(handle).write_file(list5)
        handle.seek(0)
        list6 = list(PhylipIterator(handle))

        self.assertEqual(len(list5), len(list6))
        for a1, a2 in zip(list5, list6):
            self.assertEqual(len(a1), len(a2))
            for r1, r2 in zip(a1, a2):
                self.assertEqual(r1.id, r2.id)
                self.assertEqual(r1.seq, r2.seq)