def test_write_alignment(self):
        # Default causes no interleave (columns <= 1000)
        records = [
            SeqRecord(Seq("ATGCTGCTGA" * 90),
                      id=_id,
                      annotations={"molecule_type": "DNA"})
            for _id in ["foo", "bar", "baz"]
        ]
        a = MultipleSeqAlignment(records)

        handle = StringIO()
        NexusWriter(handle).write_alignment(a)
        handle.seek(0)
        data = handle.read()
        self.assertIn("ATGCTGCTGA" * 90, data)

        # Default causes interleave (columns > 1000)
        records = [
            SeqRecord(Seq("ATGCTGCTGA" * 110),
                      id=_id,
                      annotations={"molecule_type": "DNA"})
            for _id in ["foo", "bar", "baz"]
        ]
        a = MultipleSeqAlignment(records)
        handle = StringIO()
        NexusWriter(handle).write_alignment(a)
        handle.seek(0)
        data = handle.read()
        self.assertNotIn("ATGCTGCTGA" * 90, data)
        self.assertIn("ATGCTGCTGA" * 7, data)

        # Override interleave: True
        records = [
            SeqRecord(Seq("ATGCTGCTGA" * 9),
                      id=_id,
                      annotations={"molecule_type": "DNA"})
            for _id in ["foo", "bar", "baz"]
        ]
        a = MultipleSeqAlignment(records)
        handle = StringIO()
        NexusWriter(handle).write_alignment(a, interleave=True)
        handle.seek(0)
        data = handle.read()
        self.assertNotIn("ATGCTGCTGA" * 9, data)
        self.assertIn("ATGCTGCTGA" * 7, data)

        # Override interleave: False
        records = [
            SeqRecord(Seq("ATGCTGCTGA" * 110),
                      id=_id,
                      annotations={"molecule_type": "DNA"})
            for _id in ["foo", "bar", "baz"]
        ]
        a = MultipleSeqAlignment(records)
        handle = StringIO()
        NexusWriter(handle).write_alignment(a, interleave=False)
        handle.seek(0)
        data = handle.read()
        self.assertIn("ATGCTGCTGA" * 110, data)
Example #2
0
    def test_write_alignment(self):
        # Default causes no interleave (columns <= 1000)
        records = [
            SeqRecord(Seq("ATGCTGCTGA" * 90, alphabet=ambiguous_dna), id=_id)
            for _id in ["foo", "bar", "baz"]
        ]
        a = MultipleSeqAlignment(records, alphabet=ambiguous_dna)

        handle = StringIO()
        NexusWriter(handle).write_alignment(a)
        handle.seek(0)
        data = handle.read()
        self.assertIn("ATGCTGCTGA" * 90, data)

        # Default causes interleave (columns > 1000)
        records = [
            SeqRecord(Seq("ATGCTGCTGA" * 110, alphabet=ambiguous_dna), id=_id)
            for _id in ["foo", "bar", "baz"]
        ]
        a = MultipleSeqAlignment(records, alphabet=ambiguous_dna)
        handle = StringIO()
        NexusWriter(handle).write_alignment(a)
        handle.seek(0)
        data = handle.read()
        self.assertNotIn("ATGCTGCTGA" * 90, data)
        self.assertIn("ATGCTGCTGA" * 7, data)

        # Override interleave: True
        records = [
            SeqRecord(Seq("ATGCTGCTGA" * 9, alphabet=ambiguous_dna), id=_id)
            for _id in ["foo", "bar", "baz"]
        ]
        a = MultipleSeqAlignment(records, alphabet=ambiguous_dna)
        handle = StringIO()
        NexusWriter(handle).write_alignment(a, interleave=True)
        handle.seek(0)
        data = handle.read()
        self.assertNotIn("ATGCTGCTGA" * 9, data)
        self.assertIn("ATGCTGCTGA" * 7, data)

        # Override interleave: False
        records = [
            SeqRecord(Seq("ATGCTGCTGA" * 110, alphabet=ambiguous_dna), id=_id)
            for _id in ["foo", "bar", "baz"]
        ]
        a = MultipleSeqAlignment(records, alphabet=ambiguous_dna)
        handle = StringIO()
        NexusWriter(handle).write_alignment(a, interleave=False)
        handle.seek(0)
        data = handle.read()
        self.assertIn("ATGCTGCTGA" * 110, data)
Example #3
0
    def test_multiple_output(self):
        records = [
            SeqRecord(Seq("ATGCTGCTGAT", alphabet=ambiguous_dna), id="foo"),
            SeqRecord(Seq("ATGCTGCAGAT", alphabet=ambiguous_dna), id="bar"),
            SeqRecord(Seq("ATGCTGCGGAT", alphabet=ambiguous_dna), id="baz")
        ]
        a = MultipleSeqAlignment(records, alphabet=ambiguous_dna)

        handle = StringIO()
        NexusWriter(handle).write_file([a])
        handle.seek(0)
        data = handle.read()
        self.assertTrue(data.startswith("#NEXUS\nbegin data;\n"), data)
        self.assertTrue(data.endswith("end;\n"), data)

        handle = StringIO()
        with self.assertRaises(ValueError):
            NexusWriter(handle).write_file([a, a])
Example #4
0
    def test_multiple_output(self):
        records = [SeqRecord(Seq("ATGCTGCTGAT", alphabet=ambiguous_dna), id="foo"),
                   SeqRecord(Seq("ATGCTGCAGAT", alphabet=ambiguous_dna), id="bar"),
                   SeqRecord(Seq("ATGCTGCGGAT", alphabet=ambiguous_dna), id="baz")]
        a = MultipleSeqAlignment(records, alphabet=ambiguous_dna)

        handle = StringIO()
        NexusWriter(handle).write_file([a])
        handle.seek(0)
        data = handle.read()
        self.assertTrue(data.startswith("#NEXUS\nbegin data;\n"), data)
        self.assertTrue(data.endswith("end;\n"), data)

        handle = StringIO()
        try:
            NexusWriter(handle).write_file([a, a])
            assert False, "Should have rejected more than one alignment!"
        except ValueError:
            pass
    def test_multiple_output(self):
        records = [
            SeqRecord(Seq("ATGCTGCTGAT"),
                      id="foo",
                      annotations={"molecule_type": "DNA"}),
            SeqRecord(Seq("ATGCTGCAGAT"),
                      id="bar",
                      annotations={"molecule_type": "DNA"}),
            SeqRecord(Seq("ATGCTGCGGAT"),
                      id="baz",
                      annotations={"molecule_type": "DNA"}),
        ]
        a = MultipleSeqAlignment(records)

        handle = StringIO()
        NexusWriter(handle).write_file([a])
        handle.seek(0)
        data = handle.read()
        self.assertTrue(data.startswith("#NEXUS\nbegin data;\n"), data)
        self.assertTrue(data.endswith("end;\n"), data)

        handle = StringIO()
        with self.assertRaises(ValueError):
            NexusWriter(handle).write_file([a, a])