def test_record_linkage(self): cluster = SuperCluster(SuperCluster.kinds.INTERLEAVED, self.record.get_clusters()) with self.assertRaisesRegex(ValueError, "SuperCluster not contained in record"): cluster.get_supercluster_number() self.record.add_supercluster(cluster) assert cluster.get_supercluster_number() == 1
def test_conversion(self): kind = SuperClusterKind.INTERLEAVED original = SuperCluster(kind, self.record.get_clusters(), smiles="dummy smiles", polymer="dummy polymer") self.record.add_supercluster(original) assert original.products == ["a"] assert len(original.clusters) == 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_supercluster_number()) ] assert bio.qualifiers["SMILES"] == ["dummy smiles"] assert bio.qualifiers["polymer"] == ["dummy polymer"] assert bio.qualifiers["contig_edge"] == ["True"] regenerated = SuperCluster.from_biopython(bio) assert isinstance(regenerated, TemporarySuperCluster) assert regenerated.products == original.products assert regenerated.location == original.location assert regenerated.smiles_structure == original.smiles_structure assert regenerated.polymer == original.polymer assert regenerated.clusters == [ cluster.get_cluster_number() for cluster in self.record.get_clusters() ] assert regenerated.kind == original.kind real = regenerated.convert_to_real_feature(self.record) assert isinstance(real, SuperCluster) assert len(real.clusters) == len(self.record.get_clusters()) for reference, record_cluster in zip(real.clusters, self.record.get_clusters()): assert reference is record_cluster # attempt a conversion with a record missing the cluster self.record.clear_clusters() with self.assertRaisesRegex(ValueError, "Not all referenced clusters are present"): regenerated.convert_to_real_feature(self.record)