This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Piping Input Into Picard Sortsam

Hello everyone,

does it make any sense to (Unix) pipe input into Picard SortSam, or will SortSam wait for all the input before starting?

For example, if I have the command

samtools view -Shu in.sam | \
java -Xmx4g SortSam.jar I=/dev/stdin O=sorted.bam SO=coordinate VALIDATION_STRINGENCY=SILENT

Will SortSam already do some work on the reads it gets from samtools view (e.g. by putting new reads in place) or will it wait for ALL reads from samtools until it starts sorting? In the latter case I would have SortSam running and blocking memory without doing something for the execution time of samtools view. Does anybody know?

Thanks

picard bam

2 answers

Yes, picard (and most java apps should) take pipes. I do query sorts to FASTQs like this as one example:

java -Xmx30g -jar ${PICARD}/SortSam.jar \
I=$IN_BAM \
TMP_DIR=${TMP} \
MAX_RECORDS_IN_RAM=7000000 \
VALIDATION_STRINGENCY=LENIENT \
COMPRESSION_LEVEL=0 \
O=/dev/stdout \
SORT_ORDER=queryname | \ # NOTE PIPE HERE
java -Xmx12g -jar ${PICARD}/SamToFastq.jar \
I=/dev/stdin \
MAX_RECORDS_IN_RAM=3000000 \
VALIDATION_STRINGENCY=LENIENT \
F=$OUT.R1.fq \
F2=$OUT.R2.fq

O=/dev/stdout and I=/dev/stdin are quite handy :) I havent run time comparisons, but I like pipes wherever I can.

I don't know by experience by you can try it and use

[your_command_prompt]$ top

To see if both samtools and java SortSam.jar are running at the same time

Good idea thanks. So I was running the command and from the CPU usage one can see that both programs acutally are running (and computing) something at the same time.

Log in to answer this question.