Commit acd7143c authored by Eric CHARPENTIER's avatar Eric CHARPENTIER 🐍
Browse files

added check for annotation images in report

parent f8afb27c
......@@ -216,11 +216,20 @@
{% if deseqres[i.condition1+"__vs__"+i.condition2].counts > 9 %}
<p>GO terms enrichment analysis will find which GO terms are over-represented (or under-represented) for the differentially expressed genes.</p>
<img src="./DESEQ2/results/{{i.condition1}}__vs__{{i.condition2}}/{{i.condition1}}__vs__{{i.condition2}}_dotplotGO.png" style="width:70%"><br/></br>
<a href="./DESEQ2/results/{{i.condition1}}__vs__{{i.condition2}}/{{i.condition1}}__vs__{{i.condition2}}_annotGo.tsv">Download GO annotations enrichment table</a><br/><br/>
{% if deseqres[i.condition1+"__vs__"+i.condition2].countsGo > 0 %}
<img src="./DESEQ2/results/{{i.condition1}}__vs__{{i.condition2}}/{{i.condition1}}__vs__{{i.condition2}}_dotplotGO.png" style="width:70%"><br/></br>
<a href="./DESEQ2/results/{{i.condition1}}__vs__{{i.condition2}}/{{i.condition1}}__vs__{{i.condition2}}_annotGo.tsv">Download GO annotations enrichment table</a><br/><br/>
{% else %}
<p>No Gene Ontology enrichment found for this comparison.</p>
{% endif %}
<p>KEGG terms enrichment analysis will find which KEGG pathways are over-represented (or under-represented) for the differentially expressed genes.</p>
<img src="./DESEQ2/results/{{i.condition1}}__vs__{{i.condition2}}/{{i.condition1}}__vs__{{i.condition2}}_dotplotKEGG.png" style="width:70%"><br/></br>
<a href="./DESEQ2/results/{{i.condition1}}__vs__{{i.condition2}}/{{i.condition1}}__vs__{{i.condition2}}_annotKegg.tsv">Download KEGG pathways enrichment table</a><br/><br/>
{% if deseqres[i.condition1+"__vs__"+i.condition2].countsKegg > 0 %}
<img src="./DESEQ2/results/{{i.condition1}}__vs__{{i.condition2}}/{{i.condition1}}__vs__{{i.condition2}}_dotplotKEGG.png" style="width:70%"><br/></br>
<a href="./DESEQ2/results/{{i.condition1}}__vs__{{i.condition2}}/{{i.condition1}}__vs__{{i.condition2}}_annotKegg.tsv">Download KEGG pathways enrichment table</a><br/><br/>
{% else %}
<p>No KEGG enrichment found for this comparison.</p>
{% endif %}
<br/><br/>
{% else %}
......
......@@ -9,6 +9,13 @@ import time
import re
from jinja2 import Environment, FileSystemLoader
# Functions
def file_len(fname):
with open(fname) as f:
for i, l in enumerate(f):
pass
return i + 1
# Parser
argParser = argparse.ArgumentParser()
argParser.add_argument("-c", "--configfile", required=True, help="Jsonfile's path", dest="configFile")
......@@ -81,14 +88,21 @@ for c in conditionVS:
templateVars["deseqres"][c["condition1"]+"__vs__"+c["condition2"]] = dict()
templateVars["deseqres"][c["condition1"]+"__vs__"+c["condition2"]]["genes"] = list()
# Initialize counter for number of differentially expressed genes
count = 0
countDEG = 0
# Initialize counter for number of GO enrichment hits
countGO = 0
# Initialize counter for number of KEGG enrichment hits
countKEGG = 0
# Opening of deseqRes file
upGenes = os.path.join(config["outdir"],"DESEQ2","results",c["condition1"]+"__vs__"+c["condition2"],c["condition1"]+"__vs__"+c["condition2"]+"_UP_DEG.tsv")
downGenes = os.path.join(config["outdir"],"DESEQ2","results",c["condition1"]+"__vs__"+c["condition2"],c["condition1"]+"__vs__"+c["condition2"]+"_DOWN_DEG.tsv")
annotGoFile =os.path.join(config["outdir"],"DESEQ2","results",c["condition1"]+"__vs__"+c["condition2"],c["condition1"]+"__vs__"+c["condition2"]+"_annotGo.tsv")
annotKeggFile =os.path.join(config["outdir"],"DESEQ2","results",c["condition1"]+"__vs__"+c["condition2"],c["condition1"]+"__vs__"+c["condition2"]+"_annotKegg.tsv")
up = pd.read_csv(upGenes, header=0, sep="\t")
for index, row in up.iterrows():
count +=1
countDEG +=1
g = dict()
ls = row['Name'].strip('\n').split("|")
g["ensg"] = ls[0]
......@@ -103,7 +117,7 @@ for c in conditionVS:
down = pd.read_csv(downGenes, header=0, sep="\t")
for index, row in down.iterrows():
count +=1
countDEG +=1
g = dict()
ls = row['Name'].strip('\n').split("|")
g["ensg"] = ls[0]
......@@ -114,10 +128,12 @@ for c in conditionVS:
g["stat"] = str("%.4f" % float(row['stat']))
g["pvalue"] = str(row['pvalue'])
g["padj"] = str(row['padj'])
templateVars["deseqres"][c["condition1"]+"__vs__"+c["condition2"]]["genes"].append(g)
templateVars["deseqres"][c["condition1"]+"__vs__"+c["condition2"]]["genes"].append(g)
# Insert counts of DEG in a variable in order to print ma-plot, volcano-plot and deseq table in report if necessary
templateVars["deseqres"][c["condition1"]+"__vs__"+c["condition2"]]["counts"] = count
templateVars["deseqres"][c["condition1"]+"__vs__"+c["condition2"]]["counts"] = countDEG
templateVars["deseqres"][c["condition1"]+"__vs__"+c["condition2"]]["countsGo"] = file_len(annotGoFile) - 1
templateVars["deseqres"][c["condition1"]+"__vs__"+c["condition2"]]["countsKegg"] = file_len(annotKeggFile) - 1
#################
# Tools listing #
......@@ -144,4 +160,4 @@ for pack in packages.split("\n"):
template = args.templateFile
output = Environment(loader=FileSystemLoader(os.path.dirname(template))).get_template(os.path.basename(template)).render(templateVars)
with open(args.output, "wb") as f:
f.write(output.encode("utf-8"))
f.write(output.efile_len
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment