Hi I am new to shell programming was reading a "chromosome coordinates" file line by line and then further want to use each line and give it to a new different commands so my "chromosome coordinates" file looks like below these are few lines but I have 2500 such lines in this file
and I am reading this file using following script which looks like working fine
while read -r line || [[ -n "$line" ]]; # read all the line and this reads the last line|| [[ -n "$line" ]]
done < "$filename"
Now i want to give each line of the "chromosome coordinates" file as an input to samtools command e.g.
samtools view -f 0x02 -b CLL.bam chr1:822979-822979 > chr1_reads.bam
samtools view -f 0x02 -b CLL.bam chr1:1052781-1052781 > chr1.1_reads.bam
samtools view -f 0x02 -b CLL.bam chr1:1216196-1216196 > chr1.2_reads.bam
and so on for 2500 lines
The above output file will contain reads from one location only but I want to make output files that contains reads from all the 2500 lines that were read from the original "chromosome coordinates" file.
Further want to use the "chr1_reads.bam" , chr1.1_reads.bam, chr1.2_reads.bam files as an input to another command
samtools index chr1_reads.bam
samtools index chr1.1_reads.bam
samtools index chr1.2_reads.bam
then finally give the indexed file as input to another command
samtools idxstats chr1_reads.bam > chr_count
samtools idxstats chr1.1_reads.bam > chr_count
samtools idxstats chr1.2_reads.bam > chr_count`
But want to store the output of the final command to be stored in one singe output file "chr_count"
Any suggestions will be highly appreciated.