I am trying to access methods provided by htsjdk.jar from here: https://samtools.github.io/htsjdk/
and documented here: https://samtools.github.io/htsjdk/javadoc/htsjdk/index.html
using jython. I need methods for accessing / querying BAM file index (BAI file) to get start-end positions in binary BAM file. The test BAM & BAI files can be obtained i.e from: https://github.com/samtools/htsjdk/tree/master/testdata/htsjdk/samtools/BAMFileIndexTest
In jython 2.7.0 after putting in Jython registry:
python.security.respectJavaAccessibility = false
#I did in the jython comandline:
import sys
sys.path.append("/usr/local/soft/picard_1.138/htsjdk-1.138.jar")
from htsjdk.samtools import *
from java.io import File
#the BAM index file + BAM files
bai_fh = File("./index_test.bam.bai")
mydict = SAMSequenceDictionary()
bai_foo = DiskBasedBAMFileIndex(bai_fh, mydict)
I can access some methods, like bai_foo.getNumberOfReferences() etc., but the desired method
getBinsOverlapping(int referenceIndex, int startPos, int endPos) is in BrowseableBAMIndex interface.
But I am lost when it comes to subclassing Java classes in Jython. The task is to get the list of BAM file chunk(s) corresponding to a given genomic position. For the test BAM/BAI files, i.e. for chrM 10000-15000 (chromosome, start_pos, end_pos) I get 11 mapped reads using off the shelf samtools standalone program instead of htsjdk:
samtools view index_test.bam chrM:10000-15000
Many thanks for your help
Darek
Edit: re the groovy part Groovy Version: 2.4.4
groovy -cp libs/htsjdk-1.138.jar test_htsjdk.groovy
#!/usr/bin/env groovy
import htsjdk.samtools.*
File bam_fh = new File("./A.bam")
File bai_fh = new File("./A.bam.bai")
def mydict = new SAMSequenceDictionary()
def bai_foo = new DiskBasedBAMFileIndex(bai_fh, mydict)
println bai_foo.getNumberOfReferences()
Above code works in groovy. My problem is not that this code does not work, but that I do not know the proper way of accessing the methods from Java classes dealing with BAI file format. I did search for AbstractBAMFileIndex in htsjdk/src/java/htsjdk/samtools/*java files (git clone from repo@github), but it is still not clear what I need to do.