當前位置: 首頁>>代碼示例>>Python>>正文


Python Helper.countOccurrences方法代碼示例

本文整理匯總了Python中Helper.Helper.countOccurrences方法的典型用法代碼示例。如果您正苦於以下問題:Python Helper.countOccurrences方法的具體用法?Python Helper.countOccurrences怎麽用?Python Helper.countOccurrences使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Helper.Helper的用法示例。


在下文中一共展示了Helper.countOccurrences方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: createDiagramms

# 需要導入模塊: from Helper import Helper [as 別名]
# 或者: from Helper.Helper import countOccurrences [as 別名]
def createDiagramms(output, geneNumber=20,logFile=None,textField=0):
        '''
        writes all the diagrams wich are then shown in the resultTab
        All the values are stored in an instance of the Class Stats
        
        :param output: output variable of Params.output
        '''
        Helper.info("Creating Diagrams for %s" % output, logFile, textField)
        
        stats = Stats(output)
        
        stats.output = output
        stats.outdir = output[0:output.rfind("/")+1]
        stats.sampleName=output[output.rfind("/")+1:]
        
        if not os.path.exists(stats.outdir+"html/"):
            os.makedirs(stats.outdir+"html/")
        
        #print outdir, sampleName
        #################################################
        ####               Basecount Plot            ####
        #################################################
        counts1=Helper.getMMBaseCounts(output+".alu.vcf")
        counts2=Helper.getMMBaseCounts(output+".noBlat.vcf") #use the var file after all the filters have been applied for nonAlu regions
        
        
        stats.totalAluNumber = counts1["A->G"] + counts1["T->C"]
        stats.totalNonAluNumber = counts2["A->G"] + counts2["T->C"]
        stats.totalNumber = stats.totalAluNumber + stats.totalNonAluNumber
        
        
        #write the baseCounts to a file to open with Excel later
        stats.baseCountHTMLTable="<table><tr><th>Missmatch Type</th><th>Alu</th><th>Non Alu</th></tr>"
        file=open(stats.outdir+"html/"+stats.sampleName+"_baseCounts.txt","w")
        file.write("\t".join(["MM","alu","nonAlu"])+"\n")
        for keyAlu,keyNonAlu in zip(counts1.keys(),counts2.keys()):
            file.write("\t".join([str(keyAlu),str(counts1[keyAlu]),str(counts2[keyAlu])])+"\n")
            stats.baseCountHTMLTable+="<tr><td>%s</td><td>%s</td><td>%s</td></tr>"%(keyAlu,str(counts1[keyAlu]),str(counts2[keyAlu]))
        file.close()
        stats.baseCountHTMLTable+="</table>"
        fileName=stats.outdir+"html/"+stats.sampleName+"_baseCounts.png"
        
        valueMatrix=[counts1.values(),counts2.values()]
        Helper.createBarplot(valueMatrix, fileName, counts1.keys(), ("Alu","non-Alu"),width=0.4,title="Variants per Base", barText=False, yText="Number",)
        
    
        #################################################
        ####       Editing per Position Plot         ####
        #################################################
        fileName=stats.outdir+"html/"+stats.sampleName+"_EditingPositions.png"
        fileNamePercentage=stats.outdir+"html/"+stats.sampleName+"_EditingPositions(Percentage).png"
        counts1=Helper.countOccurrences(output+".editingSites.alu.gvf", 2, logFile, textField)
        counts2=Helper.countOccurrences(output+".editingSites.nonAlu.gvf", 2, logFile, textField) 
        
        file=open(stats.outdir+"html/"+stats.sampleName+"_editingSites.txt","w")
        file.write("\t".join(["Position","alu","nonAlu"])+"\n")
        
        for key in counts1.keys():
            if key in counts2.keys():
                file.write("\t".join([str(key),str(counts1[key]),str(counts2[key])])+"\n")
            else:
                file.write("\t".join([str(key), str(counts1[key]), "--"]) + "\n")
        for key in counts2.keys():
            if key not in counts1.keys():
                file.write("\t".join([str(key), "--", str(counts2[key])]) + "\n")
        file.close()
        
        
        #set values to 0 if they dont exist in the opposite file
        orderList = ["3'UTR","5'UTR","coding-exon","noncoding-exon","intron","intergenic"]
        aluPositions,nonAluPositions = [],[]
        for key in orderList:
            aluPositions.append(counts1[key]) if key in counts1.keys() else aluPositions.append(0.000000001)
            nonAluPositions.append(counts2[key]) if key in counts2.keys() else nonAluPositions.append(0.00000001)
            """if key in counts1.keys():
                aluPositions.append(counts1[key])
            else:
                aluPositions.append(0)
        for key in orderList:
            nonAluPositions.append(counts2[key]) 
            """
        sumAlu,sumNonAlu = sum(aluPositions),sum(nonAluPositions)
        #aluPositions=[counts1["3'UTR"],counts1["5'UTR"],counts1["coding-exon"],counts1["noncoding-exon"],counts1["intron"],counts1["intergenic"]]
        #nonAluPositions=[counts2["3'UTR"],counts2["5'UTR"],counts2["coding-exon"],counts2["noncoding-exon"],counts2["intron"],counts2["intergenic"]]
        barNames=["3'UTR","5'UTR","coding-exon","noncoding-exon","intron","intergenic"]
        valueMatrix=[aluPositions,nonAluPositions]
        
        Helper.createBarplot(valueMatrix, fileName, barNames, ("Alu","non-Alu"),width=0.4,title="Editing Sites per Position", barText=False, yText="Total Counts")
        
        valueMatrixPercentage=[Helper.getPercentage(aluPositions),Helper.getPercentage(nonAluPositions)]
        Helper.createBarplot(valueMatrixPercentage, fileNamePercentage, barNames, ("Alu","non-Alu"),width=0.4,title="Editing Sites per Position",yLim=100,yText="Precentage")
        
        #make String for the HTML Table and write to a table for Ecxel
        file=open(stats.outdir+"html/"+stats.sampleName+"_editingSites.txt","w")
        file.write("\t".join(["Position","alu","nonAlu"])+"\n")
        stats.editingPositionHTMLTable="<table><tr><th>Editing Position</th><th>Total Alu</th><th>Alu Percentage</th><th>Total Non Alu</th><th>Non Alu Percentage</th></tr>"
        for key in orderList:
            alu = counts1[key] if key in counts1.keys() else 0
            nonAlu = counts2[key] if key in counts2.keys() else 0
            aluNumber=str(counts1[key]) if key in counts1.keys() else "0"
#.........這裏部分代碼省略.........
開發者ID:djhn75,項目名稱:RNAEditor,代碼行數:103,代碼來源:createDiagrams.py


注:本文中的Helper.Helper.countOccurrences方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。