def add_location(self, seqid, gene, params, sr): """Get a gene's Sequence Location. :param str seqid: The sequence ID. :param Feature gene: A gene from the source file. :param dict params: The transformed gene record. :param SeqRepo sr: Access to the SeqRepo :return: A dictionary of a GA4GH VRS SequenceLocation. """ location = dict() aliases = self.get_aliases(sr, seqid) if not aliases: return location sequence_id = [a for a in aliases if a.startswith('ga4gh')][0] if gene.start != '.' and gene.end != '.' and sequence_id: if 0 <= gene.start <= gene.end: seq_location = models.SequenceLocation( sequence_id=sequence_id, start=models.Number(value=gene.start - 1, type="Number"), end=models.Number(value=gene.end, type="Number"), type="SequenceLocation" ) seq_location.id = ga4gh_identify(seq_location) location = seq_location.as_dict() else: logger.info(f"{params['concept_id']} has invalid interval:" f"start={gene.start - 1} end={gene.end}") return location
def add_location(self, location): """Get a gene's Chromosome Location. :param dict location: A gene's location. :return: A dictionary of a GA4GH VRS ChromosomeLocation. """ chr_location = models.ChromosomeLocation(species_id="taxonomy:9606", chr=location['chr'], start=location['start'], end=location['end'], type="ChromosomeLocation") chr_location.id = ga4gh_identify(chr_location) return chr_location.as_dict()
def test_vr(): assert a.as_dict() == allele_dict assert ga4gh_serialize( a.location.interval ) == b'{"end":55181320,"start":55181319,"type":"SimpleInterval"}' assert ga4gh_serialize( a.location ) == b'{"interval":{"end":55181320,"start":55181319,"type":"SimpleInterval"},"sequence_id":"F-LrLMe1SRpfUZHkQmvkVKFEGaoDeHul","type":"SequenceLocation"}' assert sha512t24u(ga4gh_serialize( a.location)) == '5D9eG-ev4fA7mYIpOpDEe-4Am1lzPZlQ' assert ga4gh_digest(a.location) == '5D9eG-ev4fA7mYIpOpDEe-4Am1lzPZlQ' assert ga4gh_identify( a.location) == 'ga4gh:VSL.5D9eG-ev4fA7mYIpOpDEe-4Am1lzPZlQ' assert ga4gh_serialize( a ) == b'{"location":"5D9eG-ev4fA7mYIpOpDEe-4Am1lzPZlQ","state":{"sequence":"T","type":"SequenceState"},"type":"Allele"}' assert ga4gh_digest(a) == 'vU0meY5wGjpyRLCjSxCfb2Jlruyn2adL' assert ga4gh_identify(a) == 'ga4gh:VA.vU0meY5wGjpyRLCjSxCfb2Jlruyn2adL' assert a.as_dict() == { 'location': { 'interval': { 'end': 55181320, 'start': 55181319, 'type': 'SimpleInterval' }, 'sequence_id': 'ga4gh:SQ.F-LrLMe1SRpfUZHkQmvkVKFEGaoDeHul', 'type': 'SequenceLocation' }, 'state': { 'sequence': 'T', 'type': 'SequenceState' }, 'type': 'Allele' }
def _post_process_imported_allele(self, allele): """Provide common post-processing for imported Alleles IN-PLACE. """ if self.translate_sequence_identifiers: seq_id = self.data_proxy.translate_sequence_identifier( allele.location.sequence_id._value, "ga4gh")[0] allele.location.sequence_id = seq_id if self.normalize: self._normalize_allele(allele) if self.identify: allele._id = ga4gh_identify(allele) return allele
def put(body): request = body defn = request.pop("definition") av = get_anyvar() messages = [] if "members" in defn: return {"messages": ["unsupported"]}, 400 if "member_ids" in defn: vo = models.VariationSet(members=defn["member_ids"]) vo._id = ga4gh_identify(vo) av.put_object(vo) result = { "messages": messages, "data": vo.as_dict(), } return result, 200
a0_dict = { 'location': { 'interval': {'end': 44908822, 'start': 44908821, 'type': 'SimpleInterval'}, 'sequence_id': 'ga4gh:SQ.IIB53T8CNeJJdUqzn9V_JnRtQadwWCbl', 'type': 'SequenceLocation' }, 'state': { 'sequence': 'T', 'type': 'SequenceState' }, 'type': 'Allele' } a0 = models.Allele(**a0_dict) a0id = ga4gh_identify(a0) assert a0id == "ga4gh:VA.EgHPXXhULTwoP4-ACfs-YCXaeUQJBjH_" a0._id = a0id a0l = a0.location a0lid = ga4gh_identify(a0l) assert a0lid == "ga4gh:VSL.u5fspwVbQ79QkX6GHLF8tXPCAXFJqRPx" ros.redis.flushdb() # Danger! # db looks empty? assert len(ros) == 0 assert list(ros.keys()) == [] # add Allele
def create_text(self, defn): vo = models.Text(definition=defn) vo._id = ga4gh_identify(vo) return vo
def put_object(self, vo): v = vrs_enref(vo, self.object_store) _id = ga4gh_identify(v) return _id