Skip to content

Commit

Permalink
Complete rename.
Browse files Browse the repository at this point in the history
  • Loading branch information
gusevfe committed Jul 15, 2014
1 parent f56fc2c commit 65df0e0
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 23 deletions.
28 changes: 28 additions & 0 deletions bio-kseq.gemspec
@@ -0,0 +1,28 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'bio/kseq/version'

Gem::Specification.new do |spec|
spec.name = "bio-kseq"
spec.version = Bio::Kseq::VERSION
spec.authors = ["Gusev Fedor"]
spec.email = ["gusevfe@gmail.com"]
spec.summary = %q{Ruby inferface for Heng Li kseq.h}
spec.description = %q{A fast FASTA/FASTQ parser based on kseq.h by Heng Li}
spec.homepage = ""
spec.license = "MIT"

spec.files = `git ls-files -z`.split("\x0")
spec.files << "ext/seqtk_bindings/seqtk/kseq.h"
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib", "ext"]
spec.extensions = Dir['ext/**/extconf.rb']
spec.platform = Gem::Platform::RUBY

spec.add_development_dependency "bundler", "~> 1.5"
spec.add_development_dependency "rake"
spec.add_development_dependency "rspec"
spec.add_development_dependency "rake-compiler"
end
13 changes: 1 addition & 12 deletions ext/seqtk_bindings/seqtk_bindings.c
Expand Up @@ -14,7 +14,6 @@ static void kseq_wrapper_deallocate(void *seq);
static VALUE kseq_wrapper_read(VALUE self);

VALUE mBio;
VALUE mSeqtk;
VALUE cKseq;

typedef struct {
Expand All @@ -23,15 +22,6 @@ typedef struct {
gzFile fp;
} Kseq_Wrapper;

FILE *rb_io_stdio_file(rb_io_t *fptr)
{
if (!fptr->stdio_file) {
int oflags = rb_io_fmode_oflags(fptr->mode);
fptr->stdio_file = rb_fdopen(fptr->fd, rb_io_oflags_modestr(oflags));
}
return fptr->stdio_file;
}

#define kseq_wrapper_field(NAME) \
static VALUE kseq_wrapper_ ## NAME(VALUE self) { \
Kseq_Wrapper *w; \
Expand All @@ -49,8 +39,7 @@ kseq_wrapper_field(qual);

void Init_seqtk_bindings() {
mBio = rb_define_module("Bio");
mSeqtk = rb_define_module_under(mBio, "SeqTK");
cKseq = rb_define_class_under(mSeqtk, "Kseq", rb_cObject);
cKseq = rb_define_class_under(mBio, "Kseq", rb_cObject);
rb_define_alloc_func(cKseq, kseq_wrapper_allocate);
rb_define_method(cKseq, "initialize", kseq_wrapper_initialize, 1);

Expand Down
24 changes: 24 additions & 0 deletions lib/bio/kseq.rb
@@ -0,0 +1,24 @@
require "seqtk_bindings/seqtk_bindings"
require "bio/kseq/version"

module Bio
module SeqTK
class Kseq
def to_s
if qual.nil?
if comment.nil?
">" + name + "\n" + seq
else
">" + name + " " + comment + "\n" + seq
end
else
if comment.nil?
"@" + name + "\n" + seq + "\n+\n" + qual
else
"@" + name + " " + comment + "\n" + seq + "\n+\n" + qual
end
end
end
end
end
end
5 changes: 5 additions & 0 deletions lib/bio/kseq/version.rb
@@ -0,0 +1,5 @@
module Bio
class Kseq
VERSION = "0.0.1"
end
end
23 changes: 12 additions & 11 deletions spec/seqtk_spec.rb → spec/kseq_spec.rb
@@ -1,6 +1,7 @@
require 'bio/seqtk'
require 'bio/kseq'
require 'tempfile'
include Bio::SeqTK

include Bio

describe Kseq do
it 'should parse simple FASTA files' do
Expand All @@ -13,19 +14,19 @@

kseq = Kseq.new tmp.path

expect(kseq.read!).to be_true
expect(kseq.read!).to be_truthy
expect(kseq.name).to eq("A")
expect(kseq.comment).to be_nil
expect(kseq.seq).to eq("AAAATTTTCCCCGGGG")
expect(kseq.qual).to be_nil

expect(kseq.read!).to be_true
expect(kseq.read!).to be_truthy
expect(kseq.name).to eq("B")
expect(kseq.comment).to eq("comment")
expect(kseq.seq).to eq("GGGGTTTTCCCCAAAA")
expect(kseq.qual).to be_nil

expect(kseq.read!).to be_false
expect(kseq.read!).to be_falsey
end

it 'should parse simple FASTQ files' do
Expand All @@ -42,19 +43,19 @@

kseq = Kseq.new tmp.path

expect(kseq.read!).to be_true
expect(kseq.read!).to be_truthy
expect(kseq.name).to eq("A")
expect(kseq.comment).to be_nil
expect(kseq.seq).to eq("AAAATTTTCCCCGGGG")
expect(kseq.qual).to eq("AAAAAAAAAAAAAAAA")

expect(kseq.read!).to be_true
expect(kseq.read!).to be_truthy
expect(kseq.name).to eq("B")
expect(kseq.comment).to eq("comment")
expect(kseq.seq).to eq("GGGGTTTTCCCCAAAA")
expect(kseq.qual).to eq("IIIIIIIIIIIIIIII")

expect(kseq.read!).to be_false
expect(kseq.read!).to be_falsey
end

it 'should read from IO' do
Expand All @@ -69,18 +70,18 @@

kseq = Kseq.new io

expect(kseq.read!).to be_true
expect(kseq.read!).to be_truthy
expect(kseq.name).to eq("A")
expect(kseq.comment).to be_nil
expect(kseq.seq).to eq("AAAATTTTCCCCGGGG")
expect(kseq.qual).to be_nil

expect(kseq.read!).to be_true
expect(kseq.read!).to be_truthy
expect(kseq.name).to eq("B")
expect(kseq.comment).to eq("comment")
expect(kseq.seq).to eq("GGGGTTTTCCCCAAAA")
expect(kseq.qual).to be_nil

expect(kseq.read!).to be_false
expect(kseq.read!).to be_falsey
end
end

0 comments on commit 65df0e0

Please sign in to comment.