Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(1)  |  Call(1)  |  Derive(0)  |  Import(0)

        def mutationSetFromSequencesAndStructure(initialSequence, targetSequence, structure, name='Test', verbose=True):

	import PEATDB.sequence_alignment as SequenceAlignment

	if len(initialSequence) != len(targetSequence):
		raise Exceptions.ProteinDesignToolException, 'Sequences are not the same length'

	if initialSequence.find('-') != -1:
		return None
	elif targetSequence.find('-') != -1:
		return None	

	#Find the mutations in targetSequence relative to initial
	mutations = []
	for count in range(len(initialSequence)):
		if initialAA != targetAA:
			mutations.append([count, initialAA, targetAA])
	#Align the initial sequence with each chain in the pdb
	chainSeqs = GetChainSequences(structure)
	chainResidues = GetChainResidues(structure)
	chains = chainSeqs.keys()

	align = {}
	for chain in chains:
		aligner = SequenceAlignment.NW(chainSeqs[chain],initialSequence, gap=2.0)
		chainToInitial = data[2]
		initialToChain = data[3]
		length = len(data[0])
		identical = aligner.sequence_identity*length/100
		percentIdentical = identical/len(chainSeqs[chain])
		notFound = True
		i = 0
		while notFound:
			if chainToInitial[i] != '-':
				notFound = False
				firstAlignedResidue = i
				i += 1
		notFound = True
		i = len(chainToInitial) - 1				
		while notFound:
			if chainToInitial[i] != '-':
				notFound = False
				lastAlignedResidue = i
				i -= 1		
		if verbose:
			print '%lf percent of residues in chain %s were matched to wild-type' % (percentIdentical, chain)
		wtAlign = [chainToInitial[firstAlignedResidue], chainToInitial[lastAlignedResidue]]
		chainAlign = [firstAlignedResidue, lastAlignedResidue]
		align[chain] = [percentIdentical, chainAlign, wtAlign, initialToChain]
	#Find overlapping chains
	i = 0
	overlap = {}		
	for chain in chains:
		end = align[chain][2][1]
		overlap[chain] = []
		for chain2 in chains[j:]:
			start = align[chain2][2][0]
			if start < end:
				if verbose:
					print 'Chain %s and %s overlap' % (chain, chain2)
			j += 1
		i+= 1		

	#For overlapping chains only keep the one that has the highest alignment	
	discard = set()
	for chain in chains:
		best = chain
		for id in overlap[chain]:
			if align[id][0] > align[chain][0]:
				best = id
		if verbose:
			print 'Best out of %s is %s - discard others' % (overlap[chain], best)
	if verbose:	
		print 'Discarding ', discard	
	keep = [chain for chain in chains if not chain in discard]			
	mutationSet = MutationSet(name=name)
	unidmuts = []
	originalMutations = []
	for chain in keep:
		if verbose:
			print 'Checking for mutations in chain %s' % chain
		data = align[chain]
		#Get the residue numbering offset
		offset = Utilities.ParseResidueCode(chainResidues[chain][0])[1]
		initialToChain = data[3]
		for mutation in mutations:
			print mutation
			chainRes = initialToChain[mutation[0]]
			if chainRes != '-':
				mutationSet.addMutation(chain, chainRes+offset, mutation[2]) 
				if verbose:
					print '%s not found in chain %s' % (mutation, chain)
		mutations = unidmuts
		unidmuts = []
	if len(mutationSet.mutationCodes()) != len(originalMutations):	
		print 'Could not find residues corresponding to some sequence mutations in pdb structure'	
		mutationSet = None
	return mutationSet					

src/p/e/PEATDB-2.3/PEATDB/Actions.py   PEATDB(Download)
        print X 
        mset = Core.Data.mutationSetFromSequencesAndStructure(refseq, seq, X)
        #prot.Mutations = '+'.join(mset.mutationCodes())
        prot.Mutations = mset.codeString(X)