57
votes
Accepted
What is the difference between FASTA, FASTQ, and SAM file formats?
Let’s start with what they have in common: All three formats store
sequence data, and
sequence metadata.
Furthermore, all three formats are text-based.
However, beyond that all three formats are ...
18
votes
What is the difference between FASTA, FASTQ, and SAM file formats?
In a nutshell,
FASTA file format is a DNA sequence format for specifying or representing DNA sequences and was first described by Pearson ...
15
votes
Accepted
Are soft-clipped bases used for variant calling in samtools + bcftools?
No, samtools (and therefore bcftools) does not use soft-clipped bases. You can quickly confirm this by using either samtools depth or ...
13
votes
Accepted
Why do SAM and BAM use different coordinate systems?
Arithmetic on a zero-based coordinate system is less complicated than that on a one-based system, so it appears zero-based is often (not exclusively) used for binary data formats, like BAM or bigBed, ...
9
votes
Accepted
What are the de facto required fields in a SAM/BAM read group?
The sample tag (i.e. SM) was a mandatory tag in the initial SAM spec (see the .pages file; you need a mac to open it). When transitioned to Latex, this requirement ...
8
votes
Accepted
True bam file encoding and viewing as text
Why not work only with sam files and we need to convert them to bam?
SAM is for human only, a binary format like BAM is smaller and parsed much faster by a program (and we want speed and optimize ...
8
votes
Accepted
Why most aligners do not output the "X" CIGAR operation?
The SAM format originally had only M, I, D, N, S, H, and P CIGAR operators. See the original SAM specification (if you can view Apple Pages documents) and Table 1 in The Sequence Alignment/Map format ...
7
votes
What is the difference between FASTA, FASTQ, and SAM file formats?
FASTA (officially) just stores the name of a sequence and the sequence, unofficially people also add comment fields after the name of the sequence. FASTQ was invented to store both sequence and ...
6
votes
Is there a way to retrieve several SAM fields faster than `samtools view | cut -f`?
I modified your original question: as you are extracting 4 fields, you are not outputting BAM. The answer to the modified question is: yes, you can write a C program with htslib (or with bamtools, ...
6
votes
Accepted
Is there a way to retrieve several SAM fields faster than `samtools view | cut -f`?
The BAM file format is not a text-based format. It has a specific binary structure, specified in reasonable detail in the SAM file format specification. Whenever this information is displayed on a ...
6
votes
Accepted
How to Sort and Index a SAM file without converting it to BAM?
Not only will you save disk space by converting to BAM, but BAM files are faster to manipulate than SAM. Source: Dave Tang's SAMTools wiki.
sort supports ...
5
votes
Accepted
Modifying a SAM header after removing all non-primary reads
Your first command only needs a slight modification to add in -h. This will create a SAM file with a header.
...
5
votes
Accepted
How to merge sam files together with adding read groups
I have used https://github.com/ekg/bamaddrg to add read groups quickly to multiple sam files. And then you can do a samtools merge of the tagged files.
5
votes
How should the SAM MD tag match the CIGAR string?
The MD string doesn't apply to soft or hard clipped regions,. so your example read becomes 43G42. Since variant calling using something simplistic like this is only ...
4
votes
Accepted
Is the optional SAM NM field strictly computable from the MD and CIGAR?
Assuming both the MD and CIGAR are present and correct, then yes, you can parse both to get the edit distance (NM auxiliary tag). One big caveat to this is that ...
4
votes
What is the difference between FASTA, FASTQ, and SAM file formats?
FASTA and FASTQ formats are both file formats that contain sequencing reads while SAM files are these reads aligned to a reference sequence. In other words, FASTA and FASTQ are the "raw data"...
4
votes
Accepted
How can I easily get the read size distribution of reads mapping on a certain set of regions?
This can be done rather simply by combining this samtools based answer and bioawk:
...
3
votes
Is there a way to retrieve several SAM fields faster than `samtools view | cut -f`?
Another library you can use for this purpose is the htsjdk, which is written in java. Using htsjdk with java is analogous to using htslib with C; the BAM format is already handled by the library and ...
3
votes
Number of reference sequences in a SAM file
There are multiple ways. Here are two:
samtools idxstats ‹bamfile›
samtools view -H ‹bamfile› | grep '^@SQ'
Both commands give ...
3
votes
True bam file encoding and viewing as text
Assuming you want to visualize the pileup of reads across the reference, you may want to look into ASCIIgenome, a command line visualization tool for sam/bam/cram files, similar in spirit as IGV, but ...
3
votes
True bam file encoding and viewing as text
The way to visualise BAM files as text in Linux is with tools like samtools.
If you want to see the raw binary information as slightly more human-readable, you can run ...
3
votes
Accepted
Interpreting 0x200 flag in bwa-mem alignments
bwa mem is using exactly the same meaning of the 0x200 flag as every other program, including picard. Don't blindly assume that that entry in the header file ...
3
votes
While opening a Bam file with the SeqAn library I get 'seqan::FileOpenError'
Remove the getAbsolutePath call — your path is already absolute. getAbsolutePath garbles it, as you can see in the error message....
3
votes
What are the de facto required fields in a SAM/BAM read group?
The read group identifier needs to be specified in both the header lines of the BAM/SAM file and the alignment line. No other fields are required, but note that because the additional information is ...
3
votes
How to merge sam files together with adding read groups
Not so elegant but working solution
I found a solution that satisfy several of my conditions, basically I just have to assign read groups to individual mapping files, which can be just added to ...
3
votes
True bam file encoding and viewing as text
bam file is a compressed sam file, comparable with zip or tar. They are binary, which means we (humans) cannot read them. So you need to unpack them (convert back to sam) to read it as a text file.
...
3
votes
Extract end position from CIGAR
The start position is the first correctly mapped base. One way to do it, is to use GenomicAlignments in R to read in the alignments.
For example the sam file looks like this:
...
3
votes
Accepted
Is there a sam flag for all&none of the reads?
Instead of doing this kind of tweaking I would write my script in a way that these options are passed as strings that can be empty. Something like:
...
2
votes
Convert local alignments to spliced alignments in SAM file
Just use minimap2 in split alignment mode to realign the reads.
If that is not an option, then you could try using pysam to modify the CIGAR strings. I do not recommend this, as there are many ...
2
votes
Parsing SAM/BAM files for additional information
Other options... samtools stats maybe gives you some of the stats you are after. Chances are you already have samtools so nothing additional to install. Also useful may be pysamstats, in particular ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
sam × 40bam × 17
samtools × 15
file-formats × 6
alignment × 5
bwa × 3
c++ × 3
cigar × 3
fasta × 2
assembly × 2
read-mapping × 2
long-reads × 2
bed × 2
reads × 2
pysam × 2
htslib × 2
r × 1
sequence-alignment × 1
vcf × 1
genome × 1
snp × 1
database × 1
fastq × 1
reference-genome × 1
format-conversion × 1