Class: Ms::Random::Fasta
- Inherits:
-
Tap::Task
- Object
- Tap::Task
- Ms::Random::Fasta
- Defined in:
- lib/ms/random/fasta.rb
Overview
:startdoc::task selects n random fasta entries
Selects random fasta entries from a fasta file. Entries are returned as an array, and by default as Ms::Fasta::Entry objects.
Instance Method Summary collapse
Instance Method Details
#process(fasta_file) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ms/random/fasta.rb', line 16 def process(fasta_file) entries = [] log :index, fasta_file unless File.exist?("#{fasta_file}.index") Ms::Fasta::Archive.open(fasta_file) do |archive| total_entries = archive.length log :select, "#{n} entries" # pick entries, filtering by sequence while entries.length < n entry = archive[rand(total_entries)] next if distinct && entries.find {|existing| existing.sequence == entry.sequence } entries << entry end end entries.collect! do |entry| entry.to_s end if fasta entries end |