Пример #1
0
 def test_record_linkage(self):
     cluster = CandidateCluster(CandidateCluster.kinds.INTERLEAVED,
                                self.record.get_protoclusters())
     with self.assertRaisesRegex(
             ValueError, "CandidateCluster not contained in record"):
         cluster.get_candidate_cluster_number()
     self.record.add_candidate_cluster(cluster)
     assert cluster.get_candidate_cluster_number() == 1
Пример #2
0
    def test_conversion(self):
        kind = CandidateClusterKind.INTERLEAVED
        original = CandidateCluster(kind,
                                    self.record.get_protoclusters(),
                                    smiles="dummy smiles",
                                    polymer="dummy polymer")
        self.record.add_candidate_cluster(original)
        assert original.products == ["a"]
        assert len(original.protoclusters) == 1
        bios = original.to_biopython()
        assert len(bios) == 1
        bio = bios[0]
        assert bio.qualifiers["product"] == ["a"]
        assert bio.qualifiers["kind"] == [str(kind)]
        assert bio.qualifiers["candidate_cluster_number"] == [
            str(original.get_candidate_cluster_number())
        ]
        assert bio.qualifiers["SMILES"] == ["dummy smiles"]
        assert bio.qualifiers["polymer"] == ["dummy polymer"]
        assert bio.qualifiers["contig_edge"] == ["True"]
        regenerated = CandidateCluster.from_biopython(bio)
        assert isinstance(regenerated, TemporaryCandidateCluster)
        assert regenerated.products == original.products
        assert regenerated.location == original.location
        assert regenerated.smiles_structure == original.smiles_structure
        assert regenerated.polymer == original.polymer
        proto_numbers = [
            cluster.get_protocluster_number()
            for cluster in self.record.get_protoclusters()
        ]
        assert regenerated.protoclusters == proto_numbers
        assert regenerated.kind == original.kind

        real = regenerated.convert_to_real_feature(self.record)
        assert isinstance(real, CandidateCluster)
        assert len(real.protoclusters) == len(self.record.get_protoclusters())
        for reference, record_cluster in zip(real.protoclusters,
                                             self.record.get_protoclusters()):
            assert reference is record_cluster

        # attempt a conversion with a record missing the cluster
        self.record.clear_protoclusters()
        with self.assertRaisesRegex(ValueError,
                                    "Not all referenced clusters are present"):
            regenerated.convert_to_real_feature(self.record)
Пример #3
0
    def test_conversion(self):
        kind = CandidateClusterKind.INTERLEAVED
        original = CandidateCluster(kind,
                                    self.record.get_protoclusters(),
                                    smiles="dummy smiles",
                                    polymer="dummy polymer")
        self.record.add_candidate_cluster(original)
        assert original.products == ["a"]
        assert len(original.protoclusters) == 1
        bios = original.to_biopython()
        assert len(bios) == 1
        bio = bios[0]
        assert bio.qualifiers["product"] == ["a"]
        assert bio.qualifiers["kind"] == [str(kind)]
        assert bio.qualifiers["candidate_cluster_number"] == [
            str(original.get_candidate_cluster_number())
        ]
        assert bio.qualifiers["SMILES"] == ["dummy smiles"]
        assert bio.qualifiers["polymer"] == ["dummy polymer"]
        assert bio.qualifiers["contig_edge"] == ["True"]
        real = CandidateCluster.from_biopython(bio, record=self.record)
        assert isinstance(real, CandidateCluster)
        assert len(real.protoclusters) == len(self.record.get_protoclusters())
        for reference, record_cluster in zip(real.protoclusters,
                                             self.record.get_protoclusters()):
            assert reference is record_cluster

        # attempt a conversion with a record missing the cluster
        self.record.clear_protoclusters()
        with self.assertRaisesRegex(
                ValueError,
                "record does not contain all expected protoclusters"):
            CandidateCluster.from_biopython(bio, record=self.record)
        # and with no record
        with self.assertRaisesRegex(ValueError, "record instance required"):
            CandidateCluster.from_biopython(bio)