fla
May 25, 2010, 3:52am
1
Hello,
I would like to use a Java library in JRuby. I have started to write a
little script, but I do not know how to continue it:
require ‘java’
require ‘/home/fla/jars/picard-tools/sam-1.21.jar’
net.sf.samtools.SAMFileReader
I would like to use this code (
)
in JRuby. How could I do it?
Thank you in advance.
Best regards
fla
May 25, 2010, 8:04am
2
On Mon, May 24, 2010 at 6:52 PM, Fla As [email protected] wrote:
Hello,
I would like to use a Java library in JRuby. I have started to write a
little script, but I do not know how to continue it:
require ‘java’
require ‘/home/fla/jars/picard-tools/sam-1.21.jar’
net.sf.samtools.SAMFileReader
I would use
require ‘java’
require ‘/home/fla/jars/picard-tools/sam-1.21.jar’
import Java::net.sf.samtools.SAMFileReader
instead.
I can’t help on the rest.
–
Enjoy global warming while it lasts.
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
fla
May 25, 2010, 11:34am
3
I’d recommend tinkering with it in (j)irb, so you can inspect your
objects as you do it. Something like:
$ jirb
require ‘java’
require ‘/home/fla/jars/picard-tools/sam-1.21.jar’
import Java::net.sf.samtools.SAMFileReader
input_sam = SAMFileReader.new(inputSamOrBamFile)
puts input_sam.methods.sort
That last line will show you what methods you’ve got on your reader.
You’ll probably find you can iterate over your SAMFileReader (it appears
to be iterable) object like so:
input_sam.each {|record| record.foo(bar) }
Cheers,
Nick
On Mon, 2010-05-24 at 23:03 -0700, Agile A. wrote:
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
fla
May 25, 2010, 1:45pm
4
Hi!
Did you want the code you linked to translated to JRuby? If so, here is
my suggestion:
class ExampleSamUsage
include_package ‘net.sf.samtools’
import java.io.File
def convertReadNamesToUpperCase(inputSamOrBamFile, outputSamOrBamFile)
inputSam = SAMFileReader.new(inputSamOrBamFile)
outputSam =
SAMFileWriterFactory.new.makeSAMOrBAMWriter(inputSam.file_header, true,
outputSamOrBamFile)
inputSam.each do |samRecord|
samRecord.read_name = samRecord.read_name.toUpperCase
outputSam.addAlignment(samRecord)
end
outputSam.close
inputSam.close
end
end
On May 25, 2010, at 3:52 AM, Fla As wrote:
picard download | SourceForge.net
)
in JRuby. How could I do it?
–
With kind regards
Uwe K.
Kubosch Consulting
[email protected]
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
fla
May 31, 2010, 9:27am
5
Thank you for the code, but unfortunately I get the following error:
test.rb:10:in `convertReadNamesToUpperCase’: no constructor with
arguments matching [class org.jruby.RubyString] on object
#Java::NetSfSamtools::SAMFileReader:0x0 (NameError)
from test.rb:33
with the following code:
require ‘java’
require ‘/home/fla/jars/picard-tools/sam-1.21.jar’
class ExampleSamUsage
include_package ‘net.sf.samtools’
import java.io.File
def convertReadNamesToUpperCase(inputSamOrBamFile, outputSamOrBamFile)
inputSam = SAMFileReader.new(inputSamOrBamFile)
outputSam =
SAMFileWriterFactory.new.makeSAMOrBAMWriter(inputSam.file_header,
true, outputSamOrBamFile.file_header)
inputSam.each do |samRecord|
puts samRecord.read_name
samRecord.read_name = samRecord.read_name.toUpperCase
puts read_name
outputSam.addAlignment(samRecord)
end
outputSam.close
inputSam.close
end
end
PATH = “/home/fla/Test_Data/”
inputSamOrBamFile = PATH + “a.sorted.bam”
outputSamOrBamFile = PATH + “a.sorted-JRUBY.bam”
test = ExampleSamUsage.new
test.convertReadNamesToUpperCase(inputSamOrBamFile, outputSamOrBamFile)
What did I wrong?
fla
June 1, 2010, 7:22am
6
Thank you, but unfortunately I get the following error:
HWI#0test.rb:16:in convertReadNamesToUpperCase': undefined method
toUpperCase’ for “HWI#0”:String (NoMethodError)
from
/home/fla/apps/jruby/lib/ruby/site_ruby/shared/builtin/java/java.lang.rb:12:in
each' from test.rb:14:in
convertReadNamesToUpperCase’
from test.rb:32
But the method should available because the Java code works.
This is the code
require ‘java’
require ‘/home/uqmlore1/jars/picard-tools/sam-1.21.jar’
class ExampleSamUsage
include_package ‘net.sf.samtools’
import java.io.File
def convertReadNamesToUpperCase(inputSamOrBamFile, outputSamOrBamFile)
inputSam = SAMFileReader.new(File.new(inputSamOrBamFile))
outputSam =
SAMFileWriterFactory.new.makeSAMOrBAMWriter(inputSam.file_header,
true, File.new(outputSamOrBamFile))
inputSam.each do |samRecord|
puts samRecord.read_name
samRecord.read_name = samRecord.read_name.toUpperCase()
outputSam.addAlignment(samRecord)
end
outputSam.close
inputSam.close
end
end
How to get toUpperCase running?
fla
June 1, 2010, 7:58pm
7
samRecord.read_name = samRecord.read_name.toUpperCase()
It’s string in Ruby.
Try
samRecord.read_name = samRecord.read_name.upcase
–
Enjoy global warming while it lasts.
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
fla
June 1, 2010, 1:08am
8
inputSam = SAMFileReader.new(inputSamOrBamFile)
You’re passing SAMFileReader class a string instead of a File object.
Try
inputSam = SAMFileReader.new(File.new(inputSamOrBamFile))
–
Enjoy global warming while it lasts.
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email