1
$\begingroup$

I have 10 .sam files after my bowtie2 alignment on ten single-pair sequences. I would like to build a graph based on that output data, however I don't see any other solution but just writing the alignment percentage manually after each iteration.

Is there a tool that can help me to build a .csv file so I can manipulate the output data more easily?

$\endgroup$
1
  • 1
    $\begingroup$ You should never have SAM files: they’re not useful, not even as intermediate files! You should always directly generate BAM files. They’re smaller, more efficient, and allow more features (e.g. indexing for even faster access and statistics). For example, you would usually call bowtie2 as follows: bowtie2 ‹args› | samtools sort --output-fmt-option level=0 | samtools view -b -o sorted.bam (this immediately sorts the BAM file, which requires a lot of RAM; if this isn’t suitable for you, omit the intermediate step; but you normally want to have sorted BAMs). $\endgroup$ Jan 30 at 12:49
2
$\begingroup$

Use samtools flagstat with option -O tsv:

Using -O tsv selects a tab-separated values format that can easily be imported into spreadsheet software. In this format the first column contains the values for QC-passed reads, the second column has the values for QC-failed reads and the third contains the category names.

SEE ALSO:
What Does Samtools Flagstat Results Mean?

INSTALLATION:
Some old versions of samtools do not have option -O tsv. To install a recent versions of samtools, use either:

conda (macOS, Linux) (but see also: Tutorial: installing samtools with conda - overcoming two common errors):

conda create --name samtools samtools

or brew (macOS):

brew install samtools
$\endgroup$
9
  • 1
    $\begingroup$ Thank you, it worked however just in a "default" combination, e.g. samtools flagstat input.sam If I try samtools flagstat -O tsv input.sam, it throws me an error invalid option -- 'O' $\endgroup$ Jan 26 at 20:26
  • $\begingroup$ @DmitriiTrubetskoy See updated answer. $\endgroup$ Jan 26 at 20:53
  • 1
    $\begingroup$ thanks, however my ``` samtools is already the newest version (1.7-1).``` (info from terminal). Just to be sure, the right syntax will be: samtools flagstat -O tsv input.sam ? $\endgroup$ Jan 26 at 21:16
  • $\begingroup$ @DmitriiTrubetskoy Exactly, and note that 1.7* is older than 1.11, which is the most recent version available through both conda and brew (see links in my answer). I also confirmed that this option is present in samtools 1.10 that I installed via brew. So try updating/installing the new samtools version if you really need this option. $\endgroup$ Jan 26 at 21:22
  • 1
    $\begingroup$ Great, now everything's ok. Much appreciated the tips and for being patient. $\endgroup$ Jan 28 at 16:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.