Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for _to_hgvs for CNVs #260

Open
korikuzma opened this issue Sep 18, 2023 · 4 comments
Open

Add support for _to_hgvs for CNVs #260

korikuzma opened this issue Sep 18, 2023 · 4 comments
Labels
2.0-alpha Issues related to VRS 2.0-alpha branch priority:low Low priority Stale-exempt

Comments

@korikuzma
Copy link
Contributor

We're either going to add support for _to_hgvs for the CnvTranslator. Or we can deprecate the translate_to methods. Up to @larrybabb

@korikuzma
Copy link
Contributor Author

Initial copy/paste work from AlleleTranslator's _to_hgvs

    def _to_hgvs(self, vo, namespace="refseq"):
        if vo.type != "CopyNumberChange":
            raise ValueError("Must provide CopyNumberChange because it's lossy")

        if not isinstance(vo.location.sequenceReference, models.SequenceReference):
            raise TypeError(
                "`vo.location.sequenceReference` expects a `SequenceReference`"
            )

        sequence = f"ga4gh:{export_sequencelocation_sequence_id(vo.location.sequenceReference)}"
        aliases = self.data_proxy.translate_sequence_identifier(sequence, namespace)

        # infer type of sequence based on accession
        # TODO: move to bioutils
        stypes = list(set(t for t in (self._ir_stype(a) for a in aliases) if t))
        if len(stypes) != 1:
            raise ValueError(f"Couldn't infer sequence type for {sequence} ({stypes})")
        stype = stypes[0]

        start, end = vo.location.start, vo.location.end
        start += 1

        ival = hgvs.location.Interval(
            start=hgvs.location.SimplePosition(start),
            end=hgvs.location.SimplePosition(end)
        )

        copy_change = vo.copyChange
        if copy_change == models.CopyChange.EFO_0030067.value:
            edit = hgvs.edit.NARefAlt(ref="", alt=None, uncertain=False)
        elif copy_change == models.CopyChange.EFO_0030070.value:
            edit = hgvs.edit.Dup(ref="", uncertain=False)
        else:
            raise ValueError("")

        posedit = hgvs.posedit.PosEdit(pos=ival, edit=edit)
        var = hgvs.sequencevariant.SequenceVariant(
            ac=None,
            type=stype,
            posedit=posedit)

        hgvs_exprs = []
        for alias in aliases:
            ns, a = alias.split(":")
            # skip GRCh accessions unless specifically requested
            # because they are ambiguous without their namespace,
            # which can't be included in HGVS expressions
            # TODO: use default_assembly_name here
            if ns.startswith("GRC") and namespace is None:
                continue

            if not (any(a.startswith(pfx) for pfx in ("NM", "NP", "NC", "NG"))):
                continue

            var.ac = a

            try:
                if not namespace.startswith("GRC"):
                    # if the namespace is GRC, can't normalize, since hgvs can't deal with it
                    hgvs_tools = self._get_hgvs_tools()
                    parsed = hgvs_tools.parse(str(var))
                    var = hgvs_tools.normalize(parsed)

                hgvs_exprs += [str(var)]
            except hgvs.exceptions.HGVSDataNotAvailableError:
                _logger.warning(f"No data found for accession {a}")
        return list(set(hgvs_exprs))

@korikuzma korikuzma added 2.0-alpha Issues related to VRS 2.0-alpha branch priority:low Low priority labels Sep 18, 2023
Copy link

This issue was marked stale due to inactivity.

@sivangbagri
Copy link
Contributor

@korikuzma Is this still open ? Can I work on this?

@korikuzma
Copy link
Contributor Author

@sivangbagri I'm not sure the status of this. @larrybabb what are your thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.0-alpha Issues related to VRS 2.0-alpha branch priority:low Low priority Stale-exempt
Projects
None yet
Development

No branches or pull requests

3 participants