def computeSNVTreeError(snvMatrix, cMatrix, lafMatrix, realTree): sampleNum = snvMatrix.shape[1] cObjMatrix = np.empty(cMatrix.shape, dtype=object) for row in range(0, cMatrix.shape[0]): for col in range(0, cMatrix.shape[1]): currentC = cMatrix[row][col] cObj = C([ 2, int(currentC) ], []) #empty vector to stop initialization of allele combinations dummyCMu = DummyCMu() dummyCMu.c = cObj cObjMatrix[row][col] = dummyCMu [chromosomes, positions, variantIndices] = obtainSomaticVariantIndices() #print variantIndices #Compute the distance pairwise between samples distanceMatrix = np.empty([sampleNum, sampleNum], dtype=float) for sample1 in range(0, sampleNum): for sample2 in range(0, sampleNum): #Make the sample objects. These now need somatic variants and a CMu sample1Obj = Sample(None, None) sample1Obj.bestCMu = cObjMatrix[:, sample1] #the dummy c mu is actually a list of dummy c mu's, so we need to make one for each c #dummyCMu = DummyCMu() #dummyCMu.c = cObjMatrix[:,sample1] #sample1Obj.bestCMu = dummyCMu sample1Obj.somaticVariants = snvMatrix[:, sample1] sample1Obj.somaticVariantsInd = variantIndices sample1Obj.measurements = LAF(lafMatrix[:, sample1], chromosomes, positions, positions) sample2Obj = Sample(None, None) #dummyCMu = DummyCMu() #dummyCMu.c = cObjMatrix[:,sample2] sample2Obj.bestCMu = cObjMatrix[:, sample2] sample2Obj.somaticVariants = snvMatrix[:, sample2] sample2Obj.somaticVariantsInd = variantIndices sample2Obj.measurements = LAF(lafMatrix[:, sample2], chromosomes, positions, positions) #The distance can be computed for the entire column at once using the FST [ messages, dist ] = SomaticVariantDistance().computeDistanceBetweenSomaticVariants( sample1Obj, sample2Obj, sample1, sample2) distanceMatrix[sample1, sample2] = dist #Compute the MST fullGraph = generateInitialTree(distanceMatrix, realTree.vertices) mst = computeMST(fullGraph, realTree.vertices) simulationErrorHandler = SimulationErrorHandler() treeScore = simulationErrorHandler.computeTreeError([mst], realTree) return treeScore
def c_input(keys, c=None, auto_eq=True, return_c=True): if c is None: c = C() for key in keys: c.handle_input(key) if auto_eq: c.handle_input('=') if return_c: return c.c return c
def duplicateGenome(self, simulator): newC = [] for c in self.C: oldCTumor = c.c[1] newC.append(C([2, oldCTumor*2])) newAlleles = [] #Make sure that the allele identifiers are the same across a region with the same chromosome arm. prevArm = simulator.chromosomeArms[0] currentAlleleA = 'A' + str(uuid.uuid4()) currentAlleleB = 'B' + str(uuid.uuid4()) for a in range(0, len(self.A)): newACount = self.A[a].ACount*2 newBCount = self.A[a].BCount*2 #make the new names #Check for each arm if it is the same as the previous. If true, append the same name #if the chromosome arm is different, append a new one if simulator.chromosomeArms[a] != prevArm: currentAlleleA = 'A' + str(uuid.uuid4()) currentAlleleB = 'B' + str(uuid.uuid4()) #the identifiers for the new alleles depends on the ACount. newAlleleObjects = Alleles(newACount, newBCount) newAlleleObjects.alleleIdentifiers += self.A[a].alleleIdentifiers for newAIdentifier in range(0, (self.A[a].ACount*2 - self.A[a].ACount)): newAlleleObjects.alleleIdentifiers.append(currentAlleleA) for newBIdentifier in range(0, (self.A[a].BCount*2 - self.A[a].BCount)): newAlleleObjects.alleleIdentifiers.append(currentAlleleB) newAlleles.append(newAlleleObjects) prevArm = simulator.chromosomeArms[a] #Check if our alleles always match across the chromosomes #we are using this for duplicating a precursor that does not have somatic variants. If the precursor did have somatic variants, we should duplicate these too here! precursor = Subclone() precursor.C = newC precursor.A = newAlleles precursor.somaticVariants = deepcopy(self.somaticVariants) precursor.parent = self precursor.name = str(uuid.uuid4()) self.children.append(precursor) return precursor
def inferBestCMu(self, samples, currentGraph): #import threading import time start_time = time.time() fitness = Fitness() threads = [] #can we run the method for each sample in parallel? This would speed up the process by a lot. THe samples are not dependent on each other! for sampleInd in range( 1, len(samples)): #Skip the first 'dummy' precursor sample self.inferBestCMuPerSample(samples, sampleInd, currentGraph, fitness) #t = threading.Thread(target=self.inferBestCMuPerSample, args=[samples,sampleInd,currentGraph, fitness]) #threads.append(t) #t.start() #for thread in threads: # thread.join() #After we have inferred the best C and mu for each sample, we can update the best C and mu in the samples. for sample in range(0, len(samples)): samples[sample].originalCMu = samples[sample].bestCMu if samples[sample].bestCMu is None: measurementLength = len(samples[0].measurements.measurements) samples[sample].Mu = Mu(0) #assume 100% tumor #Set a default bestCMu in this case, we don't know the solution. print "sample ", sample, " setting CMu to 2" samples[sample].bestCMu = [ CMuCombination(C([2, 2]), Mu(0), self.eventDistances) ] * measurementLength else: if samples[sample].bestCMu[0] is not None: print "setting mu to: ", samples[sample].bestCMu[ 0].mu.mu, " in sample: ", samples[sample].name samples[sample].Mu = samples[sample].bestCMu[0].mu else: #without a successfully inferred C and mu the sample is so complex it is most likely 100% tumor or contains a lot of subclones. print sample, " Assuming 100% tumor" samples[sample].Mu = Mu(0) #assume 100% tumor print("--- %s seconds for all samples of 1 patient ---" % (time.time() - start_time)) return samples
def computeResult(data): ''' data = {Exercise, Solution} aus data werden Exercise und Solution Objekte erstellt erst Exercise Objekt erstellen und dann dem Solution Objekt übergeben (analog zur main) Solution Objekt muss Copiler übergeben werden -> Import language specific compiler file comp = C(solution) comp.processData() r = comp.result return r.createJson() dataObjects.py in Dockerfile einfügen ''' #print("sys.argv[0]: " + sys.argv[0]) #print("os.path.dirname(os.path.abspath(sys.argv[0])): " + os.path.dirname(os.path.abspath(sys.argv[0]))) exercise = dataObjects.Exercise({"Exercise": data["Exercise"]}) solution = dataObjects.Solution({"Solution": data["Solution"]}, exercise) comp = C(solution) comp.processData() return comp.result.createJson()
def __init__(self): self.kmin = settings.general['kmin'] self.kmax = settings.general['kmax'] #Make a dummy bestCMu for the healthy sample self.eventDistances = EventDistances(self.kmin, self.kmax) #Initialize C+mu combinations and store in a matrix, objects do not need to be remade in loop #These are the combinations that we will explore and score for each LAF in the method self.combinationMatrix = np.empty([101, self.kmax], dtype='object') for muIndex in range( 0, 101 ): #we allow a maximum of 0-100, so it is fine to use these settings here. muClass = Mu(muIndex) for k in range(self.kmin, self.kmax + 1): c = C([2, k]) cMuCombination = CMuCombination(c, muClass, self.eventDistances) self.combinationMatrix[muIndex][k - 1] = cMuCombination self.cCombinations = CCombinations( self.kmin, self.kmax ) #re-make this, we use iterators, otherwise the combinations need to be stored in memory.
if __name__ == "__main__": from c import C c = C() c.m()
espaceLettre = point * 3 espaceMot = point * 7 - espaceLettre message = raw_input('Que voulez-vous dire ? ') for x in message: if x.upper() == 'A': A() sleep(espaceLettre) elif x.upper() == 'B': B() sleep(espaceLettre) elif x.upper() == 'C': C() sleep(espaceLettre) elif x.upper() == 'D': D() sleep(espaceLettre) elif x.upper() == 'E': E() sleep(espaceLettre) elif x.upper() == 'F': F() sleep(espaceLettre) elif x.upper() == 'G':
#Obtain the ploidy of the precursor precursorPloidy = int(settings.general['precursorPloidy']) precursorAlleleACount = int(settings.general['precursorAlleleACount']) precursorAlleleBCount = int(settings.general['precursorAlleleBCount']) #Check if the ploidy is correct totalPloidy = precursorAlleleACount + precursorAlleleBCount precursorTumorFrequency = 100 #Check if the ploidy is different from 2 (or allele balance). If true, then the precursor is not a healthy cell and we have 100% tumor if precursorAlleleACount != 1 or precursorAlleleBCount != 1 or precursorPloidy != 2: precursorTumorFrequency = 0 #In this case we have 100% tumor in the precursor. Only if the precursor it is normal it is 0% tumor. #Initialize the 'healthy' sample, this can now also be a precursor healthySample = Sample(None, None) healthySample.C = [C([2, precursorPloidy])] * measurementLength healthySample.A = [Alleles(precursorAlleleACount, precursorAlleleBCount) ] * measurementLength healthySample.Mu = [Mu(precursorTumorFrequency)] #obtain the chromosome, start and end information from the other samples healthySample.measurements = LAF([0.5] * measurementLength, tmpSamples[0].measurements.chromosomes, tmpSamples[0].measurements.starts, tmpSamples[0].measurements.ends) healthySample.somaticVariants = [0] * somVarNum healthySample.somaticVariantsInd = tmpSamples[0].somaticVariantsInd healthySample.setParent(None) healthySample.name = 'Precursor' #do not call it healthy, it may also be a 4N precursor. #Make a dummy bestCMu for the healthy sample eventDistances = targetClone.eventDistances
def __init__(self): B.__init__(self) C.__init__(self) print("D in initiated")
def main(): c = C() c.a() c.b() c.c()