@q_total_ary = nil
@result = nil
@result_count = 0
+ @q_ids = []
+ @s_ids = []
end
# Method to load sequences from a query file in FASTA format
Fasta.open(file, 'r') do |ios|
ios.each do |entry|
+ @q_ids << entry.seq_name if @opt_hash[:query_ids]
+
oligos = str_to_oligo_rb_ary_c(entry.seq, @opt_hash[:kmer], 1).uniq.sort
q_total << oligos.size
Fasta.open(file, 'r') do |ios|
ios.each_with_index do |entry, s_index|
+ @s_ids << entry.seq_name if @opt_hash[:subject_ids]
+
zero_ary_c(oligo_ary, (4 ** @opt_hash[:kmer]) * BYTES_IN_INT)
zero_ary_c(shared_ary, @q_size * BYTES_IN_INT)
end
# Method that for each query index yields all hits, sorted according to
- # decending score, as a list of Score objects.
+ # decending score, as Hit objects.
def each
sort_hits_c(@result, @result_count)
hit_index = 0
(0 ... @q_size).each do |q_index|
- scores = []
zero_ary_c(hit_ary, HIT_ARY_MAX * BYTES_IN_HIT)
hit_ary_size = get_hits_c(@result, @result_count, hit_index, hit_ary, q_index)
- max = (hit_ary_size > @opt_hash[:report_scores]) ? @opt_hash[:report_scores] : hit_ary_size
+ if @opt_hash[:report_scores]
+ max = (hit_ary_size > @opt_hash[:report_scores]) ? @opt_hash[:report_scores] : hit_ary_size
+ else
+ max = hit_ary_size
+ end
(0 ... max).each do |i|
q_index, s_index, score = hit_ary[BYTES_IN_HIT * i ... BYTES_IN_HIT * i + BYTES_IN_HIT].unpack("IIF")
- scores << Score.new(score, s_index)
- end
+ q_id = @opt_hash[:query_ids] ? @q_ids[q_index] : q_index
+ s_id = @opt_hash[:subject_ids] ? @s_ids[s_index] : s_index
- yield scores
+ yield Hit.new(q_id, s_id, score)
+ end
hit_index += hit_ary_size
end
# Method that given a string (char array) encodes all kmers overlapping
# with a given step size as integers that are pushed onto a Ruby array
# which is returned.
+ # TODO should have an option for skipping oligos with ambiguity codes.
builder.c %{
VALUE str_to_oligo_rb_ary_c(
VALUE _str, // DNA or RNA string.
# >>>>>>>>>>>>>>> Embedded classes <<<<<<<<<<<<<<<
# Class for holding score information.
- class Score
- attr_reader :score, :s_index
-
- # Method to initialize Score object with
- # a subject sequence index and a score.
- def initialize(score, s_index)
- @s_index = s_index
- @score = score
+ class Hit
+ attr_reader :q_id, :s_id, :score
+
+ # Method to initialize Hit object with
+ # query and subject id a score.
+ def initialize(q_id, s_id, score)
+ @q_id = q_id
+ @s_id = s_id
+ @score = score
end
# Method for outputting score objects.
def to_s
- "#{@s_index}:#{@score.round(2)}"
+ "#{@q_id}:#{@s_id}:#{@score.round(2)}"
end
end
end