Created
September 14, 2017 05:43
-
-
Save ngoto/50fd9216686d9f98f3adb25c7b325122 to your computer and use it in GitHub Desktop.
pycall.rb 1.0.1 example to call Biopython SeqIO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# coding: utf-8 | |
# | |
# Test data must be downloaded via: | |
# $ wget http://togows.org/entry/ncbi-nucleotide/J00231.fasta | |
# | |
# References: http://qiita.com/sato32ha6/items/6b762b0d0314a5db7dc3 | |
require "pycall/import" | |
include PyCall::Import | |
pyfrom 'Bio', import: :SeqIO | |
module WrapGenerator | |
def each | |
iter = self.__iter__ | |
while true | |
begin | |
v = iter.__next__ | |
rescue PyCall::PyError | |
break | |
end | |
yield v | |
end | |
self | |
end | |
end | |
sio = SeqIO.parse("J00231.fasta", "fasta") | |
sio.extend(WrapGenerator) | |
sio.each do |record| | |
id = record.id | |
desc = record.description | |
seq = PyCall.builtins.str.(record.seq) | |
print 'id: <', id.class, '> ', id.inspect, "\n" | |
print 'description: <', desc.class, '> ', desc.inspect, "\n" | |
print 'seq: <', record.seq.inspect, '> ', seq.inspect, "\n" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment