Seperate DE files required for the report and to be output to the user
This commit is contained in:
parent
46f748f493
commit
1c67e3274e
@ -237,29 +237,29 @@ def dtu_section(dtu_file, section, gt_dic, ge_dic):
|
|||||||
section.table(dtu_results.loc[dtu_pvals.index])
|
section.table(dtu_results.loc[dtu_pvals.index])
|
||||||
|
|
||||||
|
|
||||||
def add_gene_names_dge(dge_file, geid_gname):
|
def copy_dge_add_gene_names(dge_file, geid_gname, newfile_name):
|
||||||
"""Add gene name column to DGE TSV with gene ID to gene Name dict."""
|
"""Add gene name column to DGE TSV with gene ID to gene Name dict."""
|
||||||
dge_results = pd.read_csv(dge_file, sep='\t')
|
dge_results = pd.read_csv(dge_file, sep='\t')
|
||||||
column_to_move = dge_results.index.map(
|
column_to_move = dge_results.index.map(
|
||||||
lambda x: geid_gname.get(x))
|
lambda x: geid_gname.get(x))
|
||||||
dge_results.insert(0, "gene_name", column_to_move)
|
dge_results.insert(0, "gene_name", column_to_move)
|
||||||
dge_results.to_csv(dge_file, index=True, index_label="gene_id", sep="\t")
|
dge_results.to_csv(newfile_name, index=True, index_label="gene_id", sep="\t")
|
||||||
|
|
||||||
|
|
||||||
def add_gene_names_filtered(unfiltered_file, geid_gname):
|
def copy_filtered_add_gene_names(unfiltered_file, geid_gname, newfile_name):
|
||||||
"""Use gene id to gene name dict to add name column to counts TSV."""
|
"""Use gene id to gene name dict to add name column to counts TSV."""
|
||||||
unfiltered = pd.read_csv(unfiltered_file, sep='\t')
|
unfiltered = pd.read_csv(unfiltered_file, sep='\t')
|
||||||
unfiltered.insert(1, "gene_name", unfiltered.gene_id.map(
|
unfiltered.insert(1, "gene_name", unfiltered.gene_id.map(
|
||||||
lambda x: geid_gname.get(x)))
|
lambda x: geid_gname.get(x)))
|
||||||
unfiltered.to_csv(unfiltered_file, index=False, sep='\t')
|
unfiltered.to_csv(newfile_name, index=False, sep='\t')
|
||||||
|
|
||||||
|
|
||||||
def add_tpm_names(tpm_file, txid_gname):
|
def copy_tpm_add_gene_names(tpm_file, txid_gname, newfile_name):
|
||||||
"""Use transcript id to gene name dict to add gname column to TPM TSV."""
|
"""Use transcript id to gene name dict to add name column to TPM TSV."""
|
||||||
tpm = pd.read_csv(tpm_file, sep='\t')
|
tpm = pd.read_csv(tpm_file, sep='\t')
|
||||||
tpm.insert(1, "gene_name", tpm.Reference.map(
|
tpm.insert(1, "gene_name", tpm.Reference.map(
|
||||||
lambda x: txid_gname.get(x)))
|
lambda x: txid_gname.get(x)))
|
||||||
tpm.to_csv(tpm_file, index=False, sep='\t')
|
tpm.to_csv(newfile_name, index=False, sep='\t')
|
||||||
|
|
||||||
|
|
||||||
def dge_section(dge_file, section, ids_dic):
|
def dge_section(dge_file, section, ids_dic):
|
||||||
@ -404,13 +404,14 @@ Find the full sequences of any transcripts in the
|
|||||||
section.table(alignment_summary_df, key='alignment-stats', index=True)
|
section.table(alignment_summary_df, key='alignment-stats', index=True)
|
||||||
salmon_table(tpm, section)
|
salmon_table(tpm, section)
|
||||||
gene_txid, gene_name, geid_gname = get_translations(stringtie)
|
gene_txid, gene_name, geid_gname = get_translations(stringtie)
|
||||||
|
|
||||||
# Use dictionaries to add gene names to the counts tsv files to help users
|
# Use dictionaries to add gene names to the counts tsv files to help users
|
||||||
add_gene_names_dge(dge, geid_gname)
|
copy_dge_add_gene_names(dge, geid_gname, "results_dge.tsv")
|
||||||
add_gene_names_dge(gene_counts, geid_gname)
|
copy_dge_add_gene_names(gene_counts, geid_gname, "all_gene_counts.tsv")
|
||||||
add_gene_names_filtered(filtered, geid_gname)
|
copy_filtered_add_gene_names(
|
||||||
add_gene_names_filtered(unfiltered, geid_gname)
|
filtered, geid_gname, "filtered_transcript_counts_with_genes.tsv")
|
||||||
add_tpm_names(tpm, gene_txid)
|
copy_filtered_add_gene_names(
|
||||||
|
unfiltered, geid_gname, "unfiltered_transcript_counts_with_genes.tsv")
|
||||||
|
copy_tpm_add_gene_names(tpm, gene_txid, "unfiltered_tpm_transcript_counts.tsv")
|
||||||
|
|
||||||
# Add tables to report
|
# Add tables to report
|
||||||
dge_section(dge, section, gene_name)
|
dge_section(dge, section, gene_name)
|
||||||
|
|||||||
23
main.nf
23
main.nf
@ -407,10 +407,13 @@ process makeReport {
|
|||||||
path "seqkit/*"
|
path "seqkit/*"
|
||||||
path "isoforms_table/*"
|
path "isoforms_table/*"
|
||||||
output:
|
output:
|
||||||
path("wf-transcriptomes-*.html"), emit: report
|
path ("wf-transcriptomes-*.html"), emit: report
|
||||||
// for DE analysis, a `gene_name` column will be added to
|
// If de analysis has been run output the counts files with gene name added.
|
||||||
// `de_report/results_dge.tsv`
|
path ("results_dge.tsv"), emit: results_dge, optional: true
|
||||||
path "results_dge.tsv", emit: de_analysis, optional: true
|
path ("unfiltered_tpm_transcript_counts.tsv"), emit: tpm, optional: true
|
||||||
|
path ("unfiltered_transcript_counts_with_genes.tsv"), emit: unfiltered, optional: true
|
||||||
|
path ("filtered_transcript_counts_with_genes.tsv"), emit: filtered, optional: true
|
||||||
|
path ("all_gene_counts.tsv"), emit: gene_counts, optional: true
|
||||||
shell:
|
shell:
|
||||||
// Convert the sample_id arrayList.
|
// Convert the sample_id arrayList.
|
||||||
sids = new BlankSeparatedList(sample_ids)
|
sids = new BlankSeparatedList(sample_ids)
|
||||||
@ -691,7 +694,7 @@ workflow pipeline {
|
|||||||
|
|
||||||
report = makeReport.out.report
|
report = makeReport.out.report
|
||||||
|
|
||||||
results = results.concat(makeReport.out.report)
|
results = results.concat(report)
|
||||||
|
|
||||||
if (use_ref_ann){
|
if (use_ref_ann){
|
||||||
results = run_gffcompare.output.gffcmp_dir.concat(
|
results = run_gffcompare.output.gffcmp_dir.concat(
|
||||||
@ -719,9 +722,13 @@ workflow pipeline {
|
|||||||
results = results.map{ [it, null] }.concat(fastq_ingress_results.map { [it, "fastq_ingress_results"] })
|
results = results.map{ [it, null] }.concat(fastq_ingress_results.map { [it, "fastq_ingress_results"] })
|
||||||
|
|
||||||
if (params.de_analysis){
|
if (params.de_analysis){
|
||||||
de_update = makeReport.out.de_analysis
|
de_results = report.concat(
|
||||||
de_results = report.concat(transcriptome, de_outputs.flatten(), counts.flatten(), de_update)
|
transcriptome, de_outputs.flatten(), counts.flatten(),
|
||||||
results = results.concat(de_results.map{ [it, "de_analysis"] })
|
makeReport.out.results_dge, makeReport.out.tpm,
|
||||||
|
makeReport.out.filtered, makeReport.out.unfiltered,
|
||||||
|
makeReport.out.gene_counts)
|
||||||
|
// Output de_analysis results in the dedicated directory.
|
||||||
|
results = results.concat(de_results.map{ [it, "de_analysis"] })
|
||||||
}
|
}
|
||||||
|
|
||||||
results.concat(workflow_params.map{ [it, null]})
|
results.concat(workflow_params.map{ [it, null]})
|
||||||
|
|||||||
@ -76,6 +76,7 @@ process deAnalysis {
|
|||||||
path "de_analysis/results_dge.tsv", emit: dge
|
path "de_analysis/results_dge.tsv", emit: dge
|
||||||
path "de_analysis/results_dexseq.tsv", emit: dexseq
|
path "de_analysis/results_dexseq.tsv", emit: dexseq
|
||||||
path "de_analysis", emit: de_analysis
|
path "de_analysis", emit: de_analysis
|
||||||
|
path "de_analysis/cpm_gene_counts.tsv", emit: cpm
|
||||||
script:
|
script:
|
||||||
// Just try both annotation file type because a .gff extension may be gff2(gtf) or gff3
|
// Just try both annotation file type because a .gff extension may be gff2(gtf) or gff3
|
||||||
String annotation_type = "gtf"
|
String annotation_type = "gtf"
|
||||||
@ -115,7 +116,15 @@ process plotResults {
|
|||||||
output:
|
output:
|
||||||
path "de_analysis/dtu_plots.pdf", emit: dtu_plots
|
path "de_analysis/dtu_plots.pdf", emit: dtu_plots
|
||||||
path "sample_sheet.tsv", emit: sample_sheet_csv
|
path "sample_sheet.tsv", emit: sample_sheet_csv
|
||||||
|
// Output all DE files for use in report process
|
||||||
path "de_analysis/*", emit: stageR
|
path "de_analysis/*", emit: stageR
|
||||||
|
// Output selected DE files to be output in out_dir
|
||||||
|
path "de_analysis/results_dge.pdf", emit: dge_pdf
|
||||||
|
path "de_analysis/results_dge.tsv", emit: dge_tsv
|
||||||
|
path "de_analysis/results_dtu_gene.tsv", emit: dtu_gene
|
||||||
|
path "de_analysis/results_dtu_transcript.tsv", emit: dtu_transcript
|
||||||
|
path "de_analysis/results_dtu_stageR.tsv", emit: dtu_stageR
|
||||||
|
path "de_analysis/results_dtu.pdf", emit: dtu_pdf
|
||||||
"""
|
"""
|
||||||
plot_dtu_results.R
|
plot_dtu_results.R
|
||||||
"""
|
"""
|
||||||
@ -178,14 +187,18 @@ workflow differential_expression {
|
|||||||
merged_TPM = mergeTPM(count_transcripts.out.counts.collect())
|
merged_TPM = mergeTPM(count_transcripts.out.counts.collect())
|
||||||
analysis = deAnalysis(sample_sheet, merged, ref_annotation)
|
analysis = deAnalysis(sample_sheet, merged, ref_annotation)
|
||||||
plotResults(analysis.flt_counts, analysis.stageR, sample_sheet, analysis.de_analysis)
|
plotResults(analysis.flt_counts, analysis.stageR, sample_sheet, analysis.de_analysis)
|
||||||
|
// Concat files required for making the report
|
||||||
de_report = analysis.flt_counts.concat(analysis.gene_counts, analysis.dge, analysis.dexseq,
|
de_report = analysis.flt_counts.concat(analysis.gene_counts, analysis.dge, analysis.dexseq,
|
||||||
analysis.stageR, plotResults.out.sample_sheet_csv, merged, ref_annotation, merged_TPM, analysis.unflt_counts).collect()
|
analysis.stageR, plotResults.out.sample_sheet_csv, merged, ref_annotation, merged_TPM, analysis.unflt_counts).collect()
|
||||||
|
// Concat files required to be output to user
|
||||||
|
de_outputs_concat = analysis.cpm.concat(plotResults.out.dtu_plots, plotResults.out.dge_pdf, plotResults.out.dge_tsv,
|
||||||
|
plotResults.out.dtu_gene, plotResults.out.dtu_transcript, plotResults.out.dtu_stageR, plotResults.out.dtu_pdf).collect()
|
||||||
count_transcripts_file = count_transcripts.out.seqkit_stats.collect()
|
count_transcripts_file = count_transcripts.out.seqkit_stats.collect()
|
||||||
all_counts = merged_TPM.concat(analysis.flt_counts, analysis.gene_counts)
|
all_counts = merged_TPM.concat(analysis.flt_counts, analysis.gene_counts)
|
||||||
emit:
|
emit:
|
||||||
all_de = de_report
|
all_de = de_report
|
||||||
count_transcripts = count_transcripts_file
|
count_transcripts = count_transcripts_file
|
||||||
dtu_plots = plotResults.out.dtu_plots
|
dtu_plots = plotResults.out.dtu_plots
|
||||||
de_outputs = plotResults.out.stageR
|
de_outputs = de_outputs_concat
|
||||||
counts = all_counts
|
counts = all_counts
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user