Beispiel #1
0
    def from_json(json: Dict[str, Any],
                  record: Record) -> Optional["CassisResults"]:
        # throw away the results if the conditions are different
        if json["record_id"] != record.id:
            logging.debug(
                "Record identifiers don't match, discarding previous results")
            return None
        if json["max_percentage"] != MAX_PERCENTAGE:
            logging.debug(
                "CASSIS commonality threshold changed, discarding previous results"
            )
            return None
        if json["max_gap_length"] != MAX_GAP_LENGTH:
            logging.debug(
                "CASSIS maximum island length changed, discarding previous results"
            )
            return None

        subregions = []
        promoters = []  # type: List[Promoter]
        for cluster in json["subregions"]:
            subregions.append(
                SubRegion.from_biopython(feature_from_json(cluster)))
        for promoter in json["promoters"]:
            if promoter["type"] == "CombinedPromoter":
                promoters.append(CombinedPromoter.from_json(promoter))
            else:
                promoters.append(Promoter.from_json(promoter))
        results = CassisResults(record.id)
        results.subregions = subregions
        results.promoters = promoters
        return results
Beispiel #2
0
    def from_json(json: Dict[str, Any], record: Record) -> "RuleDetectionResults":
        """ Constructs a RuleDetectionResults instance from a JSON representation """
        cds_by_cluster = {}
        for json_cluster, json_cds_results in json["cds_by_cluster"]:
            cluster = Cluster.from_biopython(serialiser.feature_from_json(json_cluster))
            cds_results = [CDSResults.from_json(result_json, record) for result_json in json_cds_results]
            cds_by_cluster[cluster] = cds_results

        return RuleDetectionResults(cds_by_cluster, json["tool"])
    def from_json(json: Dict[str, Any], record: Record) -> Optional["RuleDetectionResults"]:
        """ Constructs a RuleDetectionResults instance from a JSON representation """
        if RuleDetectionResults.schema_version != json.get("schema_version", 1):
            return None

        cds_by_cluster = {}
        for json_cluster, json_cds_results in json["cds_by_protocluster"]:
            cluster = Protocluster.from_biopython(serialiser.feature_from_json(json_cluster))
            cds_results = [CDSResults.from_json(result_json, record) for result_json in json_cds_results]
            cds_by_cluster[cluster] = cds_results

        cdses_outside = [CDSResults.from_json(chunk, record) for chunk in json["outside_protoclusters"]]

        return RuleDetectionResults(cds_by_cluster, json["tool"], cdses_outside)
Beispiel #4
0
    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)