Skip to content

Commit

Permalink
updating readme and including test with makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
adigenova committed Nov 24, 2020
1 parent 0cf4707 commit 55cb63b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
```
22 changes: 17 additions & 5 deletions main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -36,28 +35,41 @@ 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)]}
.ifEmpty{exit 1, "params.bams_csv was empty - no input files supplied" }
.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')
.map { path -> [ path.name.replace(".bam.bai",""), path ] }
//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)
}
}


Expand Down
11 changes: 11 additions & 0 deletions test/makefile
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 55cb63b

Please sign in to comment.