Skip to content

Commit

Permalink
can now find pairs of given sequence IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben J. Woodcroft committed Apr 11, 2014
1 parent ec75eb3 commit bc4f22c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -50,3 +50,4 @@ pkg
# Ignore Gemfile.lock for gems. See http://yehudakatz.com/2010/12/16/clarifying-the-roles-of-the-gemspec-and-gemfile/
Gemfile.lock
*.gemspec
lib/bio-velvet_underground/external/libvelvet.so.1.0
18 changes: 18 additions & 0 deletions lib/bio-velvet_underground/velvet_underground.rb
Expand Up @@ -30,6 +30,21 @@ def [](sequence_id)
def length
@readset[:readCount]
end

def is_second_in_pair?(sequence_id)
if sequence_id==0 or sequence_id > @readset[:readCount]
raise "Invalid sequence_id #{sequence_id}"
end
Bio::Velvet::Underground.isSecondInPair @readset, sequence_id-1
end

def pair_id(sequence_id)
if is_second_in_pair?(sequence_id)
sequence_id-1
else
sequence_id+1
end
end
end

private
Expand Down Expand Up @@ -67,6 +82,9 @@ class ReadSet < FFI::Struct
# TightString *getTightStringInArray(TightString * tString,
# IDnum position);
attach_function :getTightStringInArray, [:pointer, :int32], :pointer

# boolean isSecondInPair(ReadSet * reads, IDnum index);
attach_function :isSecondInPair, [:pointer, :int32], :bool
end
end
end
12 changes: 12 additions & 0 deletions spec/binary_sequence_store_spec.rb
Expand Up @@ -24,4 +24,16 @@
seqs[78]
}.to raise_error
end

it 'should be able to understand mates' do
path = File.join TEST_DATA_DIR, '2', 'CnyUnifiedSeq'
seqs = Bio::Velvet::Underground::BinarySequenceStore.new path
seqs.is_second_in_pair?(1).should == false
seqs.is_second_in_pair?(2).should == true
seqs.is_second_in_pair?(5).should == false
seqs.pair_id(1).should == 2
seqs.pair_id(2).should == 1
seqs.pair_id(5).should == 6
seqs.pair_id(6).should == 5
end
end
Binary file added spec/data/2/CnyUnifiedSeq
Binary file not shown.

0 comments on commit bc4f22c

Please sign in to comment.