Example #1
0
    def test_line_with_no_tags(self):
        fields = [
            "query_name",
            "1239",
            "65",
            "1239",
            "+",
            "target_name",
            "4378340",
            "2555250",
            "2556472",
            "1139",
            "1228",
            "60",
        ]
        line = "\t".join(fields)

        actual = PafRecord.from_str(line)
        expected = PafRecord(
            "query_name",
            1239,
            65,
            1239,
            Strand.Forward,
            "target_name",
            4378340,
            2555250,
            2556472,
            1139,
            1228,
            60,
        )

        assert actual == expected
Example #2
0
    def test_line_with_invalid_tag_raises_error(self):
        fields = [
            "query_name",
            "1239",
            "65",
            "1239",
            "-",
            "target_name",
            "4378340",
            "2555250",
            "2556472",
            "1139",
            "1228",
            "60",
            "NMX:i:89",
        ]
        line = "\t".join(fields)

        with pytest.raises(InvalidTagFormat):
            PafRecord.from_str(line)
Example #3
0
    def test_line_with_dupliacte_tag_returns_last_one(self):
        fields = [
            "query_name",
            "1239",
            "65",
            "1239",
            "-",
            "target_name",
            "4378340",
            "2555250",
            "2556472",
            "1139",
            "1228",
            "60",
            "NM:i:89",
            "NM:i:2",
        ]
        line = "\t".join(fields)

        actual = PafRecord.from_str(line)
        expected_tags = {"NM": Tag.from_str("NM:i:2")}
        expected = PafRecord(
            "query_name",
            1239,
            65,
            1239,
            Strand.Reverse,
            "target_name",
            4378340,
            2555250,
            2556472,
            1139,
            1228,
            60,
            expected_tags,
        )

        assert actual == expected
Example #4
0
    def test_line_with_tags(self):
        fields = [
            "query_name",
            "1239",
            "65",
            "1239",
            "-",
            "target_name",
            "4378340",
            "2555250",
            "2556472",
            "1139",
            "1228",
            "60",
            "NM:i:89",
            "ms:i:1906",
        ]
        line = "\t".join(fields)

        actual = PafRecord.from_str(line)
        tags = {"NM": Tag.from_str("NM:i:89"), "ms": Tag.from_str("ms:i:1906")}
        expected = PafRecord(
            "query_name",
            1239,
            65,
            1239,
            Strand.Reverse,
            "target_name",
            4378340,
            2555250,
            2556472,
            1139,
            1228,
            60,
            tags,
        )

        assert actual == expected
Example #5
0
 def __next__(self) -> PafRecord:
     if self.closed:
         raise IOError("PAF file is closed - cannot get next element.")
     return PafRecord.from_str(next(self._stream))
Example #6
0
    def test_line_has_too_few_fields_raises_error(self):
        line = "qname\t1\t3"

        with pytest.raises(MalformattedRecord):
            PafRecord.from_str(line)
Example #7
0
    def test_empty_str_raises_error(self):
        line = ""

        with pytest.raises(MalformattedRecord):
            PafRecord.from_str(line)