示例#1
0
 def from_json(data: Dict, _record: secmet.Record) -> "ThiopeptideMotif":
     """ Builds a ThiopeptideMotif from a JSON object"""
     args = []
     args.append(serialiser.location_from_json(data["location"]))
     for arg_name in ["core", "leader", "locus_tag", "monoisotopic_mass",
                      "molecular_weight", "alternative_weights",
                      "peptide_subclass", "score", "rodeo_score", "macrocycle",
                      "tail", "core_features", "mature_weights",
                      "amidation"]:
         args.append(data[arg_name])
     # pylint doesn't do well with the splat op, so don't report errors
     return ThiopeptideMotif(*args)  # pylint: disable=no-value-for-parameter
示例#2
0
    def convert(self, location, expected_type=FeatureLocation):
        assert isinstance(location, expected_type)

        before_string = str(location)
        print(before_string)  # just for help when debugging a failing test
        after_string = serialiser.location_to_json(location)
        assert isinstance(after_string, str)
        assert before_string == after_string

        new_location = serialiser.location_from_json(after_string)
        assert isinstance(new_location, expected_type)

        return new_location
示例#3
0
 def from_json(data: Dict[str, Any]) -> "LassopeptideMotif":
     """ Converts a JSON representation of the motif back into an instance
         of LassopeptideMotif
     """
     args = []
     args.append(serialiser.location_from_json(data["location"]))
     for arg_name in [
             "leader", "core", "tail", "locus_tag", "monoisotopic_mass",
             "molecular_weight", "cut_mass", "cut_weight", "num_bridges",
             "peptide_subclass", "score", "rodeo_score", "macrolactam"
     ]:
         args.append(data[arg_name])
     # pylint doesn't do well with the splat op, so don't report errors
     return LassopeptideMotif(*args)  # pylint: disable=no-value-for-parameter
示例#4
0
 def from_json(json: Dict[str, Any], record: secmet.Record) -> "SactiResults":
     if json.get("schema_version") != SactiResults.schema_version:
         logging.warning("Discarding Sactipeptide results, schema version mismatch")
         return None
     results = SactiResults(json["record_id"])
     for locus, motifs in json["motifs"].items():
         for motif in motifs:
             results.motifs_by_locus[locus].append(SactipeptideMotif.from_json(motif))
     results.clusters = {int(key): set(val) for key, val in json["clusters"].items()}
     for location, name in json["new_cds_features"]:
         loc = serialiser.location_from_json(location)
         cds = all_orfs.create_feature_from_location(record, loc, label=name)
         results.new_cds_features.add(cds)
     return results
示例#5
0
 def from_json(data: Dict[str, Any]) -> "LanthipeptideMotif":
     """ Converts a JSON representation of the motif back into an instance
         of LanthipeptideMotif
     """
     args = []
     args.append(serialiser.location_from_json(data["location"]))
     args.append(data["core"])
     for arg_name in [
             "leader", "locus_tag", "monoisotopic_mass", "molecular_weight",
             "alternative_weights", "lan_bridges", "peptide_subclass",
             "score", "rodeo_score", "aminovinyl_group", "chlorinated",
             "oxygenated", "lactonated"
     ]:
         args.append(data[arg_name])
     # pylint doesn't do well with the splat op, so don't report errors
     return LanthipeptideMotif(*args)  # pylint: disable=no-value-for-parameter
示例#6
0
 def add_to_record(self, record: Record) -> None:
     db_version = pfamdb.get_db_version_from_path(self.database)
     for i, hit in enumerate(self.hits):
         pfam_feature = PFAMDomain(serialiser.location_from_json(
             hit["location"]),
                                   description=hit["description"],
                                   protein_start=hit["protein_start"],
                                   protein_end=hit["protein_end"])
         for key in [
                 "label", "locus_tag", "domain", "evalue", "score",
                 "translation", "db_xref"
         ]:
             setattr(pfam_feature, key, hit[key])
         pfam_feature.tool = self.tool
         pfam_feature.database = db_version
         pfam_feature.detection = "hmmscan"
         pfam_feature.domain_id = "{}_{}_{:04d}".format(
             self.tool, pfam_feature.locus_tag, i + 1)
         record.add_pfam_domain(pfam_feature)
示例#7
0
 def from_json(json: Dict[str, Any]) -> "SactipeptideMotif":
     """ Regenerate an instance of the class from a JSON representation """
     location = serialiser.location_from_json(json["location"])
     return SactipeptideMotif(location, json["name"], json["score"],
                              json["leader"], json["core"])