def to_json(self) -> Dict[str, Any]: """ Constructs a JSON representation from the RuleDetectionResults instance """ cds_results_json = [ ] # type: List[Tuple[Dict[str, Any], List[Dict[str, Any]]]] json = {"tool": self.tool, "cds_by_cluster": cds_results_json} for border, cds_results in self.cds_by_cluster.items(): json_border = serialiser.feature_to_json(border.to_biopython()[0]) json_cds_results = [result.to_json() for result in cds_results] cds_results_json.append((json_border, json_cds_results)) return json
def to_json(self) -> Dict[str, Any]: """ Constructs a JSON representation from the RuleDetectionResults instance """ cds_results_json: List[Tuple[Dict[str, Any], List[Dict[str, Any]]]] = [] json = { "schema_version": self.schema_version, "tool": self.tool, "cds_by_protocluster": cds_results_json, "outside_protoclusters": [result.to_json() for result in self.cdses_outside_clusters], } for cluster, cds_results in self.cds_by_cluster.items(): json_cluster = serialiser.feature_to_json(cluster.to_biopython()[0]) json_cds_results = [result.to_json() for result in cds_results] cds_results_json.append((json_cluster, json_cds_results)) return json
def to_json(self) -> Dict[str, Any]: subregions = [] promoters = [] for cluster in self.subregions: subregions.append(feature_to_json(cluster.to_biopython()[0])) for promoter in self.promoters: promoters.append(promoter.to_json()) return { "record_id": self.record_id, "subregions": subregions, "promoters": promoters, "max_percentage": MAX_PERCENTAGE, "max_gap_length": MAX_GAP_LENGTH }
def test_simple_feature(self): location = FeatureLocation(1, 6, strand=1) f_type = "test type" qualifiers = {"a": ["1", "2"], "b": ["3", "4"]} f_id = "dummy id" # skipping biopython deprecated members: ref, ref_db, strand, location_operator feature = SeqFeature(location=location, type=f_type, qualifiers=qualifiers, id=f_id) print(str(feature)) json = serialiser.feature_to_json(feature) print(json) # for debugging failures new_feature = serialiser.feature_from_json(json) print(str(new_feature)) assert new_feature.qualifiers == feature.qualifiers assert new_feature.id == feature.id assert new_feature.type == feature.type assert str(new_feature.location) == str(new_feature.location)