This is a test version of Biostars. For the public version, visit https://www.biostars.org.
sorting multiple .bam files in linux cluster

I am working Linux cluster and ı have 1000 bam files under bam/ directory and they have pretty similar name bam_runid_bf2ff0593235864c9d423d28f1746a42d62df29e_0_0 and just first 0 changing into folder like 1,2,3,

I am wondering how can ı sort them as a single and merge them after indexing. I tried:

for f in bam/*_0.bam
do
  samtools sort -@ 7 $f ${f/bam/sorted}
done

what u advised but it did not worked. sorry ı am very new in this field .I generate a snakefile. When I try dry run with snakemake -n this error is shown

SyntaxError in line 2 of /cluster/lrcfs/2397405/projects/nanopore_testing/data/remoratrial/Snakefile: invalid syntax

When I type in working node same command samtools options are pop up my screen :( could you explain to me more simple? Thanks

bam samtools snakemake

Your samtools sort syntax is incorrect. it should be as follows (assuming rest of your loop is working as expected).

   samtools sort -@ 7 -o ${f/bam/sorted} $f

If there is snakemake involved (code for which you have not shown above) then there may be more to this than just samtools syntax.

Should it be ${f/.bam/.sorted.bam} instead?

1 answer

Hi all,

I find out that samtools default package (1.15.1) has issue with library (libtinfow.so.6: no version information availabl(required by samtools)) so if you change the version like 1.14.1, this command (for f in <folder>/*_0.bam; do samtools sort -@ 7 -o ${f/bam/sorted} $f; done`) is working fine.

Log in to answer this question.