def _coreMapping(self): """ Build the Mapping ClassSerializer. @return: Mapping ; A ClassSerializer object @rtype: object """ Cross = self.makeCrossmap() if not Cross: return None if self.parseTree.SingleAlleleVarSet: mutations = [v.RawVar for v in self.parseTree.SingleAlleleVarSet] elif self.parseTree.RawVar: mutations = [self.parseTree.RawVar] else: self.__output.addMessage( __file__, 4, 'ENOVARIANT', 'Variant description contains no mutation.') return None mappings = [] for mutation in mutations: if not mutation.StartLoc: self.__output.addMessage(__file__, 4, 'EUNKNOWN', 'Variant type not supported.') return None # Get the coordinates of the start position startmain, startoffset, start_g = \ self._getcoords(Cross, mutation.StartLoc, self.parseTree.RefType) # If there is an end position, calculate the coordinates. if mutation.EndLoc: endmain, endoffset, end_g = \ self._getcoords(Cross, mutation.EndLoc, self.parseTree.RefType) else: end_g, endmain, endoffset = start_g, startmain, startoffset # Assign these values to the Mapping ClassSerializer V = Mapping() V.startmain = startmain V.startoffset = startoffset V.endmain = endmain V.endoffset = endoffset V.start_g = start_g V.end_g = end_g V.mutationType = mutation.MutationType mappings.append(V) return mappings
def _coreMapping(self): """ Build the Mapping ClassSerializer. @return: Mapping ; A ClassSerializer object @rtype: object """ Cross = self.makeCrossmap() if not Cross: return None if self.parseTree.SingleAlleleVarSet: mutations = [v.RawVar for v in self.parseTree.SingleAlleleVarSet] else: mutations = [self.parseTree.RawVar] mappings = [] for mutation in mutations: if not mutation.StartLoc: return None # Get the coordinates of the start position startmain, startoffset, start_g = \ self._getcoords(Cross, mutation.StartLoc, self.parseTree.RefType) # If there is an end position, calculate the coordinates. if mutation.EndLoc: endmain, endoffset, end_g = \ self._getcoords(Cross, mutation.EndLoc, self.parseTree.RefType) else: end_g, endmain, endoffset = start_g, startmain, startoffset # Assign these values to the Mapping ClassSerializer V = Mapping() V.startmain = startmain V.startoffset = startoffset V.endmain = endmain V.endoffset = endoffset V.start_g = start_g V.end_g = end_g V.mutationType = mutation.MutationType mappings.append(V) return mappings
def mainMapping(self, accNo, mutation): """ One of the entry points (called by the HTML publisher). @arg accNo: transcript (NM_) accession number (with version?) @type accNo: unicode @arg mutation: the 'mutation' (e.g. c.123C>T) @type mutation: unicode @return: ClassSerializer object @rtype: object """ variant = "%s:%s" % (accNo, mutation) if self._parseInput(variant): acc = self.parseTree.LrgAcc or self.parseTree.RefSeqAcc try: version = int(self.parseTree.Version) except ValueError: version = None self._get_mapping(acc, version) mappings = self._coreMapping() errors = [] for message in self.__output.getMessages(): soap_message = SoapMessage() soap_message.errorcode = message.code soap_message.message = message.description errors.append(soap_message) mapping = Mapping() mapping.messages = errors if not mappings: # Something went wrong mapping.errorcode = len(errors) return mapping mapping.errorcode = 0 if len(mappings) == 1: return mappings[0] mapping.mutationType = 'compound' # Now we have to do some tricks to combine the information from # possibly multiple variants into one Mapping object. # Todo: Maybe it is better to use self.mapping.orientation here. min_g = 9000000000 max_g = 0 forward = True for m in mappings: if m.start_g > m.end_g: forward = False if m.start_g < min_g: min_g = m.start_g min_main = m.startmain min_offset = m.startoffset if m.end_g < min_g: min_g = m.end_g min_main = m.endmain min_offset = m.endoffset if m.start_g > max_g: max_g = m.start_g max_main = m.startmain max_offset = m.startoffset if m.end_g > max_g: max_g = m.end_g max_main = m.endmain max_offset = m.endoffset if forward: mapping.startmain = min_main mapping.startoffset = min_offset mapping.endmain = max_main mapping.endoffset = max_offset mapping.start_g = min_g mapping.end_g = max_g else: mapping.startmain = max_main mapping.startoffset = max_offset mapping.endmain = min_main mapping.endoffset = min_offset mapping.start_g = max_g mapping.end_g = min_g return mapping