def writeTraitPage(filename, title, desc, commonGenes, pfilter_cutoff): traitpage = htmltools.createPage(title, scripts={'sorttable.js':'javascript'}) htmltools.pageDescription(traitpage, desc) traitChi = computeTraitStatistics(commonGenes, pfilter_cutoff) significance_pairs = [ (i, trait, traitChi[trait][5]) for i, trait in enumerate(traitChi.keys()) ] significance_levels = [ pval for (i, trait, pval) in significance_pairs ] FDR = computePermutationTest(traitChi, commonGenes, significance_levels, __ITERATIONS) FDR_map = dict( [ ( trait, FDR[i] ) for (i, trait, pval) in significance_pairs ] ) traitTable = [] for trait in traitChi: (cnt, oddsratio, kappa, numgenes, fisher_exact, fisher_p, genes) = traitChi[trait] fdr_value = FDR_map[trait] translate = trait.replace(" ","_").replace("/", " or ").replace("\\", " or ") if len(trait) > 38: trait = trait[:35] + "..." alink = "<a href=\"traitlists/%s.html\">%s</a>" % (translate, trait) entry = [alink, cnt, numgenes, "%.7f" % (fisher_exact), "%.7f" % (fisher_p), "%.1f" % (oddsratio), "%.4f" % (kappa), fdr_value] traitTable.append(entry) traitTable = sorted(traitTable, key=lambda item: -item[1]) htmltools.createTable( traitpage, traitTable, ["Disease/Trait", "# RE Genes", "# Trait Genes", "fisher exact", "p-value", "odds ratio", "kappa", "FDR"], "traitlisthead", None, ["traitcol", "recol", "genecol", "fishercol","pcol", "oddscol", "kappacol","bencol"], "sortable", None) htmltools.endPage(traitpage) htmltools.savePage(traitpage, filename)
def writeGenePage(output_dir, filename, title, desc, total, geneTable): genepage = htmltools.createPage(title) htmltools.pageDescription(genepage, desc) newTable=[] for row in geneTable: drugcount = 0 if row[0] in drugDB.__drugDict: drugcount = len(drugDB.__drugDict[row[0]]) if os.path.exists(os.sep.join([output_dir,"genelists",row[0]+".html"])): newTable.append(["<a href=\"genelists/%s.html\">%s</a>" % (row[0], geneDB.__original_names[row[0]]), row[1], drugcount]) else: newTable.append([geneDB.__original_names[row[0]], row[1], drugcount]) htmltools.createTable(genepage, newTable, ["Gene","#Associated Traits", "#Targeted Drugs"], "genelisthead", None, ["genecol","traitcol", "drugcol"],"genetable",None) htmltools.endPage(genepage) htmltools.savePage(genepage, filename)
def createTraitListingsHTML(traitListDir): traitSet = set(gwasDB.__studyByTrait.keys()) for trait in traitSet: if trait not in __traitMetaAnalysis: continue traitMetadata = __traitMetaAnalysis[trait] RE_proteins = traitMetadata['RE'] drug_proteins = traitMetadata['drugbank'] other_proteins = traitMetadata['other'] chi_RE = traitMetadata['RE_chi'] chi_Drugbank = traitMetadata['drugbank_chi'] traitListFilename = os.sep.join([traitListDir, trait.replace(" ","_").replace("/", " or ").replace("\\", " or ") + ".html"]) traitpage = htmltools.createPage("Trait Summary: " + trait, css_file='../genereport.css') htmltools.pageDescription(traitpage, "Gene list overlap summary for trait: %s" % (trait)) # two of these htmltools.createContingencyTable(traitpage, "Overlap with rapidly evolving genes:", "RE", "trait", chi_RE[0], chi_RE[1], chi_RE[2], chi_RE[3], chi_RE[4], chi_RE[5], chi_RE[6], chi_RE[7] ) htmltools.createContingencyTable(traitpage, "Overlap with drugbank genes:", "Drugbank", "trait", chi_Drugbank[0], chi_Drugbank[1], chi_Drugbank[2], chi_Drugbank[3], chi_Drugbank[4], chi_Drugbank[5], chi_Drugbank[6], chi_Drugbank[7]) chi_drugs = traitMetadata['drugchi'] htmltools.createContingencyTable(traitpage, "Drug contingency for targeting disease vs targeting rapidly evolving proteins:", "Targets Disease Genes", "Targets RE Genes", chi_drugs[0], chi_drugs[1], chi_drugs[2], chi_drugs[3], chi_drugs[4], chi_drugs[5], chi_drugs[6], chi_drugs[7]) traitpage.table.open(class_="invisible") traitpage.tr.open() traitpage.td.open() traitpage.div("Gene Lists:", class_="header") traitpage.div("Trait genes indicated as rapidly evolving: ", class_="description") createGeneListTable(traitpage, RE_proteins) traitpage.div("Trait genes associated with Drugbank targets: ", class_="description") createGeneListTable(traitpage, drug_proteins) traitpage.div("Other trait genes: ", class_="description") createGeneListTable(traitpage, other_proteins) traitpage.td.close() traitpage.td.open() traitpage.div("Drug Lists:", class_="header") druglistlen = len(__traitMetaAnalysis[trait]['RE_drugs']) traitpage.div("%d drugs targeting associated rapidly evolving proteins" % (druglistlen), class_="description") traitpage.div.open(class_="druglist") traitpage.ul.open() for drug in __traitMetaAnalysis[trait]['RE_drugs']: link = "http://www.drugbank.ca/drugs/%s" % (drug) if drug not in drugDB.__drugs: traitpage.li(oneliner.a(drug, href=link)) else: traitpage.li(oneliner.a(drugDB.__drugs[drug]['name'], href=link)) traitpage.ul.close() traitpage.div.close() druglistlen = len(__traitMetaAnalysis[trait]['other_drugs']) traitpage.div("%d Drugs targeting other proteins" % (druglistlen), class_="description") traitpage.div.open(class_="druglist") traitpage.ul.open() for drug in __traitMetaAnalysis[trait]['other_drugs']: link = "http://www.drugbank.ca/drugs/%s" % (drug) if drug not in drugDB.__drugs: traitpage.li(oneliner.a(drug, href=link)) else: traitpage.li(oneliner.a(drugDB.__drugs[drug]['name'], href=link)) traitpage.ul.close() traitpage.div.close() traitpage.td.close() traitpage.tr.close() traitpage.table.close() htmltools.savePage(traitpage, traitListFilename)