module Qu::Utils
Constants
- IUPAC
- VERSION
Public Instance Methods
convert_degenerate_primer(primer_file)
click to toggle source
# File lib/qu/utils.rb, line 45 def convert_degenerate_primer(primer_file) primer_records = Bio::FlatFile.new(Bio::FastaFormat, File.open(primer_file)) primer_list = [] primer_records.each do |primer| if primer.naseq.to_s =~ /[^atcgATCG]+/ normal_seq_list = iupac2normal(primer.naseq.upcase) fasta_io = StringIO.new normal_seq_list.each_with_index do |normal_seq, index| fasta_io << ">#{primer.entry_name}_#{index+1} #{primer.description}\n#{normal_seq}\n" end fasta_io.rewind primer_list += Bio::FlatFile.new(Bio::FastaFormat, fasta_io).to_a fasta_io.close else primer_list << primer end end return primer_list end
iupac2normal(seq, prefixes = [''])
click to toggle source
# File lib/qu/utils.rb, line 28 def iupac2normal(seq, prefixes = ['']) return prefixes if seq.size == 0 first = seq[0].to_sym last_seq = seq[1..-1] new_prefixes = [] prefixes.each do |prefix| if IUPAC.include?(first) IUPAC[first].each {|base| new_prefixes << "#{prefix}#{base}"} else $stderr.puts "Error: unrecognized base: #{first}" exit end end return iupac2normal(last_seq, prefixes = new_prefixes) end
long_seq_wrap(word, length=80, separator="\n")
click to toggle source
# File lib/qu/utils.rb, line 74 def long_seq_wrap(word, length=80, separator="\n") # Wrap a long sentence with may words into multiple lines (word.length < length) ? word : word.scan(/.{1,#{length}}/).join(separator) end
platform_bit()
click to toggle source
# File lib/qu/utils.rb, line 112 def platform_bit OS.bits end
platform_os()
click to toggle source
# File lib/qu/utils.rb, line 100 def platform_os if OS.windows? return 'windows' elsif OS.mac? return 'mac' elsif OS.linux? return 'linux' else return 'unknown' end end
plural_word(word, count)
click to toggle source
# File lib/qu/utils.rb, line 96 def plural_word(word, count) count > 1 ? word + 's' : word end
seconds_to_units(seconds)
click to toggle source
# File lib/qu/utils.rb, line 81 def seconds_to_units(seconds) return "#{seconds.round(2)} second" if seconds < 1 return "#{seconds.round(2)} seconds" if seconds < 60 '%d minutes, %d seconds' % #'%d days, %d hours, %d minutes, %d seconds' % # the .reverse lets us put the larger units first for readability #[24,60,60].reverse.inject([seconds]) {|result, unitsize| [60].reverse.inject([seconds]) {|result, unitsize| result[0,0] = result.shift.divmod(unitsize) result } end
word_wrap(text, line_width = 80)
click to toggle source
File actionpack/lib/action_view/helpers/text_helper.rb, line 215
# File lib/qu/utils.rb, line 68 def word_wrap(text, line_width = 80) text.split("\n").collect do |line| line.length > line_width ? line.gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1\n").strip : line end * "\n" end