Skip to content

Instantly share code, notes, and snippets.

@ngoto
Created September 14, 2017 05:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ngoto/50fd9216686d9f98f3adb25c7b325122 to your computer and use it in GitHub Desktop.
Save ngoto/50fd9216686d9f98f3adb25c7b325122 to your computer and use it in GitHub Desktop.
pycall.rb 1.0.1 example to call Biopython SeqIO
#!/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