コード例 #1
0
    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)
コード例 #2
0
ファイル: test_Nexus.py プロジェクト: kctsai066/hello-world
    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)
コード例 #3
0
ファイル: test_Nexus.py プロジェクト: kctsai066/hello-world
    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])
コード例 #4
0
ファイル: test_Nexus.py プロジェクト: ielushuai/biopython
    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
コード例 #5
0
    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])