My input file .bam files with mapped reads is bam1 from step 1
Step 1 samtools view -F 0X4 > **bam1**
Step 2 I want to keep only those reads which are paired and mapped. so I got this flag no from here
samtools view **bam1** | awk '{ if ($2 == 99 || $2 == 147 || $2 == 83 || $2 == 163 || $2 == 67 || $2 == 131 || $2 == 115 || $2 ==179 && $9 >= -10000 && $9 <= 10000) > **bam2**
I have 20 bam2s from different samples and I want to merge them but I am getting this error bamtools merge ERROR: could not open input BAM file(s)... Aborting.
Step 3 I then redid step 2
samtools view -H **bam1** > bam2
samtools view **bam1** | awk '{ if ($2 == 99 || $2 == 147 || $2 == 83 || $2 == 163 || $2 == 67 || $2 == 131 || $2 == 115 || $2 ==179 && $9 >= -10000 && $9 <= 10000) > **bam2**
samtools view -bS t**bam2** > **newbam2**
**[E::sam_parse1] missing SAM header
[W::sam_read1] parse error at line 1
[main_samview] truncated file.**
how can I resolve this issue?
Where did you create a file called tbam2?
Also, if there is a header in bam1, surely the awk after the pipe removes it. Perhaps you should add another if statement there to deal with header lines.
Also, for more clarity, please use four spaces before commands or the "code sample" function.
Also, in your awk, do you think
affects all the "ors" or just the last one?