Commit 6b099b3c authored by Eric CHARPENTIER's avatar Eric CHARPENTIER 🐍
Browse files

Merge branch 'splitreports' into 'master'

Split reports

See merge request !33
parents c2de6be7 dded833a
......@@ -8,14 +8,24 @@ rule copyConfig:
cp {input} {output}
"""
rule buildReport:
rule renameMainReport:
input:
report = MAINDIR+"/{project}/report-" + DEFAULT_REPORT_PART + ".html"
output:
report = MAINDIR+"/{project}/report.html"
shell:
"""
mv {input.report} {output.report}
"""
rule buildReportPart:
input:
unpack(getAllFilesForReport)
output:
report = MAINDIR+"/{project}/report.html",
report = MAINDIR+"/{project}/report-{multipart}.html",
shell:
"""
python {wfbasedir}/SCRIPTS/make_html.py -c {config[conf]} -t {input.index} -p {wildcards.project} -o {output.report}
python {wfbasedir}/SCRIPTS/make_html.py -c {config[conf]} -t {input.index} -p {wildcards.project} -o {output.report} -m {wildcards.multipart}
"""
rule copyTemplateFolder:
......
......@@ -50,6 +50,7 @@ argParser.add_argument("-c", "--configfile", required=True, help="Jsonfile's pat
argParser.add_argument("-t", "--templateFile", required=True, help="HTML Template's path", dest="templateFile")
argParser.add_argument("-p", "--projectName", required=True, help="Name of the project used to select samples in config file", dest="projectName")
argParser.add_argument("-o", "--output", required=True, help="Path of the output file", dest="output")
argParser.add_argument("-m", "--multipart", required=True, default="main", help="Part of the multipart report", dest="multipart")
def getGenomeForProject(project):
for s in config["samples"]:
......@@ -186,7 +187,7 @@ corrFile = os.path.join(sys.path[0],"DE","corresIDorg.txt")
# Selection of versus conditions
conditionVS = list()
if(project in config["comparisons"]):
conditionVS.extend(config["comparisons"][project]["comps"])
conditionVS.extend([c for c in config["comparisons"][project]["comps"] if c.get("multipart", "main") == args.multipart])
templateVars["conditionVS"] = conditionVS
templateVars["deseqres"] = dict()
......
......@@ -179,10 +179,23 @@ if (args.comparisons is not None):
d["comparisons"][project]["performComps"] = None
d["comparisons"][project]["comps"] = list()
for cond1,cond2 in csv.reader(args.comparisons, delimiter='\t'):
if(cond1!=cond2):
for row in csv.reader(args.comparisons, delimiter='\t'):
multipart = None
if len(row)==2:
project_comp = None
cond1, cond2 = row
else:
project_comp, cond1, cond2 = row
v = project_comp.rsplit("::", 1)
project_comp = v[0]
multipart = v[1] if len(v) > 1 else None
if((project_comp or project_comp == project) and cond1!=cond2):
if(d["comparisons"][project]["performComps"]!=False):
d["comparisons"][project]["comps"].append(OrderedDict([("condition1",cond1),("condition2",cond2)]))
if multipart:
d["comparisons"][project]["comps"].append(OrderedDict([("condition1",cond1),("condition2",cond2),("multipart",multipart)]))
else:
d["comparisons"][project]["comps"].append(OrderedDict([("condition1",cond1),("condition2",cond2)]))
d["comparisons"][project]["performComps"] = True
else:
eprint("ERROR make_multiplates_config.py: ","Invalid comparisons file. Both comparisons and first part secondary analysis defined.\nPlease choose if you want to perform comparisons (different conditions specified) or if you only want to perform first part of secondary analysis (identical conditions specified)")
......
......@@ -177,6 +177,9 @@ for sample in d["samples"]:
d["comparisons"] = dict()
if (args.conditions is not None):
for project,cond1,cond2 in csv.reader(args.conditions, delimiter='\t'):
v = project.rsplit("::", 1)
project = v[0]
multipart = v[1] if len(v) > 1 else None
if(not project in d["comparisons"]):
d["comparisons"][project] = OrderedDict()
d["comparisons"][project]["species"] = getGenomeForProject(project)
......@@ -191,7 +194,10 @@ if (args.conditions is not None):
if(cond1!=cond2):
if(d["comparisons"][project]["performComps"]!=False):
d["comparisons"][project]["comps"].append(OrderedDict([("condition1",cond1),("condition2",cond2)]))
if multipart:
d["comparisons"][project]["comps"].append(OrderedDict([("condition1",cond1),("condition2",cond2),("multipart",multipart)]))
else:
d["comparisons"][project]["comps"].append(OrderedDict([("condition1",cond1),("condition2",cond2)]))
d["comparisons"][project]["performComps"] = True
else:
eprint("ERROR make_srp_config.py: ","Invalid condition file. In project: \""+project+"\" both comparisons and first part secondary analysis defined.\nPlease choose if you want to perform comparisons (different conditions specified) or if you only want to perform first part of secondary analysis (identical conditions specified)")
......
......@@ -15,6 +15,7 @@ SECONDARY_ANALYSIS_PROJECTS = {c for c in config["comparisons"] if config["compa
NO_COMPARISONS_PROJECTS = {c for c in config["comparisons"] if not config["comparisons"][c]["performComps"]}
DATE = str(datetime.date.today())
TIME = str(datetime.datetime.now().strftime("%H:%M:%S"))
DEFAULT_REPORT_PART="main"
# final file outputs suffixes for primary analysis
finalSuffixes = ["log.dat","refseq.total.dat","refseq.umi.dat","spike.total.dat","spike.umi.dat","unknown_list","well_summary.dat"]
......@@ -77,11 +78,12 @@ def getAllFilesForReport(wildcards):
files["deseqTables"] = list()
files["annotation"] = list()
for comp in config["comparisons"][wildcards.project]["comps"]:
files["deseqTables"].append(os.path.join(MAINDIR,wildcards.project,config["de_folder"],comp["condition1"]+"__vs__"+comp["condition2"],"DEseqResFiltered.tsv"))
files["annotation"].append(os.path.join(MAINDIR,wildcards.project,config["de_folder"],comp["condition1"]+"__vs__"+comp["condition2"],"gseGo.txt"))
files["annotation"].append(os.path.join(MAINDIR,wildcards.project,config["de_folder"],comp["condition1"]+"__vs__"+comp["condition2"],"gseKegg.txt"))
files["annotation"].append(os.path.join(MAINDIR,wildcards.project,config["de_folder"],comp["condition1"]+"__vs__"+comp["condition2"],"stringFunctionalEnrichment.tsv"))
files["annotation"].append(os.path.join(MAINDIR,wildcards.project,config["de_folder"],comp["condition1"]+"__vs__"+comp["condition2"],"stringDB-genes.txt"))
if comp.get("multipart", DEFAULT_REPORT_PART) == wildcards.multipart:
files["deseqTables"].append(os.path.join(MAINDIR,wildcards.project,config["de_folder"],comp["condition1"]+"__vs__"+comp["condition2"],"DEseqResFiltered.tsv"))
files["annotation"].append(os.path.join(MAINDIR,wildcards.project,config["de_folder"],comp["condition1"]+"__vs__"+comp["condition2"],"gseGo.txt"))
files["annotation"].append(os.path.join(MAINDIR,wildcards.project,config["de_folder"],comp["condition1"]+"__vs__"+comp["condition2"],"gseKegg.txt"))
files["annotation"].append(os.path.join(MAINDIR,wildcards.project,config["de_folder"],comp["condition1"]+"__vs__"+comp["condition2"],"stringFunctionalEnrichment.tsv"))
files["annotation"].append(os.path.join(MAINDIR,wildcards.project,config["de_folder"],comp["condition1"]+"__vs__"+comp["condition2"],"stringDB-genes.txt"))
files["index"] = os.path.join(wfbasedir,"TEMPLATE","index_SA.html")
return files
......@@ -97,7 +99,17 @@ def getTargetFiles():
for s in config["samples"]:
if(s["project"]==p):
targets.append(os.path.join(MAINDIR,p,config["align_folder"],s["name"]+".bai"))
targets.append(os.path.join(MAINDIR,p,"report.html"))
multiparts = set()
for c in config["comparisons"]:
if (p in config["comparisons"]) and config["comparisons"][p]["performComps"]:
for comps in config["comparisons"][p]["comps"]:
multiparts.add(comps.get("multipart", DEFAULT_REPORT_PART))
if multiparts:
targets.extend([os.path.join(MAINDIR, p, "report-{}.html".format(mp)) if mp != DEFAULT_REPORT_PART else os.path.join(MAINDIR, p, "report.html") for mp in multiparts])
else:
targets.append(os.path.join(MAINDIR, p, "report.html"))
targets.append(os.path.join(MAINDIR,p,"INPUT_FILES","samplesheet_used.tsv"))
# Targets for projects with secondary analysis
......
......@@ -10,6 +10,7 @@ wfbasedir = workflow.basedir
MAINDIR = config["maindir"]
DATE = str(datetime.date.today())
TIME = str(datetime.datetime.now().strftime("%H:%M:%S"))
DEFAULT_REPORT_PART="main"
# final file outputs suffixes for primary analysis
finalSuffixes = ["log.dat","refseq.total.dat","refseq.umi.dat","spike.total.dat","spike.umi.dat","well_summary.dat"]
......@@ -53,10 +54,11 @@ def getAllFilesForReport(wildcards):
files["deseqTables"] = list()
files["annotation"] = list()
for comp in config["comparisons"][config["analysis_name"]]["comps"]:
files["deseqTables"].append(os.path.join(MAINDIR,config["analysis_name"],config["de_folder"],comp["condition1"]+"__vs__"+comp["condition2"],"DEseqResFiltered.tsv"))
files["annotation"].append(os.path.join(MAINDIR,config["analysis_name"],config["de_folder"],comp["condition1"]+"__vs__"+comp["condition2"],"gseGo.txt"))
files["annotation"].append(os.path.join(MAINDIR,config["analysis_name"],config["de_folder"],comp["condition1"]+"__vs__"+comp["condition2"],"gseKegg.txt"))
files["annotation"].append(os.path.join(MAINDIR,config["analysis_name"],config["de_folder"],comp["condition1"]+"__vs__"+comp["condition2"],"stringFunctionalEnrichment.tsv"))
if comp.get("multipart", DEFAULT_REPORT_PART) == wildcards.multipart:
files["deseqTables"].append(os.path.join(MAINDIR,config["analysis_name"],config["de_folder"],comp["condition1"]+"__vs__"+comp["condition2"],"DEseqResFiltered.tsv"))
files["annotation"].append(os.path.join(MAINDIR,config["analysis_name"],config["de_folder"],comp["condition1"]+"__vs__"+comp["condition2"],"gseGo.txt"))
files["annotation"].append(os.path.join(MAINDIR,config["analysis_name"],config["de_folder"],comp["condition1"]+"__vs__"+comp["condition2"],"gseKegg.txt"))
files["annotation"].append(os.path.join(MAINDIR,config["analysis_name"],config["de_folder"],comp["condition1"]+"__vs__"+comp["condition2"],"stringFunctionalEnrichment.tsv"))
files["index"] = os.path.join(wfbasedir,"TEMPLATE","index_SA.html")
return files
......@@ -69,9 +71,16 @@ def getTargetFiles():
targets.append(MAINDIR+"/"+config["analysis_name"]+"/"+config["multiqc_folder"]+"/multiqc_report.html")
targets.extend(expand(os.path.join(MAINDIR,config["analysis_name"],config["expression_folder"],config["analysis_name"]+".{exp}.well_summary.pdf"),exp=["unq","all"]))
targets.append(MAINDIR+"/config_used_in_analysis.json")
multiparts = set()
if(config["analysis_name"] in config["comparisons"]):
targets.append(MAINDIR+"/"+config["analysis_name"]+"/"+config["de_folder"]+"/exprDatUPM.tsv")
targets.append(MAINDIR+"/"+config["analysis_name"]+"/report.html")
for comps in config["comparisons"][config["analysis_name"]]["comps"]:
multiparts.add(comps.get("multipart", DEFAULT_REPORT_PART))
if multiparts:
targets.extend([os.path.join(MAINDIR, config["analysis_name"], "report-{}.html".format(mp)) if mp != DEFAULT_REPORT_PART else os.path.join(MAINDIR, config["analysis_name"], "report.html") for mp in multiparts])
else:
targets.append(os.path.join(MAINDIR, config["analysis_name"], "report.html".format(DEFAULT_REPORT_PART)))
return targets
......
Markdown is supported
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