How to use the cogent3.util.misc.get_object_provenance function in cogent3

To help you get started, we’ve selected a few cogent3 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cogent3 / cogent3 / tests / test_core / test_sequence.py View on Github external
def test_to_json(self):
        """to_json roundtrip recreates to_dict"""
        r = self.SEQ("AAGGCC", name="seq1")
        got = json.loads(r.to_json())
        expect = {
            "name": "seq1",
            "seq": "AAGGCC",
            "moltype": r.moltype.label,
            "info": None,
            "type": get_object_provenance(r),
            "version": __version__,
        }
        self.assertEqual(got, expect)
github cogent3 / cogent3 / tests / test_core / test_sequence.py View on Github external
def test_to_rich_dict(self):
        """Sequence to_dict works"""
        r = self.SEQ("AAGGCC", name="seq1")
        got = r.to_rich_dict()
        expect = {
            "name": "seq1",
            "seq": "AAGGCC",
            "moltype": r.moltype.label,
            "info": None,
            "type": get_object_provenance(r),
            "version": __version__,
        }
        self.assertEqual(got, expect)
github cogent3 / cogent3 / tests / test_util / test_misc.py View on Github external
def test_get_object_provenance(self):
        """correctly deduce object provenance"""
        result = get_object_provenance("abncd")
        self.assertEqual(result, "str")
        from cogent3 import DNA

        got = get_object_provenance(DNA)
        self.assertEqual(got, "cogent3.core.moltype.MolType")
        from cogent3.evolve.models import HKY85

        sm = HKY85()
        got = get_object_provenance(sm)
        self.assertEqual(
            got, "cogent3.evolve.substitution_model." "TimeReversibleNucleotide"
        )

        # handle a type
        from cogent3 import SequenceCollection
github cogent3 / cogent3 / tests / test_core / test_alignment.py View on Github external
def test_to_rich_dict(self):
        """to_rich_dict produces correct dict"""
        aln = self.Class({"seq1": "ACGG", "seq2": "CGCA", "seq3": "CCG-"})
        try:
            seq_type = get_object_provenance(aln.seqs[0].data)
        except AttributeError:
            seq_type = get_object_provenance(aln.seqs[0])

        got = aln.to_rich_dict()
        expect = {
            "seqs": {
                "seq1": {
                    "name": "seq1",
                    "seq": "ACGG",
                    "info": None,
                    "type": seq_type,
                    "moltype": aln.moltype.label,
                    "version": __version__,
                },
                "seq2": {
                    "name": "seq2",
                    "seq": "CGCA",
                    "info": None,
github cogent3 / cogent3 / src / cogent3 / core / alphabet.py View on Github external
def to_rich_dict(self, for_pickle=False):
        data = {"motifset": tuple(self), "gap": self.gap, "moltype": self.moltype}
        if not for_pickle:
            data["type"] = get_object_provenance(self)
            data["moltype"] = self.moltype.label
            data["version"] = __version__
            if hasattr(self, "_gc"):
                data["genetic_code"] = self._gc.name
        return data
github cogent3 / cogent3 / src / cogent3 / app / result.py View on Github external
def to_rich_dict(self):
        """returns the rich dict on values"""
        result = {
            "type": get_object_provenance(self),
            "result_construction": self._construction_kwargs,
            "version": __version__,
        }
        items = []
        for key, val in self.items():
            try:
                val = val.to_rich_dict()
            except AttributeError:
                pass
            items.append([key, val])
        result["items"] = items
        return result
github cogent3 / cogent3 / src / cogent3 / evolve / likelihood_function.py View on Github external
# there's a mix of assertions
            # for "storage", make this indeterminate in those cases
            unique_Q = None

        data = dict(
            model=model,
            tree=tree,
            alignment=alignment,
            likelihood_construction=data,
            param_rules=self.get_param_rules(),
            lnL=self.get_log_likelihood(),
            nfp=self.get_num_free_params(),
            motif_probs=mprobs,
            DLC=DLC,
            unique_Q=unique_Q,
            type=get_object_provenance(self),
            name=self.get_name(),
            version=__version__,
        )
        return data
github cogent3 / cogent3 / src / cogent3 / evolve / substitution_model.py View on Github external
def to_rich_dict(self, for_pickle=False):
        data = self._serialisable.copy()
        if not for_pickle:
            for key, value in data.items():
                type_ = get_object_provenance(value)
                if type_.startswith("cogent3"):
                    try:
                        value = value.to_rich_dict(for_pickle=False)
                    except AttributeError:
                        pass
                    finally:
                        data[key] = value
            if "predicates" in data and data["predicates"]:
                data["predicates"] = [str(p) for p in data["predicates"]]
            data["type"] = get_object_provenance(self)
            data["version"] = __version__
        return data
github cogent3 / cogent3 / src / cogent3 / evolve / substitution_model.py View on Github external
def to_rich_dict(self, for_pickle=False):
        data = self._serialisable.copy()
        if not for_pickle:
            for key, value in data.items():
                type_ = get_object_provenance(value)
                if type_.startswith("cogent3"):
                    try:
                        value = value.to_rich_dict(for_pickle=False)
                    except AttributeError:
                        pass
                    finally:
                        data[key] = value
            if "predicates" in data and data["predicates"]:
                data["predicates"] = [str(p) for p in data["predicates"]]
            data["type"] = get_object_provenance(self)
            data["version"] = __version__
        return data