def test_reserved_attributes(self, test_data_dir, tmp_path):
     gb = test_data_dir / "INSC1020_subset_gff3.gb"
     parsed = list(parse_genbank(gb))
     a = [x.to_annotation_collection() for x in parsed]
     tmp_gff = tmp_path / "tmp.gff"
     with pytest.warns(ReservedKeyWarning):
         with open(tmp_gff, "w") as fh:
             collection_to_gff3(a, fh, raise_on_reserved_attributes=False)
     with pytest.raises(GFF3ExportException):
         with open(tmp_gff, "w") as fh:
             collection_to_gff3(a, fh, raise_on_reserved_attributes=True)
    def test_gff3_strand_error(self, tmp_path):
        tmp_gff3 = tmp_path / "tmp.gff3"

        annot = self.annot.to_annotation_collection().to_dict()
        annot["feature_collections"][0]["feature_intervals"][0][
            "strand"] = "MINUS"
        annot = AnnotationCollectionModel.Schema().load(
            annot).to_annotation_collection()

        with open(tmp_gff3, "w") as fh:
            collection_to_gff3([annot], fh)
        with pytest.raises(GFF3ChildParentMismatchError):
            _ = list(parse_standard_gff3(tmp_gff3))
    def test_to_gff(self, test_data_dir, tmp_path):
        """Parse GFF, write to disk, parse, compare"""
        gff = test_data_dir / "INSC1006_chrI.gff3"
        parsed = list(parse_standard_gff3(gff))
        a = [x.to_annotation_collection() for x in parsed]

        tmp_gff = tmp_path / "tmp.gff"
        with open(tmp_gff, "w") as fh:
            collection_to_gff3(a, fh)
        gff2 = list(parse_standard_gff3(tmp_gff))
        a2 = [x.to_annotation_collection() for x in gff2]

        for c1, c2 in zip(a, a2):
            assert c1.to_dict() == c2.to_dict()
    def test_genbank_to_gff(self, test_data_dir, tmp_path, gbk, gff3, add_sequences):
        """
        INSC1006_chrI.gff3 and INSC1003.gff3 were created from INSC1006_chrI.gbff and INSC1003.gbk
        respectively, so we can compare to the source file.
        """
        gbk = test_data_dir / gbk
        with open(gbk, "r") as fh:
            parsed = list(ParsedAnnotationRecord.parsed_annotation_records_to_model(parse_genbank(fh)))

        tmp_gff = tmp_path / "tmp.gff"
        with open(tmp_gff, "w") as fh:
            collection_to_gff3(parsed, fh, add_sequences=add_sequences)

        for l1, l2 in zip(open(tmp_gff), open(test_data_dir / gff3)):
            assert l1 == l2