<p>I have 133 aligned and sorted BAM files that I am trying to run through the ref_map.pl script from the STACKS pipeline. My script looks as follows:</p>
<pre><code>module load stacks

ref_map.pl -T 15 --popmap B2_filenames.txt --samples /home/heather/scratch/03_sort_and_map/filtered_and_sorted/B2/ --out-path /home/heather/scratch/ref_map_results/full_data

echo &quot;ref_map.pl for B2 dataset completed&quot;
</code></pre>
<p>I keep running into the issue where gstacks is unable to read the BAM files. This is what the log file looks like:</p>
<pre><code>  Configuration for this run:
  Input mode: reference-based
  Population map: 'B2_filenames.txt'
  Input files: 133, e.g. '/home/heather/scratch/03_sort_and_map/filtered_and_sorted/B2/1401-47750.sort_filt.bam'
  Output to: '/home/heather/scratch/ref_map_results/full_data/'
  Model: marukilow (var_alpha: 0.01, gt_alpha: 0.05)

Reading BAM headers...
Processing all loci...
Error: No BAM records.
Error: (At the 0th record in file '/home/heather/scratch/03_sort_and_map/filtered_and_sorted/B2/1401-47754_B2.sort_filt.bam'.)
Aborted.

ref_map.pl: Aborted because the last command failed (1).
Last command executed by ref_map.pl was:
  /cvmfs/soft.computecanada.ca/easybuild/software/2020/avx2/Core/stacks/2.64/bin/gstacks -I /home/heather/scratch/03_sort_and_map/filtered_and_sorted/B2/ -M B2_filenames.txt -O /home/heather/scratch/ref_map_results/full_data -t 15
</code></pre>
<p>I checked the BAM file with samtools - the headers look ok, and I don't get any output when I run samtools quickcheck, so I can't quite figure out what is causing the issue. I am following the same pipeline as I did with a previous batch of data and can't understand whats going wrong.</p>

CC BY-SA 4.0
2023-07-13T18:59:07.677Z
"the headers look ok, and I don't get any output when I run samtools quickcheck" - this would be true even if the files contained **only** headers, no? Do you see alignment info when you look beyond the headers?
Ram RS
CC BY-SA 4.0
2023-07-18T20:32:36.023Z
I keep getting a similar error with the sorted and filtered bam file generated from samtools "Error: 'sample.bam': this is a SAM file (and BAM was specified).
aych
<sam><genomics><genetics>
STACKS ref_map.pl no BAM records
# STACKS ref_map.pl no BAM records

(Asked by: username_0 on 2023-07-12)

I have 133 aligned and sorted BAM files that I am trying to run through the ref_map.pl script from the STACKS pipeline. My script looks as follows:
module load stacks

ref_map.pl -T 15 --popmap B2_filenames.txt --samples /home/heather/scratch/03_sort_and_map/filtered_and_sorted/B2/ --out-path /home/heather/scratch/ref_map_results/full_data

echo "ref_map.pl for B2 dataset completed"

I keep running into the issue where gstacks is unable to read the BAM files. This is what the log file looks like:
  Configuration for this run:
  Input mode: reference-based
  Population map: 'B2_filenames.txt'
  Input files: 133, e.g. '/home/heather/scratch/03_sort_and_map/filtered_and_sorted/B2/1401-47750.sort_filt.bam'
  Output to: '/home/heather/scratch/ref_map_results/full_data/'
  Model: marukilow (var_alpha: 0.01, gt_alpha: 0.05)

Reading BAM headers...
Processing all loci...
Error: No BAM records.
Error: (At the 0th record in file '/home/heather/scratch/03_sort_and_map/filtered_and_sorted/B2/1401-47754_B2.sort_filt.bam'.)
Aborted.

ref_map.pl: Aborted because the last command failed (1).
Last command executed by ref_map.pl was:
  /cvmfs/soft.computecanada.ca/easybuild/software/2020/avx2/Core/stacks/2.64/bin/gstacks -I /home/heather/scratch/03_sort_and_map/filtered_and_sorted/B2/ -M B2_filenames.txt -O /home/heather/scratch/ref_map_results/full_data -t 15

I checked the BAM file with samtools - the headers look ok, and I don't get any output when I run samtools quickcheck, so I can't quite figure out what is causing the issue. I am following the same pipeline as I did with a previous batch of data and can't understand whats going wrong.

**Tags:** sam, genomics, genetics
> **Comments:**
> **username_1**: "the headers look ok, and I don't get any output when I run samtools quickcheck" - this would be true even if the files contained **only** headers, no? Do you see alignment info when you look beyond the headers?  
> **username_2**: I keep getting a similar error with the sorted and filtered bam file generated from samtools "Error: 'sample.bam': this is a SAM file (and BAM was specified).  

---

## 0 answers

