Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options questions only not deleted user 1770

Questions specific to interacting with and post-processing sequence alignments using the SAMtools package. For questions specifically about formats SAM, BAM or CRAM use tags sam or bam,

3 votes
1 answer
509 views

What is the standard way to measure contig sequence lengths in a BAM?

My understanding is that the community would use samtools idxstats to compute this information from the corresponding index file. Are there more precise/standard approaches? …
EB2127's user avatar
  • 1,423
2 votes
1 answer
1k views

Modifying a SAM header after removing all non-primary reads

I subset a BAM to only include primary reads using the following samtools commands: samtools view -F 256 input.bam > input.primaryOnly.sam Now, in order to convert this SAM into a new subsetted BAM, … view -H input.bam > input.header.sam Then I could convert the SAM into a BAM with samtools view -S -b i new.sam > new.bam My problem is, I'm using the original BAM header. …
EB2127's user avatar
  • 1,423
6 votes
5 answers
4k views

Subset smaller BAM to contain several thousand rows from multiple chromosomes

Normally I do the following, which will subset the BAM file.bam and keep the header samtools view -H file.bam > header.sam samtools view file.bam | head -n 5000 | cat header.sam - | samtools view -Sb … samtools view file.bam | grep "chr1" | cat header.sam - | samtools view -Sb - > file.unique.bam but then I have two problems: (1) I may not be grepping the alignments to chromsome 2---there may exist …
EB2127's user avatar
  • 1,423
8 votes
7 answers
13k views

How to subset a BAM by a list of QNAMEs?

Naturally, I can do this individually, e.g. samtools view file.bam | grep 'EXAMPLE:QNAME1' > subset.bam But I'm unsure how to do this for a list of QNAMES: How do I write a for loop that will do all …
EB2127's user avatar
  • 1,423
2 votes
1 answer
153 views

SAM format: Does the BAM "Integer or numeric array" field no longer exist? Why?

+ Integer or numeric array However, looking at the samtools source code, I noticed this: https://github.com/samtools/samtools/blob/develop/sam_view.c#L920-L931 switch (aux_type) { case 'H': … Was this the case with previous versions of samtools? …
EB2127's user avatar
  • 1,423
7 votes
2 answers
704 views

How does htslib/samtools access optional BAM fields?

My questions: How does htslib/samtools (e.g. samtools view) access these optional fields, which differ in number from BAM to BAM (possible row to row)? … When a user runs htslib or even samtools view, how does the BAM row "end", i.e. what data structure exists to show that the BAM row has no more optional fields, and that the algorithm should "move on" …
EB2127's user avatar
  • 1,423
5 votes
3 answers
566 views

Is there an efficient way to check an input BAM in R?

Perhaps pipe to samtools (which doesn't feel very stable in terms of software)? …
EB2127's user avatar
  • 1,423
7 votes
1 answer
2k views

How to remove all BAM read groups from all reads (not just the header)?

Normally when I have such a problem, I remove all the read groups from the BAM header as follows: samtools view -H your.bam | grep -v "^@RG" | samtools reheader - original.bam > new.bam and then I would …
EB2127's user avatar
  • 1,423