@Pierre Thanks for your reply, can I also extract one mpileup per read with a filtering region II know try it like this:
while read LINE
do
chr=$( printf "$LINE" | cut -f1 )
start=$( printf "$LINE" | cut -f2 )
stop=$( printf "$LINE" | cut -f3 )
region=$chr:$start-$stop
echo "Regions:" $region
echo "start:" $start
echo "stop:" $stop
echo "line:" $LINE
mkdir -p results/${region/-/_}
samtools view -F 4 $inBAM $region | while read L; do (samtools view -H $inBAM && echo "$L" ) | samtools view -bS - | samtools mpileup -f $refGenome -r $region - > results/${region/-/_}/${FILE%.bam}Mpileup.txt; done
done < $BED
unfortunately this fails. I need to have the mpileup files inside a different region directory so that I can distinguish them. Later on and i will not be left over with 1000 files if I have 200 regions in my bed file. Hope this is also possible thanks for you help already!
this is the error I got:
[bam_header_read] EOF marker is absent. The input is probably truncated.
[samopen] SAM header is present: 93 sequences.
[bam_index_load] fail to load BAM index.
[mpileup] fail to load index for -