Esempio n. 1
0
    def to_gaf_2_2_tsv(self) -> List:
        gp_isoforms = "" if not self.subject_extensions else self.subject_extensions[
            0].term

        qual_labels = [
            relations.lookup_uri(curie_util.expand_uri(str(q), strict=False))
            for q in self.qualifiers
        ]
        if self.negated:
            qual_labels.insert(0, "NOT")

        qualifier = "|".join(qual_labels)

        self.object.taxon.namespace = "taxon"
        taxon = str(self.object.taxon)
        if self.interacting_taxon:
            self.interacting_taxon.namespace = "taxon"
            taxon = "{taxon}|{interacting}".format(taxon=taxon,
                                                   interacting=str(
                                                       self.interacting_taxon))

        return [
            self.subject.id.namespace, self.subject.id.identity,
            self.subject.label, qualifier,
            str(self.object.id), "|".join(
                [str(ref) for ref in self.evidence.has_supporting_reference]),
            ecomap.ecoclass_to_coderef(str(self.evidence.type))[0],
            ConjunctiveSet.list_to_str(self.evidence.with_support_from),
            self.aspect if self.aspect else "", self.subject.fullname,
            "|".join(self.subject.synonyms), self.subject.type, taxon,
            self.date, self.provided_by,
            ConjunctiveSet.list_to_str(self.object_extensions), gp_isoforms
        ]
Esempio n. 2
0
    def to_gaf_2_1_tsv(self) -> List:
        """
        Converts the GoAssociation into a "TSV" columnar GAF 2.1 row as a list of strings.
        """
        gp_isoforms = "" if not self.subject_extensions else self.subject_extensions[
            0].term

        allowed_qualifiers = {"contributes_to", "colocalizes_with"}

        # Curie Object -> CURIE Str -> URI -> Label
        qual_labels = [
            relations.lookup_uri(curie_util.expand_uri(str(q), strict=False))
            for q in self.qualifiers
        ]
        if len(qual_labels) == 1 and qual_labels[0] not in allowed_qualifiers:
            logger.warning(
                "Cannot write qualifier `{}` in GAF version 2.1 since only {} are allowed: skipping"
                .format(self.qualifiers[0], ", ".join(allowed_qualifiers)))
            # If the qualifier is wrong, blank out the qualifiers
            qual_labels = []

        if self.negated:
            qual_labels.append("NOT")

        qualifier = "|".join(qual_labels)

        self.object.taxon.namespace = "taxon"
        taxon = str(self.object.taxon)
        if self.interacting_taxon:
            self.interacting_taxon.namespace = "taxon"
            taxon = "{taxon}|{interacting}".format(taxon=taxon,
                                                   interacting=str(
                                                       self.interacting_taxon))

        # For extensions, we provide the to string function on ConjunctElement that
        # calls its `display` method, with the flag to use labels instead of the CURIE.
        # This function is used to turn the whole column correctly into a string
        return [
            self.subject.id.namespace, self.subject.id.identity,
            self.subject.label, qualifier,
            str(self.object.id), "|".join(
                [str(ref) for ref in self.evidence.has_supporting_reference]),
            self.evidence.gaf_evidence_code(),
            ConjunctiveSet.list_to_str(self.evidence.with_support_from),
            self.aspect if self.aspect else "",
            self.subject.fullname_field(), "|".join(self.subject.synonyms),
            gp_type_label_to_curie(self.subject.type[0]), taxon,
            ymd_str(self.date, ""), self.provided_by,
            ConjunctiveSet.list_to_str(
                self.object_extensions,
                conjunct_to_str=lambda conj: conj.display(use_rel_label=True)),
            gp_isoforms
        ]
Esempio n. 3
0
    def to_gpad_1_2_tsv(self) -> List:
        """
        Converts the GoAssociation into a "TSV" columnar GPAD 1.2 row as a list of strings.
        """
        # Curie Object -> CURIE Str -> URI -> Label
        qual_labels = [
            relations.lookup_uri(curie_util.expand_uri(str(q), strict=False))
            for q in self.qualifiers
        ]

        # Try qualifiers first since, if we are going from GAF -> GPAD and the GAF had a qualifier, that would be
        # more specific than the relation, which is calculated from the aspect/Go term.
        if qual_labels == []:
            # If there were no qualifiers, then we'll use the Relation. Gpad requires at least one qualifier (which is the relation)
            qual_labels.append(
                relations.lookup_uri(
                    curie_util.expand_uri(str(self.relation), strict=False)))

        if self.negated:
            qual_labels = ["NOT"] + qual_labels

        qualifier = "|".join(qual_labels)

        props_list = [
            "{key}={value}".format(key=key, value=value)
            for key, value in self.properties
        ]
        return [
            self.subject.id.namespace, self.subject.id.identity, qualifier,
            str(self.object.id), "|".join(
                [str(ref) for ref in self.evidence.has_supporting_reference]),
            str(self.evidence.type),
            ConjunctiveSet.list_to_str(self.evidence.with_support_from),
            str(self.interacting_taxon) if self.interacting_taxon else "",
            ymd_str(self.date, ""), self.provided_by,
            ConjunctiveSet.list_to_str(
                self.object_extensions,
                conjunct_to_str=lambda conj: conj.display(use_rel_label=True)),
            "|".join(props_list)
        ]
Esempio n. 4
0
    def to_gaf_2_2_tsv(self) -> List:
        """
        Converts the GoAssociation into a "TSV" columnar GAF 2.2 row as a list of strings.
        """
        gp_isoforms = "" if not self.subject_extensions else self.subject_extensions[
            0].term

        qual_labels = [
            relations.lookup_uri(curie_util.expand_uri(str(q), strict=False))
            for q in self.qualifiers
        ]
        if self.negated:
            qual_labels.insert(0, "NOT")

        qualifier = "|".join(qual_labels)

        self.object.taxon.namespace = "taxon"
        taxon = str(self.object.taxon)
        if self.interacting_taxon:
            self.interacting_taxon.namespace = "taxon"
            taxon = "{taxon}|{interacting}".format(taxon=taxon,
                                                   interacting=str(
                                                       self.interacting_taxon))

        return [
            self.subject.id.namespace, self.subject.id.identity,
            self.subject.label, qualifier,
            str(self.object.id), "|".join(
                [str(ref) for ref in self.evidence.has_supporting_reference]),
            self.evidence.gaf_evidence_code(),
            ConjunctiveSet.list_to_str(self.evidence.with_support_from),
            self.aspect if self.aspect else "",
            self.subject.fullname_field(), "|".join(self.subject.synonyms),
            gp_type_label_to_curie(self.subject.type[0]), taxon,
            ymd_str(self.date, ""), self.provided_by,
            ConjunctiveSet.list_to_str(
                self.object_extensions,
                conjunct_to_str=lambda conj: conj.display(use_rel_label=True)),
            gp_isoforms
        ]
Esempio n. 5
0
 def __relation_to_label(self) -> str:
     # Curie -> expand to URI -> reverse relation lookup Label
     return relations.lookup_uri(relations.curie_to_obo_uri(self.relation))
Esempio n. 6
0
 def __relation_to_label(self) -> str:
     # Curie -> expand to URI -> reverse relation lookup Label
     return relations.lookup_uri(
         curie_util.expand_uri(str(self.relation), strict=False))