I have multiple sam file like this:
sam file location:
/data/SNU_work/Analysis/mapped/mapped
samtool location:
/home/yog/software/samtools-1.3.1/samtools
218_9W_Pa2.sam
218_9W_Pa1.sam
216_7W_Co1.sam
216_7W_Ca2.sam
216_7W_Ca1.sam
I converting them one by one using below commnad:
/home/yog/software/samtools-1.3.1/samtool view -b 218_9W_Pa2.sam > 218_9W_Pa2.bam
After that I am extracting mapped read from bam file and sorting of bam using below cammnd:
/home/yog/software/samtools-1.3.1/samtools view -b -F4 218_9W_Pa2.bam > 218_9W_Pa2.mapped.bam
/home/yog/software/samtools-1.3.1/samtools sort 218_9W_Pa2.mapped.bam -o 218_9W_Pa2_mapped_sort.bam
After sorting bam I also want to do index bam file and follwed by raw read count:
For indexing: /home/yog/software/samtools-1.3.1/samtools index 218_9W_Pa2_mapped_sort.bam
For read count: /home/yog/software/samtools-1.3.1/samtools idxstats 218_9W_Pa2_mapped_sort.bam > readcount_for_each_bam
Please, can you suggest how can I do all step for all sam files in a single command/scripts?
Thanks
I removed flag -S from command as you have suggested.
I used this scripts and I able to extract mapped reads from sam file to in the bam format.
Now can you please suggest how to sort and index all these bam files?
replace the text within the single quotes with the command you wish to execute.
In general, when someone helps you with an advice you need to make a concerted effort to understand what the content consists of and how it works - that way it is easy to generalize and apply to a different situation.
Conceptually quite easy is a
for
loopto avoid .sam.bam you can do
for j in *.sam ; do basename $j .sam ;done |sed ':a;N;$!ba;s/\n/ /g'
sed is just removing the new lines by spaces