Esempio n. 1
0
File: test.py Progetto: chaby/dana
def tryToFusion(fastqSequence, reverseFileName, threshold, log, seqOutput):
    fastqSequence.applyDrasticThreshold(threshold)
    f = open(reverseFileName, "r")
    reverseLineHeader = fastqSequence.getReverseLineHeader()
    logging.debug("Search " + reverseLineHeader)
    
    lastHeaderLineNumber    = 0
    lastSeparatorLineNumber = 0
    parseFastq     = False
    rFastqSequence = None
    lineNumber     = 0
    
    for line in f:
        line = line[:-1]
        lineNumber += 1
        #logging.debug(str(lineNumber) +"\t****   "+line + "\t" + str(line[0] == "@") + "\t" + str(lineNumber == 1))
        
        if line[0] == "@" and (lastSeparatorLineNumber != lineNumber - 1 or lineNumber == 1):
            logging.debug(line + " est un header")
            if parseFastq:
                rFastqSequence.applyDrasticThreshold(threshold)
                
                s = FastqSequence.matchFastqSequence(fastqSequence, rFastqSequence)
                if s != None:
                    seqOutput.write(">" + s.getLineHeader() + "\n")
                    seqOutput.write(s.sequence + "\n")
                    logging.debug(s.getLineHeader() + "\t" + str(s.typeFusion))
                    if s.typeFusion == s.TYPE_FUSION_OK:
                        log.write("Merge " + fastqSequence.getLineHeader() + " with " + rFastqSequence.getLineHeader() + "\n")
                    elif s.typeFusion == s.TYPE_FUSION_NO_MATCH:
                        log.write("Forced merge " + fastqSequence.getLineHeader() + " with " + rFastqSequence.getLineHeader() + "\n")
                    elif s.typeFusion == s.TYPE_FUSION_PARTIAL:
                        log.write("Partial merge " + fastqSequence.getLineHeader() + " with " + rFastqSequence.getLineHeader() + "\n")
                    else:
                        log.write("Can't merge " + fastqSequence.getLineHeader() + " with " + rFastqSequence.getLineHeader() + "\n")
                else:
                    log.write("*Can't merge " + fastqSequence.getLineHeader() + " with " + rFastqSequence.getLineHeader() + "\n")
                parseFastq = False
                
            #logging.debug("-"+line)
            #logging.debug("-"+reverseLineHeader)
            #logging.debug(line + " =?= " + reverseLineHeader + " ? " + str(line == reverseLineHeader))
            if line == reverseLineHeader:
                parseFastq = True
                
            if parseFastq:
                rFastqSequence = FastqSequence.readFasqSequenceHeader(line)
                #logging.debug("Compare to " + rFastqSequence.getLineHeader())
                lastHeaderLineNumber = lineNumber
        elif parseFastq:
            if  lastHeaderLineNumber == lineNumber - 1:
                rFastqSequence.setSequence(line)
            elif line[0] == "+":
                lastSeparatorLineNumber = lineNumber
            elif lastSeparatorLineNumber == lineNumber - 1:
                rFastqSequence.setQuality(line)                
            
    f.close()
Esempio n. 2
0
def cutFusionAndMerge(headerF, dataF, headerR, dataR, wellThresholds, log,
                      outputFile):
    logger.debug("[cutFusionAndMerge] " + headerF + ", " + headerR + ", " +
                 str(wellThresholds))

    forward = 0
    reverse = 1

    dataF = dataF[0:wellThresholds[forward]]
    #a = "ATAACGCTGTTATCCCTGCGGTAACTTGTTCTTTTGATCACTGTAAGTGGATCACACCTTCATTTTTATGATTTAAGAAAAACAATTCTTTTATTTTAGGTTAATATAACCATATAGTAGCGGAGGATTTTCTTTCTCCGGGATTGCCCCAATCAAAGCTTGTTTCAATTTGCCATGCTCTAGGCCTACTATTTCTATTATATTAGTTAGGGCTAATAGTAAATAACAATTAAAATTCAACTACAGCTCG"
    #dataR = DnaUtils.complementAndReverseDnaSequence(dataR[0:wellThresholds[reverse]])
    cdataR = DnaUtils.complementAndReverseDnaSequence(dataR)
    cdataR = cdataR[:wellThresholds[reverse]]
    #cdataR = DnaUtils.complementAndReverseDnaSequence(cdataR)
    #data   = merge(dataF, cdataR)
    # print(dataF)
    #print(DnaUtils.complementAndReverseDnaSequence(cdataR))

    fastqSequenceForward = FastqSequence.createFasqSequenceHeader(headerF)
    fastqSequenceForward.setSequence(dataF, True)
    fastqSequenceForward.quality = None

    fastqSequenceReverse = FastqSequence.createFasqSequenceHeader(headerR)
    fastqSequenceReverse.setSequence(cdataR)
    fastqSequenceReverse.quality = None

    newFastQ = FastqSequence.matchFastqSequence(fastqSequenceForward,
                                                fastqSequenceReverse)

    logging.debug(newFastQ.getLineHeader() + "\t" + str(newFastQ.typeFusion))
    if newFastQ.typeFusion == newFastQ.TYPE_FUSION_OK:
        log.write("Merge " + fastqSequenceForward.getLineHeader() + " with " +
                  fastqSequenceReverse.getLineHeader() + "\n")
    elif newFastQ.typeFusion == newFastQ.TYPE_FUSION_NO_MATCH:
        log.write("Forced merge " + fastqSequenceForward.getLineHeader() +
                  " with " + fastqSequenceReverse.getLineHeader() + "\n")
    elif newFastQ.typeFusion == newFastQ.TYPE_FUSION_PARTIAL:
        log.write("Partial merge " + fastqSequenceForward.getLineHeader() +
                  " with " + fastqSequenceReverse.getLineHeader() + "\n")
    else:
        log.write("Can't merge " + fastqSequenceForward.getLineHeader() +
                  " with " + fastqSequenceReverse.getLineHeader() + "\n")

    #outputFile.write(">" + newFastQ.getLineHeader() + "\n")
    #outputFile.write(newFastQ.sequence + "\n")
    #sys.exit(1)
    return newFastQ
Esempio n. 3
0
def tryToFusion(fastqSequence, reverseFileName, threshold, log):
    fastqSequence
    f = open(reverseFileName, "r")
    reverseLineHeader = fastqSequence.getReverseLineHeader()
    
    lastHeaderLineNumber    = 0
    lastSeparatorLineNumber = 0
    parseFastq     = False
    rFastqSequence = None
    lineNumber     = 0
    
    for line in f:
        line = line[:-1]
        lineNumber += 1
        
        if line[0] == "@" and lastSeparatorLineNumber != lineNumber - 1:
            if parseFastq:
                rFastqSequence.applyDrasticThreshold(threshold)
                s = FastqSequence.matchFastqSequence(fastqSequence, rFastqSequence)
                if s != None:
                    print(s.getLineHeader())
                    print(s.sequence)
                else:
                    log.write("Can't merge " + fastqSequence.getLineHeader() + " with " + rFastqSequence.getLineHeader() + "\n")
                parseFastq = False
                
            if line == reverseLineHeader:
                parseFastq = True
                
            if parseFastq:
                rFastqSequence = FastqSequence.readFasqSequenceHeader(line)
                lastHeaderLineNumber = lineNumber
        elif parseFastq:
            if  lastHeaderLineNumber == lineNumber - 1:
                rFastqSequence.setSequence(line)
            elif line[0] == "+":
                lastSeparatorLineNumber = lineNumber
            elif lastSeparatorLineNumber == lineNumber - 1:
                rFastqSequence.setQuality(line)                
            
    f.close()
Esempio n. 4
0
File: test.py Progetto: chaby/dana
def cutFusionAndMerge(headerF, dataF, headerR, dataR, wellThresholds, log, outputFile):
    logger.debug("[cutFusionAndMerge] " + headerF + ", " + headerR + ", " + str(wellThresholds))
    
    forward  = 0
    reverse  = 1
    
    dataF = dataF[0:wellThresholds[forward]]
    #a = "ATAACGCTGTTATCCCTGCGGTAACTTGTTCTTTTGATCACTGTAAGTGGATCACACCTTCATTTTTATGATTTAAGAAAAACAATTCTTTTATTTTAGGTTAATATAACCATATAGTAGCGGAGGATTTTCTTTCTCCGGGATTGCCCCAATCAAAGCTTGTTTCAATTTGCCATGCTCTAGGCCTACTATTTCTATTATATTAGTTAGGGCTAATAGTAAATAACAATTAAAATTCAACTACAGCTCG"
    #dataR = DnaUtils.complementAndReverseDnaSequence(dataR[0:wellThresholds[reverse]])
    cdataR = DnaUtils.complementAndReverseDnaSequence(dataR)
    cdataR = cdataR[:wellThresholds[reverse]]
    #cdataR = DnaUtils.complementAndReverseDnaSequence(cdataR)
    #data   = merge(dataF, cdataR)
    # print(dataF)
    #print(DnaUtils.complementAndReverseDnaSequence(cdataR))
    
    fastqSequenceForward = FastqSequence.createFasqSequenceHeader(headerF)
    fastqSequenceForward.setSequence(dataF, True)
    fastqSequenceForward.quality = None
    
    fastqSequenceReverse = FastqSequence.createFasqSequenceHeader(headerR)
    fastqSequenceReverse.setSequence(cdataR)
    fastqSequenceReverse.quality = None
    
    newFastQ = FastqSequence.matchFastqSequence(fastqSequenceForward, fastqSequenceReverse)
    
    logging.debug(newFastQ.getLineHeader() + "\t" + str(newFastQ.typeFusion))
    if newFastQ.typeFusion == newFastQ.TYPE_FUSION_OK:
        log.write("Merge " + fastqSequenceForward.getLineHeader() + " with " + fastqSequenceReverse.getLineHeader() + "\n")
    elif newFastQ.typeFusion == newFastQ.TYPE_FUSION_NO_MATCH:
        log.write("Forced merge " + fastqSequenceForward.getLineHeader() + " with " + fastqSequenceReverse.getLineHeader() + "\n")
    elif newFastQ.typeFusion == newFastQ.TYPE_FUSION_PARTIAL:
        log.write("Partial merge " + fastqSequenceForward.getLineHeader() + " with " + fastqSequenceReverse.getLineHeader() + "\n")
    else:
        log.write("Can't merge " + fastqSequenceForward.getLineHeader() + " with " + fastqSequenceReverse.getLineHeader() + "\n")
        
    #outputFile.write(">" + newFastQ.getLineHeader() + "\n")
    #outputFile.write(newFastQ.sequence + "\n")
    #sys.exit(1)
    return newFastQ
Esempio n. 5
0
def tryToFusion(fastqSequence, reverseFileName, threshold, log, seqOutput):
    fastqSequence.applyDrasticThreshold(threshold)
    f = open(reverseFileName, "r")
    reverseLineHeader = fastqSequence.getReverseLineHeader()
    logging.debug("Search " + reverseLineHeader)

    lastHeaderLineNumber = 0
    lastSeparatorLineNumber = 0
    parseFastq = False
    rFastqSequence = None
    lineNumber = 0

    for line in f:
        line = line[:-1]
        lineNumber += 1
        #logging.debug(str(lineNumber) +"\t****   "+line + "\t" + str(line[0] == "@") + "\t" + str(lineNumber == 1))

        if line[0] == "@" and (lastSeparatorLineNumber != lineNumber - 1
                               or lineNumber == 1):
            logging.debug(line + " est un header")
            if parseFastq:
                rFastqSequence.applyDrasticThreshold(threshold)

                s = FastqSequence.matchFastqSequence(fastqSequence,
                                                     rFastqSequence)
                if s != None:
                    seqOutput.write(">" + s.getLineHeader() + "\n")
                    seqOutput.write(s.sequence + "\n")
                    logging.debug(s.getLineHeader() + "\t" + str(s.typeFusion))
                    if s.typeFusion == s.TYPE_FUSION_OK:
                        log.write("Merge " + fastqSequence.getLineHeader() +
                                  " with " + rFastqSequence.getLineHeader() +
                                  "\n")
                    elif s.typeFusion == s.TYPE_FUSION_NO_MATCH:
                        log.write("Forced merge " +
                                  fastqSequence.getLineHeader() + " with " +
                                  rFastqSequence.getLineHeader() + "\n")
                    elif s.typeFusion == s.TYPE_FUSION_PARTIAL:
                        log.write("Partial merge " +
                                  fastqSequence.getLineHeader() + " with " +
                                  rFastqSequence.getLineHeader() + "\n")
                    else:
                        log.write("Can't merge " +
                                  fastqSequence.getLineHeader() + " with " +
                                  rFastqSequence.getLineHeader() + "\n")
                else:
                    log.write("*Can't merge " + fastqSequence.getLineHeader() +
                              " with " + rFastqSequence.getLineHeader() + "\n")
                parseFastq = False

            #logging.debug("-"+line)
            #logging.debug("-"+reverseLineHeader)
            #logging.debug(line + " =?= " + reverseLineHeader + " ? " + str(line == reverseLineHeader))
            if line == reverseLineHeader:
                parseFastq = True

            if parseFastq:
                rFastqSequence = FastqSequence.readFasqSequenceHeader(line)
                #logging.debug("Compare to " + rFastqSequence.getLineHeader())
                lastHeaderLineNumber = lineNumber
        elif parseFastq:
            if lastHeaderLineNumber == lineNumber - 1:
                rFastqSequence.setSequence(line)
            elif line[0] == "+":
                lastSeparatorLineNumber = lineNumber
            elif lastSeparatorLineNumber == lineNumber - 1:
                rFastqSequence.setQuality(line)

    f.close()