Java 使用jython或groovy中的htsjdk定义的类

Java 使用jython或groovy中的htsjdk定义的类,java,groovy,jython,samtools,Java,Groovy,Jython,Samtools,我试图从这里访问htsjdk.jar提供的方法: 并记录于此: 使用jython。我需要访问/查询BAM文件索引(BAI文件)的方法,以获取二进制BAM文件中的开始-结束位置。测试BAM和BAI文件可从以下位置获得: 在jython 2.7.0中,在放入jython注册表后: python.security.respectJavaAccessibility = false #I did in the jython comandline: import sys sys.path.append

我试图从这里访问htsjdk.jar提供的方法:

并记录于此:

使用jython。我需要访问/查询BAM文件索引(BAI文件)的方法,以获取二进制BAM文件中的开始-结束位置。测试BAM和BAI文件可从以下位置获得:

在jython 2.7.0中,在放入jython注册表后:

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)
我可以访问一些方法,如bai_foo.getNumberOfReferences()等,但所需的方法是
getBinsOverlapping(int referenceIndex、int startPos、int endPos)位于BrowseableBAMIndex接口中

但当涉及到在Jython中对Java类进行子类化时,我就不知所措了。任务是获取与给定基因组位置对应的BAM文件块列表。用于测试BAM/BAI文件,即 chrM 10000-15000(染色体、开始位置、结束位置)我使用现成的samtools独立程序而不是htsjdk获得11个映射读取:

samtools view index_test.bam  chrM:10000-15000
非常感谢你的帮助

达瑞克

编辑:重新编辑groovy部分 Groovy版本: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()

上述代码在groovy中工作。我的问题不是这段代码不起作用,而是我不知道从处理BAI文件格式的Java类访问方法的正确方法。我确实在htsjdk/src/java/htsjdk/samtools/*java文件中搜索了AbstractBAMFileIndex(git克隆自repo@github),但仍不清楚我需要做什么

他们的SamReader上有一个例子,我附上了一小部分,但还有更多的例子说明如何使用他们的SamReader

    /**
     * Broken down
     */
    final SamReaderFactory factory =
            SamReaderFactory.makeDefault().enable(SamReaderFactory.Option.VALIDATE_CRC_CHECKSUMS).validationStringency(ValidationStringency.LENIENT);

    final SamInputResource resource = SamInputResource.of(new File("/my.bam")).index(new URL("http://broadinstitute.org/my.bam.bai"));

    final SamReader myReader = factory.open(resource);

    for (final SAMRecord samRecord : myReader) {
        System.err.print(samRecord);
    }

Groovy在与一堆文件进行交互方面非常出色,无论文件的格式如何

new File('my/directory/with/many/files').eachFile{File readFile ->
    final SamInputResource resource = SamInputResource.of(readFile).index(new URL('IGotLazy.bai'))
    final SamReader myReader = ... etc

}

我不知道该把什么作为参考索引,但打印出来的数据对我来说已经足够好了,因为我从来没有处理过此类数据:

import sys
sys.path.append("/home/shackle/sam-tools/samtools-htsjdk-f650176/dist/htsjdk-1.138.jar")
from htsjdk.samtools import *
from java.io import File
#the BAM index file + BAM files 
indexFile = File("/home/shackle/index_test.bam.bai")
bamFile = File("/home/shackle/index_test.bam")
sfr = SAMFileReader(bamFile, indexFile)
sfr.enableIndexCaching(True)
bbi = sfr.getBrowseableIndex()
for i in range(0,256):
    print "i = " , i
    bl = bbi.getBinsOverlapping(i, 10000, 15000)
    count = 0
    for bin in bl:
        print "bin.getBinNumber() = " , bin.getBinNumber()
        count = count + 1
        print "count = ", count

这和groovy有什么关系?除了你把groovy放在title@tim_yates:很抱歉给你带来了困惑。我假设该解决方案较少地依赖于使用jython vs groovy,而更多地依赖于找到一种方法来实例化一个htsjdk.samtools Java类。虽然我来自python,但如果我能让它在python或groovy中工作,我会很高兴。或者Jruby,如果这将是有足够耐心了解htsjdk.samtools相关部分的人的第一选择。“chrM”对应的GetBins的int引用索引是什么?我将直接使用groovy,因为您可以使用示例复制和粘贴java,而无需修改代码。