SEQanswers (
-   Bioinformatics (
-   -   Yes .. BBMap can do that! (

raquelnb 05-16-2019 12:58 PM

Hello Brian, it is just a question that pop up when using bbmap. For the outm, what type of flags do you use to both take pairs where both reads mappedand those where just one read of the pair mapped? Or how do you get read of both 77 and 141 flags?

Thank you and best

GenoMax 05-17-2019 04:03 AM

I think you are looking for the following options that are accessible from "".


Sam and bam processing options:

mappedonly=f            Toss unmapped reads.
unmappedonly=f          Toss mapped reads.
pairedonly=f            Toss reads that are not mapped as proper pairs.
unpairedonly=f          Toss reads that are mapped as proper pairs.
primaryonly=f          Toss secondary alignments.  Set this to true for sam to fastq conversion.
minmapq=-1              If non-negative, toss reads with mapq under this.
maxmapq=-1              If non-negative, toss reads with mapq over this.
requiredbits=0          (rbits) Toss sam lines with any of these flag bits unset.  Similar to samtools -f.
filterbits=0            (fbits) Toss sam lines with any of these flag bits set.  Similar to samtools -F.

bwubb 06-11-2019 04:01 AM


I have a seemingly simple problem, that Im sure bbmap can help with, but Im unclear what steps must be taken for success.

I have several bams from paired end sequencing where some number of mates have been removed. The remaining read still says it is paired so every tool seems to throw an error. Samtools or picard fixmate does not correct it, at best they yell the read names in question.

I am trying to use to remove those mates that remain, but I also seem to get a java exception, even when just trying to convert to fastq.


[bwubb@node107 disambres]$ -Xmx5g in=qsortA.bam out1=reads1.fq out2=reads2.fq ow
java -ea -Xmx5g -cp /home/bwubb/software/bbmap/current/ jgi.ReformatReads -Xmx5g in=qsortA.bam out1=reads1.fq out2=reads2.fq ow
Executing jgi.ReformatReads [-Xmx5g, in=qsortA.bam, out1=reads1.fq, out2=reads2.fq, ow]

Found samtools 1.9
Input is being processed as paired
Exception in thread "Thread-2" java.lang.AssertionError: K00315:202:H577WBBXY:7:1101:1438:38767 13      -1      -      57328513        57328662        1000000100000000011    1      0  60      TCCAGAAAGAGAGTTCTTGAAAGAAAGAGGCGCTATCATTTTGACACAGATGGNAAGGGCTCGATTCACGATCAAAAAGGCTCCAAAAANAAAAAAAATTCTGTTTGTTNTNCTTTTTCCTCCNGATTCTAGTTTTTTTNTTATNTTTTG  AAFFFFFAJJJJJ7FFFJJ7JJ7FJJJJJFFJJJJJFJJJJJF-A-AAFFJFA!AF---AAJJ-AJF<FF-AAFAF<AAAJJJJFA-7A!--77-<A<JJ<A--7A<FJ!J!<FJJJJA<FF7!)7AJF---7AFJJFJ!JF--!7-7<F      .      30      C68m28Nm53      .


        at stream.SamReadInputStream.toReadList(
        at stream.SamReadInputStream.fillBuffer(
        at stream.SamReadInputStream.hasMore(
        at stream.ConcurrentGenericReadInputStream$ReadThread.readLists(
        at stream.ConcurrentGenericReadInputStream$

I thought I could make read1.fq reads2.fq and use Clearly it finds the two problem reads. I have tried other arguments with the, and a few other tools, but none want to correct the MATE_NOT_FOUND problem. It would seem impossible that I am the first person to run into this issue. Thank you very much for any advice/help.


EDIT: Sorry if this post shows up multiple times. I literally tried making it three times and nothing showed up for a full day. Tried a quick reply and it showed up immediately.

GenoMax 06-12-2019 07:05 AM

@bwbubb: Option for that you are looking for is "pairedonly=f Toss reads that are not mapped as proper pairs". Set pairedonly=t and process your BAM files.

bwubb 06-13-2019 07:33 AM


Originally Posted by GenoMax (Post 226803)
@bwbubb: Option for that you are looking for is "pairedonly=f Toss reads that are not mapped as proper pairs". Set pairedonly=t and process your BAM files.


Thank you @GenoMax. This actually does not work for for this case.


[bwubb@node061 disambres]$ pairedonly=t in=input.bam out=fix.bam
java -ea -Xmx200m -cp /home/bwubb/software/bbmap/current/ jgi.ReformatReads pairedonly=t in=input.bam out=fix.bam
Executing jgi.ReformatReads [pairedonly=t, in=input.bam, out=fix.bam]

Found samtools 1.9
Input is being processed as unpaired
Input:                          13726088 reads                  2041390865 bases
Output:                        12583399 reads (91.68%)        1880228501 bases (92.11%)

Time:                          349.142 seconds.
Reads Processed:      13726k    39.31k reads/sec
Bases Processed:      2041m    5.85m bases/sec

[bwubb@node061 disambres]$ samtools index fix.bam
[bwubb@node061 disambres]$ java -jar ~/software/picard/2.20.2/picard.jar ValidateSamFile I=fix.bam MODE=SUMMARY
INFO    2019-06-13 08:00:16    ValidateSamFile


## HISTOGRAM    java.lang.String
Error Type      Count

[Thu Jun 13 08:02:01 EDT 2019] picard.sam.ValidateSamFile done. Elapsed time: 1.74 minutes.
To get help, see

Not sure how things work internally, but from my understanding the "problem" reads think they are paired.

I toiled with this more yesterday and I believe I can use to make an interleaved fastq file, and then use to make read1.fq and read2.fq and take it back to alignment. All attempts at correcting the bam directly seem to fail. I have yet to have total success, which in my case would be passing picardtools ValidateSamFile.

I am aligning with bwa mem -M, having some other issue in the validation that maybe is unrelated or will be fixed with the right reformat/repair arguments.

GenoMax 06-13-2019 08:16 AM

Have you tried adding "VALIDATION_STRINGENCY=LENIENT" to your picard command? Default value is STRICT and sometime it leads to picard throwing errors like this.

It does looks like took out some of the reads so the problem reads have been hopefully addressed.

bwubb 06-13-2019 09:50 AM


Originally Posted by GenoMax (Post 226828)
Have you tried adding "VALIDATION_STRINGENCY=LENIENT" to your picard command? Default value is STRICT and sometime it leads to picard throwing errors like this.

Yes indeed, but it will still be an ERROR.

However, after more tinkering I was able to come up with a combination that worked.

Code: -Xmx5g in=qSortA.bam out=qSortA_reads.fq -Xmx5g int=t addcolon=t uniquenames=t in=qSortA_reads.fq out=out_reads.fq -Xmx5g in=out_reads.fq out1=reads1.fq out2=reads2.fq

Taking those reads into alignment and so forth will pass ValidateSamFile. Im guessing these actions are allowing me to completely rewrite the pairing status, which I am perfectly ok with.

Thank you for the comments and help!

noobie 06-26-2019 05:02 AM

I want to subsample 10 million reads from both an interleaved reads file and a singletons reads file at the same time. Can do this?

GenoMax 06-26-2019 06:32 AM

@Noobie: I don't think so. You will have to do them independently. What is the use case here, if I may ask?

bartn 07-08-2019 11:02 PM

I want to created a (small) RNAseq test set from a small bacterial plasmid. So I used :
Code: reads=30000 paired=t metagenome=t  ref=transcripts.fasta out1=test_RNA_1.fq out2=test_RNA_2.fq
(Then I get 30k reads for each pair. No problem, I guess that's because the default is single end)

Then I mapped back the reads with BBmap
Code: ref=Rhizobium_Leguminosarum_plasmid_NZ_CP025014.1_transcripts.fasta  in1=Unlock_test_RNA_1.fq in2=Unlock_test_RNA_2.fq covstats=RNA.cov

Reads:                                      60000
Mapped reads:                                54225
Mapped bases:                                8063372
Ref scaffolds:                              562
Ref bases:                                  521537

Percent mapped:                              90.375
Percent proper pairs:                        64.822
Average coverage:                            15.461
Standard deviation:                            51.768
Percent scaffolds with any coverage:        59.96
Percent of reference bases covered:          45.87

The mapping percentages seem very low to me. Mapping to the genome gives similar results.
I am using in the wrong way for this?

GenoMax 07-09-2019 03:25 AM

Since you asked for 30K reads you got 30K paired-end reads.

I would sugegst trying without the metagenome=t option for a single small input fasta. If you do have the entire genome then use that in your randomread generation step along with the plasmid.

bartn 07-09-2019 07:31 AM


Originally Posted by GenoMax (Post 227250)
Since you asked for 30K reads you got 30K paired-end reads.

I would sugegst trying without the metagenome=t option for a single small input fasta. If you do have the entire genome then use that in your randomread generation step along with the plasmid.

Yes, that does seem to increase the mapping percentages. Any idea why it is not working with meta option? Changes read length and insert size does not seem to do much..
The plasmid is about 0.5MB with 562 transcripts. Median transcript size is 830bp, so that could be a bit short, (but then I would expect the same with the meta option off)

I will also look for another suitable (small) genome. I don't want to add the complete genome because it should finish quick, since it's for testing purposes of tools and pipelines.

(btw, one other small thing. Adding any statistic file in the arguments will give the small summary in the stdout (like I posted before). Otherwise it will not be printed. Not sure if that is expected behavior)

GenoMax 07-09-2019 09:52 AM

Metagenome option is supposed to take in multiple (genome) sequences to generate an artificial metagenomic dataset.

BBMap writes stats to STDERR by default. So you can capture that.

bartn 07-09-2019 11:13 PM

From the description of the option I understood it can be used for RNA as well:

metagenome=f Assign scaffolds a random exponential coverage level, to simulate a metagenomic or RNA coverage distribution

Which makes sense in my view since I just give multiple transcripts instead of genomes (albeit short compared to a genome)

So why are so many reads not mapping back even thought almost all of it with an even distributed coverage does map.

What I meant with the summary part, if I run just bbmap in its simplest form:
Code: ref=transcripts.fasta  in1=read_1.fq  in2=read_2.fq
the stderr does not contain this part:

Reads:                                      120000
Mapped reads:                                111248
Mapped bases:                                8357095
Ref scaffolds:                              1
Ref bases:                                  592529

Percent mapped:                              92.707
Percent proper pairs:                        56.370
Average coverage:                            14.104
Standard deviation:                            46.411
Percent scaffolds with any coverage:        100.00
Percent of reference bases covered:          41.67

But it does with adding a covstats=cov.stats for example.

GenoMax 07-10-2019 03:40 AM

Unfortunately Brian would be the only person who can provide an authoritative answer and he no longer participates on this forum. You may want to try emailing him with your question directly.

BBMap provides a wide range of coverage/histogram/stats outputs. Default output (while voluminous does not contain coverage stats) but mainly contains % alignments which most users want to see by default. In-line help (run without any options/inputs) details different options available for coverage/histogram/stats outputs.

bartn 07-10-2019 05:09 AM

That's indeed unfortunate. I might try sending an email. A previous bug report was solved very quickly!

One of the reasons I like about BBMap is indeed the wide range of statistics it can generate. Just noticed that final summary percentages like I showed, are to me the most useful thing to look at on first check was missing by default.

And thanks a lot for your answers and your time GenoMax! :)

Illusive Man 08-05-2019 09:42 AM

Dear BBMap users or Brian,

I have a database of about 800 proteins and all I would like to do is create an abundance table of "hits" to these 800 proteins for each one of my 30 samples. Samples as columns, genes as rows, cells as counts. Can BBMap help me create this abundance table?


GenoMax 08-05-2019 10:28 AM

BBMap is not designed to work with protein data. You will have to find a different tool.

Take a look at blat from UCSC's Jim Kent. That should produce the stats in parse-able tab-delimited columner format. You will need to do post-processing to get the table you are looking for.

bartn 08-05-2019 11:07 PM

another program that is often used for these cases is DIAMOND

But like GenoMax said you have to do some post processing of the output to get to the format you want..

darthsequencer 08-21-2019 03:43 PM

Is there a command to output the kmers of each sequence in a multifasta file?

All times are GMT -8. The time now is 02:26 AM.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2019, vBulletin Solutions, Inc.