From 55cb63b7668abe4e569bc8ac55f3f2886506935c Mon Sep 17 00:00:00 2001 From: adigenova Date: Wed, 25 Nov 2020 00:45:05 +0100 Subject: [PATCH] updating readme and including test with makefile --- README.md | 17 +++++++++++++++++ main.nf | 22 +++++++++++++++++----- test/makefile | 11 +++++++++++ 3 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 test/makefile diff --git a/README.md b/README.md index 228f328..a89ea26 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,19 @@ # bam2cram A repository to convert BAM->CRAM files + +## run examples + +``` +#using a tsv file, with custom working directory +nextflow run main.nf --bam_csv test/bams.txt --fasta test/ref.fa --output_folder csv2 -w tmp +#using a directory with bams +nextflow run main.nf --bams test --fasta test/ref.fa --output_folder dirs_bam +``` +### tsv file +A tabular file with the following colums: + +``` +label bam index +S4 /path/S4.bam /path/S4.bam.bai +S3 /path/S3.bam /path/S3.bam.bai +``` diff --git a/main.nf b/main.nf index 1eb7f0c..fc92986 100644 --- a/main.nf +++ b/main.nf @@ -13,7 +13,6 @@ def show_help (){ --bams [directory] input folder with BAM files and indexes References --fasta [file] Path to fasta reference to encode the CRAM file - --fai [file] Path to fasta reference index [samtools faidx] Input alternatives: --bam_csv file with tabular data for each sample to process [label bam index ] -profile [str] Configuration profile to use. @@ -36,13 +35,23 @@ log.info IARC_Header() log.info tool_header() //check fasta and fasta index -if (!params.fasta && !params.fai) exit 1, "The reference fasta file need to be provided!" +if (!params.fasta) exit 1, "The reference fasta file need to be provided!" + //we check the reference ch_fasta = Channel.value(file(params.fasta)).ifEmpty{exit 1, "Fasta file not found: ${params.fasta}"} -ch_fai = Channel.value(file(params.fai)).ifEmpty{exit 1, "fai index file not found: ${params.fai}"} +ch_fai = Channel.value(file(params.fasta+".fai")).ifEmpty{exit 1, "fai index file not found: ${params.fasta}.fai"} + +//check that BAM input is provided! +if(!params.bam_csv && !params.bams) exit 1, "No --bam_csv nor --bams options provided!" -//see file ./test_dataset/sample_fwrev.txt +//we print the parameters +log.info "\n" +log.info "-\033[2m------------------Calling PARAMETERS--------------------\033[0m-" +log.info params.collect{ k,v -> "${k.padRight(18)}: $v"}.join("\n") +log.info "-\033[2m--------------------------------------------------------\033[0m-" +log.info "\n" + if(params.bam_csv) { Channel.fromPath(file(params.bam_csv)).splitCsv(header: true, sep: '\t', strip: true) .map{row -> [ row.label, file(row.bam), file(row.index)]} @@ -50,7 +59,7 @@ if(params.bam_csv) { .into { inputbams; bamstats; sizebams } }else{ - + if(file(params.bams).listFiles().findAll { it.name ==~ /.*bam/ }.size() > 0){ bams = Channel.fromPath( params.bams+'/*.bam' ) .map {path -> [ path.name.replace(".bam",""),path]} bams_index = Channel.fromPath( params.bams+'/*.bam.bai') @@ -58,6 +67,9 @@ if(params.bam_csv) { //we create the chanel files = bams.join(bams_index) files.into {inputbams; bamstats; sizebams} + }else{ + println "ERROR: input folder ${params.bams} contains no BAM files"; System.exit(1) + } } diff --git a/test/makefile b/test/makefile new file mode 100644 index 0000000..88c029d --- /dev/null +++ b/test/makefile @@ -0,0 +1,11 @@ +.DELETE_ON_ERROR: + +${PREF}.R1.fq.gz: + wgsim ref.fa ${PREF}.R1.fq ${PREF}.R2.fq 2>${PREF}.wgsim.err >${PREF}.wgsim.log + gzip ${PREF}.R2.fq + gzip ${PREF}.R1.fq +$(PREF).bam:${PREF}.R1.fq.gz + bwa mem -R '@RG\tID:${PREF}\tSM:${PREF}' ref.fa ${PREF}.R1.fq.gz ${PREF}.R2.fq.gz 2>${PREF}.bwa.err | samtools view -b - | samtools sort -o $@ - + samtools index $@ +all:$(PREF).bam +