bamtools filtering syntax - reads containing more than X mismatches and soft-clipped reads
Entering edit mode
2.3 years ago
joelepaul • 0

Hi @ll!

I'm extremely new to the field of bioinformatics, though I have some programming knowledge. A lot of tools have quite nice manuals out there, which helps me learning about how to use them properly. However, when it came to bamtools, I have been stuck.

My aims are twofold - starting from nice *.bam datasets

1) to remove reads containing more than 4 mismatches. However, I can only find the syntax to filter reads that contain 0 mismatches.

bamtools filter -tag XM:0 -in reads.bam -out reads.noMismatch.bam

However, I cannot find any documentation about the syntax of the BWA-specific flags such as XM, so I do not know how to adapt this code correctly to include a "more than" function.

2) to remove soft-clipped reads. My supervisor told me to use bamtools for that, but all guides like these Remove Soft Clipped Bases refer to other software/scripts. The bamtools manuals also do not say anything about how to do that. Does anyone know how to use specifically bamtools for that purpose?

Thank you for your time!

Cheers Joe

bwa bamtools • 1.1k views
Entering edit mode
2.3 years ago

not bamstools, using samjdk

java -jar dist/samjdk.jar -e 'Integer xm = record.getIntegerAttribute("XM"); if(xm!=null && xm > 4) return false; return record.getCigar()==null   || !record.getCigar().isClipped();' input.bam
Entering edit mode

hello Pierre, I tried to install jvarkit, but got errors like below, could you please help me? Thanks!

$ git clone ""
$ cd ~/jvarkit/
~/jvarkit$ ~/jvarkit/gradlew samjdk

FAILURE: Build failed with an exception.

* Where:
Settings file '/home/hyjforesight/jvarkit/settings.gradle'

* What went wrong:
Could not compile settings file '/home/hyjforesight/jvarkit/settings.gradle'.
> startup failed:
  General error during semantic analysis: Unsupported class file major version 61

  java.lang.IllegalArgumentException: Unsupported class file major version 61
        at groovyjarjarasm.asm.ClassReader.<init>(
        at groovyjarjarasm.asm.ClassReader.<init>(
        at groovyjarjarasm.asm.ClassReader.<init>(
        at groovyjarjarasm.asm.ClassReader.<init>(
        at org.codehaus.groovy.ast.decompiled.AsmDecompiler.parseClass(
        at org.codehaus.groovy.control.ClassNodeResolver.findDecompiled(
        at org.codehaus.groovy.control.ClassNodeResolver.tryAsLoaderClassOrScript(
        at org.codehaus.groovy.control.ClassNodeResolver.findClassNode(
        at org.codehaus.groovy.control.ClassNodeResolver.resolveName(
        at org.codehaus.groovy.ast.decompiled.AsmReferenceResolver.resolveClassNullable(
        at org.codehaus.groovy.ast.decompiled.AsmReferenceResolver.resolveClass(
        at org.codehaus.groovy.ast.decompiled.AsmReferenceResolver.resolveNonArrayType(
        at org.codehaus.groovy.ast.decompiled.AsmReferenceResolver.resolveType(
        at org.codehaus.groovy.ast.decompiled.MemberSignatureParser.createMethodNode(
        at org.codehaus.groovy.ast.decompiled.DecompiledClassNode$2.get(
        at org.codehaus.groovy.ast.decompiled.DecompiledClassNode$2.get(
        at org.codehaus.groovy.ast.decompiled.DecompiledClassNode.createMethodNode(
        at org.codehaus.groovy.ast.decompiled.DecompiledClassNode.lazyInitMembers(
        at org.codehaus.groovy.ast.decompiled.DecompiledClassNode.getDeclaredMethods(

  1 error

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at
Entering edit mode

your default java is version 60 and refers to Java 16, as specified in the manual, you need to use the 'old' java jdk 8 or a jdk 11 . (= set your PATH )


Login before adding your answer.

Traffic: 839 users visited in the last hour
Help About
Access RSS

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6