How I know a file is sam or bam, sorted or unsorted
2
1
Entering edit mode
5.3 years ago
zizigolu ★ 4.3k

Hi

I have a file by STAR alignment, I supposed to get a bam file but I obtained Aligned.out.sam

Is there any command to check if this file is a .bam or .sam file? A command to check this file sorted or unsorted?

Thank you so much

RNA-Seq alignment • 5.8k views
ADD COMMENT
5
Entering edit mode
5.3 years ago

Check the error log if STAR had any memory issues, --outSAMtype BAM SortedByCoordinate is supposed to sort the output.

ADD COMMENT
1
Entering edit mode

Just to follow up on Arup's advice -- given that you seem to have generated a SAM file instead of a BAM file, it seems highly likely that the conversion and sorting failed [EDIT:], therefore it would be highly advisable to understand what caused STAR to not honor your parameter choices, i.e. read the log file(s) and see if you can pinpoint the error that must have occurred.

ADD REPLY
0
Entering edit mode

This command gave sorted bam using STAR

STAR --runThreadN 4 --genomeDir ./STAR_hg38_Genome --readFilesIn 1.fastq 2.fastq --limitBAMsortRAM 64606632121 --outFileNamePrefix ./SeqBatch2/ --outSAMtype BAM   SortedByCoordinate --outSAMmode Full --outSAMstrandField intronMotif
ADD REPLY
1
Entering edit mode

So it was a problem with the memory. It'd be great if you could accept the answer that suggested that so that other users in the future will be pointed to the right track immediately.

ADD REPLY
3
Entering edit mode
5.3 years ago

Check the bam/sam file header line using samtools samtools view -H Aligned.out.sam |grep "@HD" if you see SO:coordinate is present, it means the output is sorted. For STAR sorted/unsorted output check the STAR aligner manual section 4.3 .

ADD COMMENT
1
Entering edit mode

This is the results

[fi1d18@cyan01 ~]$ samtools view -H Aligned.out.sam |grep "@HD"
@HD     VN:1.4
[fi1d18@cyan01 ~]$

Unsorted?

ADD REPLY
0
Entering edit mode

Yes the output is unsorted.

ADD REPLY
0
Entering edit mode

That means this STAR command does not work

STAR --genomeDir ./STAR_hg38_Genome --readFilesIn ./1.fastq ./2.fastq --outSAMtype BAM SortedByCoordinate

Because I expected by adding --outSAMtype BAM SortedByCoordinate to STAR alignment I am getting a sorted .bam as output

ADD REPLY
0
Entering edit mode

you could try to output both and see if there is a difference,

--outSAMtype BAM Unsorted SortedByCoordinate

check both files to see if either is sorted

ADD REPLY

Login before adding your answer.

Traffic: 1705 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6