def test_getKmerREFromPSSM(self): predictedDremeFile = "/projects/bhandare/workspace/PySG/src/resources/dreme.txt" seq = "CTGTCCCTTTTCGGGTTTTTTTTTTCCGAGCGGCCTCGGTGGGTGAAATGAACGACACTCATGCGAGCGACACTAGGGCGCCGTTCGTTCTGTGCACCCA" pssmList = parseDreme.getPSSMListFromDremeFile(predictedDremeFile); kmerREString = compareKmerCommon.getKmerFromPSSM(pssmList, seq) self.assertEqual(kmerREString, '(TCGGGT|TTTTTT)')
def computeSequenceBasedDREMEResults(dremeFile, realCsvFile, posSeqFile, negSeqFile): totalPosTP = totalPosFP = totalPosFN = totalPosTN = 0; totalNegTP = totalNegFP = totalNegFN = totalNegTN = 0; posSeqDict = SeqGenUtils.fasta_read(posSeqFile); negSeqDict = SeqGenUtils.fasta_read(negSeqFile); realKmerDict = parseRealKmers.GetRealKmerDict(realCsvFile); pssmList = parseDreme.getPSSMListFromDremeFile(dremeFile) numPosTP, numPosFP, numPosFN, numPosTN = compareRealAndPredicted(realKmerDict, posSeqDict, pssmList, positive=True) numNegTP, numNegFP, numNegFN, numNegTN = compareRealAndPredicted(realKmerDict, negSeqDict, pssmList, False) print "Positive: TP: ", numPosTP, ", FP: ", numPosFP, ", FN: ", numPosFN, ", TN: ", numPosTN print "Negative: TP: ", numNegTP, ", FP: ", numNegFP, ", FN: ", numNegFN, ", TN: ", numNegTN totalPos = len(posSeqDict) totalNeg = len(negSeqDict) sensitivity, ppv = compareKmers.GetSensitivityAndPPV((numPosTP + numNegTP) , (numPosFP + numNegFP), (numPosFN + numNegFN)) accuracy = compareKmers.GetAccuracy( (numPosTP + numNegTP), (numPosTN + numNegTN), (totalPos + totalNeg) ) specificity = compareKmers.GetSpecificity( (numPosFP + numNegFP), totalNeg); print "Senitivity: ", sensitivity, ", PPV: ", ppv, ", Accuracy: ", accuracy, ", Specificity: ", specificity; return sensitivity, ppv;
def GetDremePSSM(predictedDremeFile): pssmList = parseDreme.getPSSMListFromDremeFile(predictedDremeFile); return pssmList;
#print "Motif:", motif.source #print "Max Motif Score:", motif.maxscore #print "Motif Summary:", motif.summary() #motif.printlogo(2.3,10) return motif #end Make_PWM_Motif ########################################################################################## def Make_Text_Motif(textMotif): return MotifTools.Motif_from_text(textMotif) if __name__ == "__main__": dremeFile = sys.argv[1] pssmList = parseDreme.getPSSMListFromDremeFile(dremeFile); for pssmLines in pssmList: Read_Dreme_PSSM(pssmLines); if __name__ == "__main__": import sys pwmFile = sys.argv[1] type = sys.argv[2] if type == "pwm": motif = Make_PWM_Motif(pwmFile) elif type == "pfm": motif = Make_PFM_Motif(pwmFile) print motif;