Module: Qu::Utils
- Defined in:
- lib/qu/utils.rb,
lib/qu/utils/version.rb
Constant Summary collapse
- IUPAC =
{ A: ['A'], T: ['T'], C: ['C'], G: ['G'], R: ['G', 'A'], Y: ['T', 'C'], S: ['G', 'C'], W: ['T', 'A'], K: ['G', 'T'], M: ['A', 'C'], D: ['G', 'T', 'A'], H: ['T', 'A', 'C'], B: ['G', 'T', 'C'], V: ['G', 'A', 'C'], N: ['G', 'A', 'T', 'C'], I: ['G', 'A', 'T', 'C'], }
- VERSION =
"1.0.3"
Class Method Summary collapse
- .convert_degenerate_primer(primer_file) ⇒ Object
- .iupac2normal(seq, prefixes = ['']) ⇒ Object
- .long_seq_wrap(word, length = 80, separator = "\n") ⇒ Object
- .platform_bit ⇒ Object
- .platform_os ⇒ Object
- .plural_word(word, count) ⇒ Object
- .seconds_to_units(seconds) ⇒ Object
-
.word_wrap(text, line_width = 80) ⇒ Object
File actionpack/lib/action_view/helpers/text_helper.rb, line 215.
Class Method Details
.convert_degenerate_primer(primer_file) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# 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 = ['']) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# 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") ⇒ Object
74 75 76 77 78 79 |
# 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 ⇒ Object
112 113 114 |
# File 'lib/qu/utils.rb', line 112 def platform_bit OS.bits end |
.platform_os ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 |
# 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) ⇒ Object
96 97 98 |
# File 'lib/qu/utils.rb', line 96 def plural_word(word, count) count > 1 ? word + 's' : word end |
.seconds_to_units(seconds) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# 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) ⇒ Object
File actionpack/lib/action_view/helpers/text_helper.rb, line 215
68 69 70 71 72 |
# 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 |