def extractMutationLabel(generic_mutation): """ extracts a mutation-label string from a mutation, e.g. ["2vuj::A:N25R/A:S27T/A:N181D"] -> "N25R/S27T/N181D" """ if isinstance(generic_mutation, str): mutations = [generic_mutation] elif isinstance(generic_mutation, list): mutations = generic_mutation elif isinstance(generic_mutation, dict): """ do nothing """ label = "" if isinstance(generic_mutation, dict): for key in generic_mutation.keys(): code1, resName = lib.convertResidueCode(resName=key[:3]) code2, resName = lib.convertResidueCode(resName=generic_mutation[key]['label'][:3]) label += "/%s%d%s" % (code1, int(key[3:7]), code2) else: for mutation in mutations: pdbcode, mutation_string = splitStringMutationInTwo(mutation) single_mutations = splitIntoSingleMutations(mutation_string) for single_mutation in single_mutations: chainID1, chainID2, gotcha = splitSingleMutation(single_mutation) label += "/%s" % (gotcha) return label[1:]
def splitIntoMutationData(generic_mutation): """ split 'mutation' into multiple mutation data, e.g. 'A:N25R/A:N181D' -> [[A, N, 25, R], [A, N, 181, D]] """ # making sure mutation is used properly mutation_data = [] if isinstance(generic_mutation, str): mutation_list = [generic_mutation] elif isinstance(generic_mutation, list): mutation_list = generic_mutation elif isinstance(generic_mutation, dict): for key in generic_mutation.keys(): chainID1 = generic_mutation[key]['target'][-1] code1, resName = lib.convertResidueCode(resName=generic_mutation[key]['target'][:3]) resNumb = int(generic_mutation[key]['target'][3:7]) code2, resName = lib.convertResidueCode(resName=generic_mutation[key]['label'][:3]) mutation_data.append([chainID1, code1, resNumb, code2]) if len(mutation_data) > 0: return mutation_data else: for mutation in mutation_list: thermophile, mutation_string = splitStringMutationInTwo(mutation) for single_mutation in splitIntoSingleMutations(mutation_string): chainID1, chainID2, mutation_label = splitSingleMutation(single_mutation) code1, resNumb, code2 = extractSingleMutationInformation(mutation_label) mutation_data.append([chainID1, code1, resNumb, code2]) return mutation_data
def makeMutationAddendum(target=None, template=None, options=None): """ converting two residue labels to a mutation tag """ if target == " gap " or template == " gap ": return None else: code1, resName = convertResidueCode(resName=target[:3]) code2, resName = convertResidueCode(resName=template[:3]) resNumb = int(target[3:7]) return "%s%d%s" % (code1, resNumb, code2)
def makeSequence(self, mutation=None): """ creates a sequence from the chain object to be used in Scwrl-mutations """ sequence = "" for residue in self.residues: if residue.resName in lib.residueList("standard"): if mutation == None: code, resName = lib.convertResidueCode(resName=residue.resName) sequence += code.lower() elif residue.label in mutation: new_label = mutation[residue.label]['label'] code, resName = lib.convertResidueCode(resName=new_label[:3]) sequence += code.upper() else: code, resName = lib.convertResidueCode(resName=residue.resName) sequence += code.lower() return sequence
def setAlignment(self, alignment=None): """ Sets the alignment information (from self) """ if alignment == None: print("setting alignment according to protein") self.alignment = "" for residue in self.residues: if residue.resName != "N+ " and residue.resName != "C- ": code, resName = lib.convertResidueCode(resName=residue.resName) if code in "ARNDCQEGHILKMFPSTWYV": self.alignment += (code) print(self.alignment) print( len(self.alignment) ) else: self.alignment = alignment
def recastIntoDictionary(input_mutation=None, alignment=None, protein=None, chains=None): """ recasting the mutation from string or list format into dictionary format; needed for more complicated mutations """ if protein == None: mesophile = None else: mesophile = protein.name # making sure mutation is used properly if isinstance(input_mutation, str): mutation_list = [input_mutation] elif isinstance(input_mutation, list): mutation_list = input_mutation elif isinstance(input_mutation, dict): return input_mutation dictionary_mutation = {} for mutation in mutation_list: thermophile, mutation_string = splitStringMutationInTwo(mutation) for single_mutation in splitIntoSingleMutations(mutation_string): chainID1, chainID2, mutation_label = splitSingleMutation(single_mutation) code1, resNumb, code2 = extractSingleMutationInformation(mutation_label) code, resName_mesophile = lib.convertResidueCode(code=code1) code, resName_thermophile = lib.convertResidueCode(code=code2) if alignment == None or mesophile == None: # No alignment mutation as far as I can judge, just reformatting thermophile = None template = None # repeat for all chains if chainID1 == None: chainIDs = chains else: chainIDs = [[chainID1, None]] for chainID, chainID2 in chainIDs: key = "%s%4d%2s" % (resName_mesophile, resNumb, chainID) new_label = "%s%4d%2s" % (resName_thermophile, resNumb, chainID) dictionary_mutation[key] = {'pdb': thermophile, 'target': key, 'template': template, 'label': new_label} else: # preparing for alignment or overlap mutation # thermophile resNumb_mesophile = alignment[thermophile][mesophile]["resNumb"] resNumb_thermophile = alignment[thermophile][thermophile]["resNumb"] for i in range(len(alignment[thermophile][mesophile]["sequence"])): if alignment[thermophile][mesophile]["sequence"][i] in "ARNDCQEGHILKMFPSTWYV": resNumb_mesophile += 1 if alignment[thermophile][thermophile]["sequence"][i] in "ARNDCQEGHILKMFPSTWYV": resNumb_thermophile += 1 if resNumb_mesophile == resNumb: if chainID1 == None and chainID2 == None: chainIDs = chains else: chainIDs = [[chainID1, chainID2]] for chainID1, chainID2 in chainIDs: key = "%s%4d%2s" % (resName_mesophile, resNumb, chainID1) template = "%s%4d%2s" % (resName_thermophile, resNumb_thermophile, chainID2) new_label = "%s%4d%2s" % (resName_thermophile, resNumb_mesophile, chainID1) dictionary_mutation[key] = {'pdb': thermophile, 'target': key, 'template': template, 'label': new_label} return dictionary_mutation