Exemple #1
0
def transformReads(G, N, L, folderName, myIndex):

    motherGen, reads, noisyReads = logging.rawDataLoad(folderName + "UnitTest",
                                                       G, N, L, "dn")

    myRead = reads[myIndex]

    fout = open(folderName + "bridgingReads_" + str(myIndex) + ".fasta", 'w')

    fout.write(">Seg1\n")
    for i in range(len(myRead)):
        if myRead[i] == 1:
            fout.write('A')
        elif myRead[i] == 2:
            fout.write('C')
        elif myRead[i] == 3:
            fout.write('G')
        elif myRead[i] == 4:
            fout.write('T')
        #else:
        #    fout.write('A')

        if np.mod(i, 70) == 69:
            fout.write("\n")

    fout.close()

    print "len(motherGen) , len(reads), len(noisyReads)  : ", len(
        motherGen), len(reads), len(noisyReads)
def branchClearingUnitTest(G, N, L,K, liid, threshold, foldername = "",branchingDepth= 20):
    dummyParameters = logging.parameterObj()
    
    dummyParameters.defaultFolder = foldername

    dummyParameters.brachingDepth = branchingDepth    
    
    dummyParameters.K, dummyParameters.liid, dummyParameters.threshold = K, liid, threshold
    dummyParameters.G, dummyParameters.N, dummyParameters.L = G, N, L 
    
    motherGen, reads, noisyReads = logging.rawDataLoad(foldername+"UnitTest",G,N,L, "dn")
    
    returnfmapping= logging.fmappingLoad(foldername+'clusteredGroup.csv')
    G1,startList, fmapping = graphForm.getSeqGraph(returnfmapping,noisyReads, dummyParameters)
    #checkCondensingBasic(G1, startList, "simple")


    returnfmapping, G1= branchClear.clearResidual(returnfmapping,G1,dummyParameters)
    
    G2 = G1

    graphForm.debugSeqGraph(G2)
    
    #G2 = G1 
    checkCondensingBasic2(G2, [G2[0]], "simple")
Exemple #3
0
def branchClearingUnitTest(G,
                           N,
                           L,
                           K,
                           liid,
                           threshold,
                           foldername="",
                           branchingDepth=20):
    dummyParameters = logging.parameterObj()

    dummyParameters.defaultFolder = foldername

    dummyParameters.brachingDepth = branchingDepth

    dummyParameters.K, dummyParameters.liid, dummyParameters.threshold = K, liid, threshold
    dummyParameters.G, dummyParameters.N, dummyParameters.L = G, N, L

    motherGen, reads, noisyReads = logging.rawDataLoad(foldername + "UnitTest",
                                                       G, N, L, "dn")

    returnfmapping = logging.fmappingLoad(foldername + 'clusteredGroup.csv')
    G1, startList, fmapping = graphForm.getSeqGraph(returnfmapping, noisyReads,
                                                    dummyParameters)
    #checkCondensingBasic(G1, startList, "simple")

    returnfmapping, G1 = branchClear.clearResidual(returnfmapping, G1,
                                                   dummyParameters)

    G2 = G1

    graphForm.debugSeqGraph(G2)

    #G2 = G1
    checkCondensingBasic2(G2, [G2[0]], "simple")
def ECUnitTest(Nin,G, Lin, foldername = "", bridgingDepth = 20, msaWidth = 20 ):
    
    dummyParameters = logging.parameterObj()
    dummyParameters.bridgingDepth = bridgingDepth
    dummyParameters.msaWidth = msaWidth
    dummyParameters.N, dummyParameters.G, dummyParameters.L, dummyParameters.p  = Nin, G,Lin, 0.015
    dummyParameters.indel = True
    dummyParameters.defaultFolder = foldername
    dummyParameters.threshold = 5
    dummyParameters.liid = 48
    
    snpRate, typeOfGen, detail = 0.001 ,'m', "500-200-50" 
    G,N,L =  dummyParameters.G, dummyParameters.N, dummyParameters.L,
    motherGen, reads, noisyReads = logging.rawDataLoad(foldername+"UnitTest",G,N,L, "dn")  
  
    f2= logging.fmapfusedLoad(foldername+'clusteredGroup2.csv') 
    G2 = logging.loadGraph(foldername+'basicMapping.csv', foldername+'seqMapping.txt', 'simple')
    checkCondensingBasic(G2, [G2[0]], "simple")

    G3 = bridgeResolve.resolveRepeats(f2,G2,dummyParameters)
    
    checkCondensingBasic(G3, [G3[0]], "MB")

    G4 = alignmentBridge.MSAresolve(f2, G3, noisyReads, snpRate,dummyParameters)
    #G4 = G3

    #checkCondensingBasic(G4, [G4[0]], "MB")
    
    recovSeq = eulerCycle.findEC(G4)
    
    recovGen = readAns.reportRecovSeq(recovSeq, f2, noisyReads,dummyParameters)
    
    numMistakes, success = compare.subAlignCompare(recovGen, motherGen,dummyParameters)

    return numMistakes, success
def transformReads(G,N,L,folderName,myIndex):

    motherGen, reads, noisyReads = logging.rawDataLoad(folderName+"UnitTest",G,N,L, "dn")
    
    myRead = reads[myIndex]
    
    fout= open(folderName + "bridgingReads_"+str(myIndex)+".fasta", 'w')
    
    fout.write(">Seg1\n")
    for i in range(len(myRead)):
        if myRead[i]  ==1 :
            fout.write('A')
        elif myRead[i]  ==2 :
            fout.write('C')
        elif myRead[i]  ==3 :
            fout.write('G')
        elif myRead[i]  ==4 :
            fout.write('T')
        #else:
        #    fout.write('A')
        
        if np.mod(i,70) == 69 :
            fout.write("\n")

    fout.close()
    
    print "len(motherGen) , len(reads), len(noisyReads)  : ",  len(motherGen) , len(reads), len(noisyReads)  
def runAssembler(snpRate, typeOfGen, detail, parameterRobot):
    #N, G, L, p,K,snpRate, typeOfGen, detail = 100, 100, 10000, 0.01,30,0.001, 'r', "1000"

    motherGen, reads, noisyReads = dataGen.generateData(
        typeOfGen, detail, parameterRobot)
    motherGen, reads, noisyReads = logging.rawDataLoad(
        parameterRobot.defaultFolder + "UnitTest", parameterRobot.G,
        parameterRobot.N, parameterRobot.L, "dn")

    f1 = cluster.groupIndelNoisyKmers(noisyReads, parameterRobot)

    G1, startList, f1 = graphForm.getSeqGraph(f1, noisyReads, parameterRobot)
    f2, G2 = branchClear.clearResidual(f1, G1, parameterRobot)

    G3 = bridgeResolve.resolveRepeats(f2, G2, parameterRobot)

    G4 = alignmentBridge.MSAresolve(f2, G3, noisyReads, snpRate,
                                    parameterRobot)
    #G4 = G3
    recovSeq = eulerCycle.findEC(G4)

    recovGen = readAns.reportRecovSeq(recovSeq, f2, noisyReads, parameterRobot)

    numMistakes, success = compare.subAlignCompare(recovGen, motherGen,
                                                   parameterRobot)
    #numMistakes, success = 0 , 0
    return numMistakes, success


# Target of the new code : Fast Assemble and assembly in optimal amount of information
#t0 = time.time()
#N, G, L, p,snpRate, typeOfGen, detail = 1000, 10000,200, 0.015, 0.001 ,'m', "500-300-50"
#runAssembler(N, G, L, p,snpRate, typeOfGen, detail)
#print "Time (sec) :", time.time() - t0
def runAssembler(snpRate, typeOfGen, detail,parameterRobot):
    #N, G, L, p,K,snpRate, typeOfGen, detail = 100, 100, 10000, 0.01,30,0.001, 'r', "1000"

    
    motherGen, reads, noisyReads = dataGen.generateData(typeOfGen, detail,parameterRobot)
    motherGen, reads, noisyReads = logging.rawDataLoad(parameterRobot.defaultFolder+"UnitTest",parameterRobot.G,parameterRobot.N,parameterRobot.L, "dn")

    f1 = cluster.groupIndelNoisyKmers(noisyReads,parameterRobot)
    
    G1,startList, f1 = graphForm.getSeqGraph(f1,noisyReads, parameterRobot)
    f2, G2 = branchClear.clearResidual(f1, G1,parameterRobot)
    
    G3 = bridgeResolve.resolveRepeats(f2, G2,parameterRobot)  

    G4 = alignmentBridge.MSAresolve(f2, G3, noisyReads, snpRate,parameterRobot )
    #G4 = G3 
    recovSeq = eulerCycle.findEC(G4)
    
    recovGen = readAns.reportRecovSeq(recovSeq, f2, noisyReads,parameterRobot)
    
    numMistakes, success = compare.subAlignCompare(recovGen, motherGen,parameterRobot)
    #numMistakes, success = 0 , 0 
    return numMistakes, success

# Target of the new code : Fast Assemble and assembly in optimal amount of information 
#t0 = time.time()
#N, G, L, p,snpRate, typeOfGen, detail = 1000, 10000,200, 0.015, 0.001 ,'m', "500-300-50" 
#runAssembler(N, G, L, p,snpRate, typeOfGen, detail)
#print "Time (sec) :", time.time() - t0
def graphFormUnitTest2(N, G, L, folderName = ""):   
    dummyParameters = logging.parameterObj()
    dummyParameters.defaultFolder = folderName
    returnfmapping= logging.fmappingLoad(dummyParameters.defaultFolder+'clusteredGroup.csv')

    dummyParameters.N, dummyParameters.G, dummyParameters.L, dummyParameters.p, typeOfGen, detail = N, G, L, 0.015, 'm', "500-200-50" 

    motherGen, reads, noisyReads = logging.rawDataLoad(dummyParameters.defaultFolder+"UnitTest",dummyParameters.G,dummyParameters.N,dummyParameters.L, "dn")
    G1,startList,fmapping = graphForm.getSeqGraph(returnfmapping,noisyReads, dummyParameters )
def clusteringTestingOfK(G, N, L, folderName, K, threshold, liid):
    motherGen, reads, noisyReads = logging.rawDataLoad(folderName + "UnitTest",G,N,L,'a')
    dummyParameters = logging.parameterObj()
    dummyParameters.brachingDepth = 20
    dummyParameters.clusterRounds , dummyParameters.fingerPrint,  dummyParameters.clusterRatio = 2, 6, 2
    
    
    dummyParameters.N, dummyParameters.L, dummyParameters.K, dummyParameters.G, dummyParameters.threshold, dummyParameters.liid = N, L, K, G, threshold, liid
     
    cluster.groupNoisyKmers(noisyReads,dummyParameters, 'fast' )
Exemple #10
0
def clusteringTestingOfK(G, N, L, folderName, K, threshold, liid):
    motherGen, reads, noisyReads = logging.rawDataLoad(folderName + "UnitTest",
                                                       G, N, L, 'a')
    dummyParameters = logging.parameterObj()
    dummyParameters.brachingDepth = 20
    dummyParameters.clusterRounds, dummyParameters.fingerPrint, dummyParameters.clusterRatio = 2, 6, 2

    dummyParameters.N, dummyParameters.L, dummyParameters.K, dummyParameters.G, dummyParameters.threshold, dummyParameters.liid = N, L, K, G, threshold, liid

    cluster.groupNoisyKmers(noisyReads, dummyParameters, 'fast')
Exemple #11
0
def graphFormUnitTest2(N, G, L, folderName=""):
    dummyParameters = logging.parameterObj()
    dummyParameters.defaultFolder = folderName
    returnfmapping = logging.fmappingLoad(dummyParameters.defaultFolder +
                                          'clusteredGroup.csv')

    dummyParameters.N, dummyParameters.G, dummyParameters.L, dummyParameters.p, typeOfGen, detail = N, G, L, 0.015, 'm', "500-200-50"

    motherGen, reads, noisyReads = logging.rawDataLoad(
        dummyParameters.defaultFolder + "UnitTest", dummyParameters.G,
        dummyParameters.N, dummyParameters.L, "dn")
    G1, startList, fmapping = graphForm.getSeqGraph(returnfmapping, noisyReads,
                                                    dummyParameters)
def graphFormUnitTest(N, G, L, folderName =""):
    print "dataGenUnitTest"
    dummyParameters = logging.parameterObj()
    dummyParameters.defaultFolder = folderName
    dummyParameters.liid = 40
    dummyParameters.K = 40
    dummyParameters.threshold = 6
    dummyParameters.p = 0.015
    dummyParameters.indel = True


    dummyParameters.N, dummyParameters.G, dummyParameters.L, dummyParameters.p, typeOfGen, detail = N, G, L, 0.015, 'm', "500-200-50" 
    
   # motherGen, reads, noisyReads = dataGen.generateData( typeOfGen,detail,dummyParameters)    
    motherGen, reads, noisyReads = logging.rawDataLoad(dummyParameters.defaultFolder+"UnitTest",dummyParameters.G,dummyParameters.N,dummyParameters.L, "dn")
    
    returnfmapping= cluster.groupIndelNoisyKmers(noisyReads, dummyParameters,  "fast")
Exemple #13
0
def clusterUnitTest2():
    # Unit Test 1 : Generate 30 reads with 10 copies with noise , length being 20

    motherGen, reads, noisyReads = logging.rawDataLoad("clusterReadsUnitTest",
                                                       10, 300, 40, "dn")

    parameterRobot = logging.parameterObj()
    parameterRobot.N = 300
    parameterRobot.L = 40
    parameterRobot.G = 10000
    parameterRobot.liid = 30
    parameterRobot.K = 30
    parameterRobot.threshold = 5
    parameterRobot.p = 0.01

    parameterRobot.indel = True

    cluster.groupIndelNoisyKmers(noisyReads, parameterRobot, "fast")
def MSAResolverEpeatUnitTest(Nin, Lin, foldername = ""):

    f2= logging.fmapfusedLoad('clusteredGroup2.csv') 
    G2 = logging.loadGraph(foldername+'basicMapping.csv', foldername+'seqMapping.txt', 'simple')
    #checkCondensingBasic(G2, [G2[0]], "simple")
    dummyParameters = logging.parameterObj()
    dummyParameters.bridgingDepth = 5
    dummyParameters.msaWidth = 20 
    
    G3 = bridgeResolve.resolveRepeats(f2,G2,dummyParameters)
    
    
    #checkCondensingBasic(G3, [G3[0]], "MB")

    N, G, L, p,snpRate, typeOfGen, detail = Nin,  10000,Lin, 0.015, 0.001 ,'m', "500-300-50" 
    motherGen, reads, noisyReads = logging.rawDataLoad(foldername+"UnitTest",G,N,L,"dn")

    alignmentBridge.MSAresolve(f2, G3, noisyReads, snpRate,dummyParameters)
def clusterUnitTest2():
   # Unit Test 1 : Generate 30 reads with 10 copies with noise , length being 20 
    
    motherGen, reads, noisyReads = logging.rawDataLoad("clusterReadsUnitTest",10,300,40,"dn")
    
    
    parameterRobot = logging.parameterObj()
    parameterRobot.N = 300 
    parameterRobot.L = 40
    parameterRobot.G = 10000
    parameterRobot.liid = 30
    parameterRobot.K = 30
    parameterRobot.threshold = 5
    parameterRobot.p = 0.01
    
    parameterRobot.indel = True

    
    cluster.groupIndelNoisyKmers(noisyReads, parameterRobot,  "fast")
Exemple #16
0
def graphFormUnitTest(N, G, L, folderName=""):
    print "dataGenUnitTest"
    dummyParameters = logging.parameterObj()
    dummyParameters.defaultFolder = folderName
    dummyParameters.liid = 40
    dummyParameters.K = 40
    dummyParameters.threshold = 6
    dummyParameters.p = 0.015
    dummyParameters.indel = True

    dummyParameters.N, dummyParameters.G, dummyParameters.L, dummyParameters.p, typeOfGen, detail = N, G, L, 0.015, 'm', "500-200-50"

    # motherGen, reads, noisyReads = dataGen.generateData( typeOfGen,detail,dummyParameters)
    motherGen, reads, noisyReads = logging.rawDataLoad(
        dummyParameters.defaultFolder + "UnitTest", dummyParameters.G,
        dummyParameters.N, dummyParameters.L, "dn")

    returnfmapping = cluster.groupIndelNoisyKmers(noisyReads, dummyParameters,
                                                  "fast")
def segmentChopAndTestTest(Nin,G, Lin, foldername = "", bridgingDepth = 20, msaWidth = 20):         
    dummyParameters = logging.parameterObj()
    dummyParameters.bridgingDepth = bridgingDepth
    dummyParameters.msaWidth = msaWidth
    dummyParameters.N, dummyParameters.G, dummyParameters.L, dummyParameters.p  = Nin, G,Lin, 0.015
    dummyParameters.indel = True
    dummyParameters.defaultFolder = foldername
    dummyParameters.threshold = 5
    dummyParameters.liid = 48
    
    snpRate, typeOfGen, detail = 0.001 ,'m', "500-200-50" 
    G,N,L =  dummyParameters.G, dummyParameters.N, dummyParameters.L,
    motherGen, reads, noisyReads = logging.rawDataLoad(foldername+"UnitTest",G,N,L, "dn")  
    
    
    #G3, f2 = interactiveNodeRemoval(folderName, "skip")
    G3, f2 = interactiveNodeRemoval(folderName, "desiredOpt")
    
    chopAndAlign(G3, f2 , noisyReads, motherGen, dummyParameters)
Exemple #18
0
def MSAResolverEpeatUnitTest(Nin, Lin, foldername=""):

    f2 = logging.fmapfusedLoad('clusteredGroup2.csv')
    G2 = logging.loadGraph(foldername + 'basicMapping.csv',
                           foldername + 'seqMapping.txt', 'simple')
    #checkCondensingBasic(G2, [G2[0]], "simple")
    dummyParameters = logging.parameterObj()
    dummyParameters.bridgingDepth = 5
    dummyParameters.msaWidth = 20

    G3 = bridgeResolve.resolveRepeats(f2, G2, dummyParameters)

    #checkCondensingBasic(G3, [G3[0]], "MB")

    N, G, L, p, snpRate, typeOfGen, detail = Nin, 10000, Lin, 0.015, 0.001, 'm', "500-300-50"
    motherGen, reads, noisyReads = logging.rawDataLoad(foldername + "UnitTest",
                                                       G, N, L, "dn")

    alignmentBridge.MSAresolve(f2, G3, noisyReads, snpRate, dummyParameters)
Exemple #19
0
def ECUnitTest(Nin, G, Lin, foldername="", bridgingDepth=20, msaWidth=20):

    dummyParameters = logging.parameterObj()
    dummyParameters.bridgingDepth = bridgingDepth
    dummyParameters.msaWidth = msaWidth
    dummyParameters.N, dummyParameters.G, dummyParameters.L, dummyParameters.p = Nin, G, Lin, 0.015
    dummyParameters.indel = True
    dummyParameters.defaultFolder = foldername
    dummyParameters.threshold = 5
    dummyParameters.liid = 48

    snpRate, typeOfGen, detail = 0.001, 'm', "500-200-50"
    G, N, L = dummyParameters.G, dummyParameters.N, dummyParameters.L,
    motherGen, reads, noisyReads = logging.rawDataLoad(foldername + "UnitTest",
                                                       G, N, L, "dn")

    f2 = logging.fmapfusedLoad(foldername + 'clusteredGroup2.csv')
    G2 = logging.loadGraph(foldername + 'basicMapping.csv',
                           foldername + 'seqMapping.txt', 'simple')
    checkCondensingBasic(G2, [G2[0]], "simple")

    G3 = bridgeResolve.resolveRepeats(f2, G2, dummyParameters)

    checkCondensingBasic(G3, [G3[0]], "MB")

    G4 = alignmentBridge.MSAresolve(f2, G3, noisyReads, snpRate,
                                    dummyParameters)
    #G4 = G3

    #checkCondensingBasic(G4, [G4[0]], "MB")

    recovSeq = eulerCycle.findEC(G4)

    recovGen = readAns.reportRecovSeq(recovSeq, f2, noisyReads,
                                      dummyParameters)

    numMistakes, success = compare.subAlignCompare(recovGen, motherGen,
                                                   dummyParameters)

    return numMistakes, success
def testChecking(folderName, N, L, G ):
    #N, L, G =     1345, 1000, 50000
    f2 = open(folderName+"rec.txt", 'r')
    temp2 = f2.read()
    recov = np.zeros(len(temp2), dtype = np.int32)

    j =0 
    while j <len(temp2):
        if temp2[j] != '-':
            recov[j] = int(temp2[j])
            j = j+1 
        else:
            recov[j] = -1 
            j = j+2
    f2.close()
    dummyParameters = logging.parameterObj()
    dummyParameters.defaultFolder = folderName 
    dummyParameters.G = G
    motherGen, reads, noisyReads = logging.rawDataLoad(folderName+"UnitTest",G,N,L, 'd')
    
    print len(recov) , len(motherGen)
    numberMistakes, success = compare.subAlignCompare(recov, motherGen,dummyParameters)
def dataGenUnitTest2():
    print "dataGenUnitTest2"
    dummyParameters = logging.parameterObj()
    dummyParameters.N, dummyParameters.G, dummyParameters.L, dummyParameters.p, typeOfGen, detail = 100, 10000,100, 0.01, 't', "500"    
    G,N,L = dummyParameters.G, dummyParameters.N, dummyParameters.L
    
    motherGen, reads, noisyReads = logging.rawDataLoad("UnitTest",G,N,L, 'd')
    
    print reads 
    print noisyReads
    
    baseList = [] 
    
    
    for indexN in range(N):
        for indexL in range(L):
            if reads[indexN][indexL] == noisyReads[indexN][indexL]:
                baseList.append(0)
            else:
                baseList.append(1)
                
    print "Error Probability", np.mean(baseList)
    print "numberOfBasesGet ", len(baseList)
Exemple #22
0
def dataGenUnitTest2():
    print "dataGenUnitTest2"
    dummyParameters = logging.parameterObj()
    dummyParameters.N, dummyParameters.G, dummyParameters.L, dummyParameters.p, typeOfGen, detail = 100, 10000, 100, 0.01, 't', "500"
    G, N, L = dummyParameters.G, dummyParameters.N, dummyParameters.L

    motherGen, reads, noisyReads = logging.rawDataLoad("UnitTest", G, N, L,
                                                       'd')

    print reads
    print noisyReads

    baseList = []

    for indexN in range(N):
        for indexL in range(L):
            if reads[indexN][indexL] == noisyReads[indexN][indexL]:
                baseList.append(0)
            else:
                baseList.append(1)

    print "Error Probability", np.mean(baseList)
    print "numberOfBasesGet ", len(baseList)
Exemple #23
0
def segmentChopAndTestTest(Nin,
                           G,
                           Lin,
                           foldername="",
                           bridgingDepth=20,
                           msaWidth=20):
    dummyParameters = logging.parameterObj()
    dummyParameters.bridgingDepth = bridgingDepth
    dummyParameters.msaWidth = msaWidth
    dummyParameters.N, dummyParameters.G, dummyParameters.L, dummyParameters.p = Nin, G, Lin, 0.015
    dummyParameters.indel = True
    dummyParameters.defaultFolder = foldername
    dummyParameters.threshold = 5
    dummyParameters.liid = 48

    snpRate, typeOfGen, detail = 0.001, 'm', "500-200-50"
    G, N, L = dummyParameters.G, dummyParameters.N, dummyParameters.L,
    motherGen, reads, noisyReads = logging.rawDataLoad(foldername + "UnitTest",
                                                       G, N, L, "dn")

    #G3, f2 = interactiveNodeRemoval(folderName, "skip")
    G3, f2 = interactiveNodeRemoval(folderName, "desiredOpt")

    chopAndAlign(G3, f2, noisyReads, motherGen, dummyParameters)
Exemple #24
0
def testChecking(folderName, N, L, G):
    #N, L, G =     1345, 1000, 50000
    f2 = open(folderName + "rec.txt", 'r')
    temp2 = f2.read()
    recov = np.zeros(len(temp2), dtype=np.int32)

    j = 0
    while j < len(temp2):
        if temp2[j] != '-':
            recov[j] = int(temp2[j])
            j = j + 1
        else:
            recov[j] = -1
            j = j + 2
    f2.close()
    dummyParameters = logging.parameterObj()
    dummyParameters.defaultFolder = folderName
    dummyParameters.G = G
    motherGen, reads, noisyReads = logging.rawDataLoad(folderName + "UnitTest",
                                                       G, N, L, 'd')

    print len(recov), len(motherGen)
    numberMistakes, success = compare.subAlignCompare(recov, motherGen,
                                                      dummyParameters)