Skip to content

Commit 55cb63b

Browse files
committed
updating readme and including test with makefile
1 parent 0cf4707 commit 55cb63b

File tree

3 files changed

+45
-5
lines changed

3 files changed

+45
-5
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,19 @@
11
# bam2cram
22
A repository to convert BAM->CRAM files
3+
4+
## run examples
5+
6+
```
7+
#using a tsv file, with custom working directory
8+
nextflow run main.nf --bam_csv test/bams.txt --fasta test/ref.fa --output_folder csv2 -w tmp
9+
#using a directory with bams
10+
nextflow run main.nf --bams test --fasta test/ref.fa --output_folder dirs_bam
11+
```
12+
### tsv file
13+
A tabular file with the following colums:
14+
15+
```
16+
label bam index
17+
S4 /path/S4.bam /path/S4.bam.bai
18+
S3 /path/S3.bam /path/S3.bam.bai
19+
```

main.nf

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ def show_help (){
1313
--bams [directory] input folder with BAM files and indexes
1414
References
1515
--fasta [file] Path to fasta reference to encode the CRAM file
16-
--fai [file] Path to fasta reference index [samtools faidx]
1716
Input alternatives:
1817
--bam_csv file with tabular data for each sample to process [label bam index ]
1918
-profile [str] Configuration profile to use.
@@ -36,28 +35,41 @@ log.info IARC_Header()
3635
log.info tool_header()
3736

3837
//check fasta and fasta index
39-
if (!params.fasta && !params.fai) exit 1, "The reference fasta file need to be provided!"
38+
if (!params.fasta) exit 1, "The reference fasta file need to be provided!"
39+
4040
//we check the reference
4141
ch_fasta = Channel.value(file(params.fasta)).ifEmpty{exit 1, "Fasta file not found: ${params.fasta}"}
42-
ch_fai = Channel.value(file(params.fai)).ifEmpty{exit 1, "fai index file not found: ${params.fai}"}
42+
ch_fai = Channel.value(file(params.fasta+".fai")).ifEmpty{exit 1, "fai index file not found: ${params.fasta}.fai"}
43+
44+
//check that BAM input is provided!
45+
if(!params.bam_csv && !params.bams) exit 1, "No --bam_csv nor --bams options provided!"
4346

4447

45-
//see file ./test_dataset/sample_fwrev.txt
48+
//we print the parameters
49+
log.info "\n"
50+
log.info "-\033[2m------------------Calling PARAMETERS--------------------\033[0m-"
51+
log.info params.collect{ k,v -> "${k.padRight(18)}: $v"}.join("\n")
52+
log.info "-\033[2m--------------------------------------------------------\033[0m-"
53+
log.info "\n"
54+
4655
if(params.bam_csv) {
4756
Channel.fromPath(file(params.bam_csv)).splitCsv(header: true, sep: '\t', strip: true)
4857
.map{row -> [ row.label, file(row.bam), file(row.index)]}
4958
.ifEmpty{exit 1, "params.bams_csv was empty - no input files supplied" }
5059
.into { inputbams; bamstats; sizebams }
5160

5261
}else{
53-
62+
if(file(params.bams).listFiles().findAll { it.name ==~ /.*bam/ }.size() > 0){
5463
bams = Channel.fromPath( params.bams+'/*.bam' )
5564
.map {path -> [ path.name.replace(".bam",""),path]}
5665
bams_index = Channel.fromPath( params.bams+'/*.bam.bai')
5766
.map { path -> [ path.name.replace(".bam.bai",""), path ] }
5867
//we create the chanel
5968
files = bams.join(bams_index)
6069
files.into {inputbams; bamstats; sizebams}
70+
}else{
71+
println "ERROR: input folder ${params.bams} contains no BAM files"; System.exit(1)
72+
}
6173
}
6274

6375

test/makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.DELETE_ON_ERROR:
2+
3+
${PREF}.R1.fq.gz:
4+
wgsim ref.fa ${PREF}.R1.fq ${PREF}.R2.fq 2>${PREF}.wgsim.err >${PREF}.wgsim.log
5+
gzip ${PREF}.R2.fq
6+
gzip ${PREF}.R1.fq
7+
$(PREF).bam:${PREF}.R1.fq.gz
8+
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 $@ -
9+
samtools index $@
10+
all:$(PREF).bam
11+

0 commit comments

Comments
 (0)