Hot answers tagged

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 ...
user avatar
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 ...
user avatar
  • 309
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 ...
user avatar
  • 19.3k
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, ...
user avatar
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 ...
user avatar
  • 5,645
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 ...
user avatar
  • 1,473
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 ...
user avatar
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 ...
user avatar
  • 744
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, ...
user avatar
  • 5,645
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 ...
user avatar
  • 11.5k
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 ...
user avatar
  • 443
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. ...
user avatar
  • 11.5k
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.
user avatar
  • 2,566
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 ...
user avatar
  • 19.3k
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 ...
user avatar
  • 19.3k
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"...
user avatar
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: ...
user avatar
  • 2,930
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 ...
user avatar
  • 714
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 ...
user avatar
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 ...
user avatar
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 ...
user avatar
  • 11.5k
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 ...
user avatar
  • 19.3k
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....
user avatar
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 ...
user avatar
  • 11.5k
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 ...
user avatar
  • 5,287
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. ...
user avatar
  • 3,531
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: ...
user avatar
  • 1,638
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: ...
user avatar
  • 2,706
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 ...
user avatar
  • 2,051
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 ...
user avatar
  • 659

Only top scored, non community-wiki answers of a minimum length are eligible