Skip to content

Commit

Permalink
Add mapping file
Browse files Browse the repository at this point in the history
  • Loading branch information
seppinho committed Dec 19, 2023
1 parent edc5bde commit a98cfae
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 22 deletions.
28 changes: 15 additions & 13 deletions modules/local/calculate_statistics.nf
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@ process CALCULATE_STATISTICS {
path bam_file

output:
path "*summary.tab.txt", emit: stats_ch
path "*summary.txt", emit: stats_ch
path "*mapping.txt", emit: mapping_ch
path "*.zip", emit: fastqc_ch


script:
def output_name = "${bam_file.baseName}.summary.txt"
def output_name_tab = "${bam_file.baseName}.summary.tab.txt"
def mapping_name = "${bam_file.baseName}.mapping.txt"

"""
## determine mapping
echo -e "Sample\tFilename" > $mapping_name
samtools samples ${bam_file} >> $mapping_name
## calculate summary statistics
samtools samples ${bam_file}
samtools coverage ${bam_file} > samtools_coverage_${bam_file.baseName}.txt
csvtk grep -t -f3 -p 16569 samtools_coverage_${bam_file.baseName}.txt -T -o mtdna.txt
Expand All @@ -25,16 +29,14 @@ process CALCULATE_STATISTICS {
mean_depth=\$(csvtk cut -t -f 7 mtdna.txt)
mean_base_quality=\$(csvtk cut -t -f 8 mtdna.txt)
mean_map_quality=\$(csvtk cut -t -f 9 mtdna.txt)
echo Sample\tParameter\tValue > $output_name
echo ${bam_file.baseName}\tContig\t\${contig} >> $output_name
echo ${bam_file.baseName}\tNumberofReads\t\${numreads} >> $output_name
echo ${bam_file.baseName}\tCoveredBases\t\${covered_bases} >> $output_name
echo ${bam_file.baseName}\tCoveragePercentage\t\${covered_bases_percentage} >> $output_name
echo ${bam_file.baseName}\tMeanDepth\t\${mean_depth} >> $output_name
echo ${bam_file.baseName}\tMeanBaseQuality\t\${mean_base_quality} >> $output_name
echo ${bam_file.baseName}\tMeanMapQuality\t\${mean_map_quality} >> $output_name
csvtk space2tab $output_name -o $output_name_tab
echo -e "Sample\tParameter\tValue" > $output_name
echo -e "${bam_file.baseName}\tContig\t\${contig}" >> $output_name
echo -e "${bam_file.baseName}\tNumberofReads\t\${numreads}" >> $output_name
echo -e "${bam_file.baseName}\tCoveredBases\t\${covered_bases}" >> $output_name
echo -e "${bam_file.baseName}\tCoveragePercentage\t\${covered_bases_percentage}" >> $output_name
echo -e "${bam_file.baseName}\tMeanDepth\t\${mean_depth}" >> $output_name
echo -e "${bam_file.baseName}\tMeanBaseQuality\t\${mean_base_quality}" >> $output_name
echo -e "${bam_file.baseName}\tMeanMapQuality\t\${mean_map_quality}" >> $output_name
fastqc $bam_file -o .
Expand Down
3 changes: 3 additions & 0 deletions modules/local/input_validation.nf
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ process INPUT_VALIDATION {

input:
path statistics
path mapping

output:
path("sample_statistics.txt"), emit: summarized_ch
path("sample_mappings.txt"), emit: mapping_ch
path("excluded_samples.txt"), emit: excluded_ch
path("contig.txt"), emit: contig_ch

"""
csvtk concat -t ${statistics} -T -o sample_statistics.txt
csvtk concat -t ${mapping} -T -o sample_mappings.txt
java -jar /opt/mutserve/mutserve.jar stats \
--input sample_statistics.txt \
--detection-limit ${params.detection_limit} \
Expand Down
12 changes: 7 additions & 5 deletions modules/local/report.nf
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
process REPORT {

publishDir "${params.output_reports}", mode: 'copy'
publishDir "${params.output_reports}", mode: 'copy'

input:
input:
path report
path variants
path haplogroups
path haplocheck
path statistics
path mapping

output:
output:
file "*.html"

"""
Expand All @@ -27,10 +28,11 @@ process REPORT {
Rscript -e "require('rmarkdown'); render('${report}',
params = list(
pipeline_parameters = 'params.txt',
variants = '${variants}',
variants = '${variants}',vi wo
haplogroups = '${haplogroups}',
haplocheck = '${haplocheck}',
statistics = '${statistics}'
statistics = '${statistics}',
mapping = '${mapping}'
),
knit_root_dir='\$PWD', output_file='\$PWD/report.html')"
"""
Expand Down
3 changes: 2 additions & 1 deletion reports/report.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ params:
haplocheck: ../tests/data/report2/haplocheck.txt
variants: ../tests/data/report2/variants_ann.txt
statistics: ../tests/data/report2/sample_statistics.txt
mapping: ../tests/data/report2/mapping.txt
pipeline_parameters: ../tests/data/report2/pipeline_parameters.txt
---

Expand All @@ -29,7 +30,7 @@ contamination <- read.delim(params$haplocheck)
haplogroups <- read.delim(params$haplogroups)
statistics <- read.delim(params$statistics)
pipeline_params <- read.delim(params$pipeline_parameters)
mapping <- read.delim(params$mapping)
statTable<-spread(statistics, key = Parameter, value = Value)
statTable$MeanCoverage<-as.numeric(statTable$MeanDepth)
Expand Down
8 changes: 5 additions & 3 deletions workflows/mtdna_server_2.nf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if (params.output_reports == null || params.output_auxiliary == null ) {
params.output_auxiliary = params.output
}

include { INDEX } from '../modules/local/index'
include { INDEX } from '../modules/local/index'
include { CALCULATE_STATISTICS } from '../modules/local/calculate_statistics'
include { INPUT_VALIDATION } from '../modules/local/input_validation'
include { QUALITY_CONTROL } from '../modules/local/quality_control'
Expand Down Expand Up @@ -53,7 +53,8 @@ workflow MTDNA_SERVER_2 {
)

INPUT_VALIDATION(
CALCULATE_STATISTICS.out.stats_ch.collect()
CALCULATE_STATISTICS.out.stats_ch.collect(),
CALCULATE_STATISTICS.out.mapping_ch.collect()
)


Expand Down Expand Up @@ -111,7 +112,8 @@ workflow MTDNA_SERVER_2 {
variants_txt_ch,
HAPLOGROUP_DETECTION.out.haplogroups_ch,
CONTAMINATION_DETECTION.out.contamination_txt_ch,
INPUT_VALIDATION.out.summarized_ch
INPUT_VALIDATION.out.summarized_ch,
INPUT_VALIDATION.out.mapping_ch
)

}
Expand Down

0 comments on commit a98cfae

Please sign in to comment.