Class: Bioroebe::Alignment

Inherits:
CommandlineApplication show all
Defined in:
lib/bioroebe/sequence/alignment.rb

Overview

Bioroebe::Alignment

Constant Summary

Constants inherited from CommandlineApplication

CommandlineApplication::OLD_VERBOSE_VALUE

Constants included from ColoursForBase

ColoursForBase::ARRAY_HTML_COLOURS_IN_USE

Constants inherited from Base

Base::NAMESPACE

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from CommandlineApplication

#all_aminoacids?, #append_what_into, #at_home?, #be_silent, #be_verbose?, #cat, #ccliner, #change_directory, #cliner, #codon_table_dataset?, #codon_to_aminoacid, #codons_for?, #colourize_this_dna_sequence, #complement, #cp, #disable_warnings, #download_dir?, #editor?, #enable_warnings, #ensure_that_the_base_directories_exist, #esystem, #extract, #is_this_a_start_codon?, #is_this_a_stop_codon?, #leading_five_prime, #load_bioroebe_yaml_file, #log_directory?, #one_letter_to_long_name, #one_to_three, #only_numbers?, #open_in_browser, #opnerev, #opnn, #pad_with_double_quotes, #pad_with_single_quotes, #partner_nucleotide, #remove_numbers, #remove_trailing_ansii_escape_code, #return_all_possible_start_codons, #return_array_of_one_letter_aminoacids, #return_cheerful_person, #return_chunked_display, #return_ubiquitin_sequence, #runmode?, #set_be_verbose, #set_runmode, #start_codon?, #stop_codons?, #strict_filter_away_invalid_aminoacids, #taxonomy_download_directory?, #three_to_one, #to_rna, #trailing_three_prime, #use_opn?, #verbose_truth, #was_or_were, #without_extname, #write_what_into

Methods included from BaseModule

#absolute_path, #default_file_read, #file_readlines

Methods included from CommandlineArguments

#commandline_arguments?, #commandline_arguments_that_are_files?, #e, #first?, #first_non_hyphen_argument?, #remove_hyphens_from_the_commandline_arguments, #return_commandline_arguments_as_string, #return_commandline_arguments_that_are_not_files, #return_entries_without_two_leading_hyphens, #select_commandline_arguments, #select_entries_starting_with_two_hyphens, #set_commandline_arguments

Methods included from ColoursForBase

#colourize_this_aminoacid_sequence_for_the_commandline, #colourize_this_nucleotide_sequence, #disable_colours, #ecomment, #efancy, #egold, #enable_colours, #eorange, #eparse, #erev, #red, #remove_trailing_escape_part, #return_colour_for_nucleotides, #rev, #sdir, #set_will_we_use_colours, #sfancy, #sfile, #simp, #swarn, #use_colours?, #use_colours_within_the_bioroebe_namespace?

Methods inherited from Base

#append_what_into, #can_base_pair?, #convert_global_env, #delete_file, #directory_to_the_codon_tables?, #is_on_roebe?, #is_palindrome?, #main_encoding?, #mkdir, #move_file, #mv, #no_file_exists_at, #no_newlines, #project_yaml_directory?, #rds, #register_sigint, #return_pwd, #return_the_first_line_of_this_file, #word_wrap, #write_what_into

Methods included from InternalHashModule

#internal_hash?, #reset_the_internal_hash

Methods included from InferTheNamespaceModule

#infer_the_namespace, #namespace?

Constructor Details

#initialize(commandline_arguments = nil, run_already = true) ⇒ Alignment

#

initialize

#


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/bioroebe/sequence/alignment.rb', line 36

def initialize(
    commandline_arguments = nil,
    run_already           = true
  )
  reset
  set_commandline_arguments(
    commandline_arguments
  )
  case run_already
  # ======================================================================= #
  # === :do_not_run
  # ======================================================================= #
  when :do_not_run,
       :do_not_run_yet
    run_already = false
  end
  run if run_already
end

Class Method Details

.[](i = '') ⇒ Object

#

Bioroebe::Alignment[]

#


205
206
207
# File 'lib/bioroebe/sequence/alignment.rb', line 205

def self.[](i = '')
  new(i)
end

Instance Method Details

#consensus_sequence?Boolean

#

consensus_sequence?

#

Returns:

  • (Boolean)


153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/bioroebe/sequence/alignment.rb', line 153

def consensus_sequence?
  _ = ''.dup
  @array_G.size.times {|index|
    hash = {}
    hash['A'] = @array_A[index]
    hash['T'] = @array_T[index]
    hash['C'] = @array_C[index]
    hash['G'] = @array_G[index]
    max = hash.max_by {|key, value| value }
    _ << max.first
  }
  return _
end
#

print_consensus_sequence

#


125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/bioroebe/sequence/alignment.rb', line 125

def print_consensus_sequence
  e
  n_nucleotides = @array_G.size
  erev 'The consensus sequence ('+steelblue(n_nucleotides.to_s)+
       rev+' nucleotides), '\
       'derived from the above matrix, is:'
  e
  sequence_that_will_be_displayed = ''.dup
  @array_G.size.times {|index|
    hash = {}
    hash['A'] = @array_A[index]
    hash['T'] = @array_T[index]
    hash['C'] = @array_C[index]
    hash['G'] = @array_G[index]
    _ = hash.max_by {|key, value| value }
    sequence = _[0]
    sequence_that_will_be_displayed << sequence
  }
  ruler_result = Bioroebe.return_ruler(sequence_that_will_be_displayed)
  e '  '+ruler_result+rev
  print '  '+mediumslateblue(sequence_that_will_be_displayed)+rev # Print each individual character here.
  e Colours.rev
  e
end
#

print_row_for

#


170
171
172
173
174
175
176
177
178
# File 'lib/bioroebe/sequence/alignment.rb', line 170

def print_row_for(
    i     = 'A',
    array = @array_A
  )
  print "#{rev}  #{i}: " # First output the identifier, e. g. "A" or "T" and so forth.
  array.each {|entry| # entry is a Float.
    print steelblue(entry.round(1).to_s.ljust(4))
  }; e
end

#resetObject

#

reset (reset tag)

#


58
59
60
# File 'lib/bioroebe/sequence/alignment.rb', line 58

def reset
  super()
end

#runObject

#

run (run tag)

#


183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/bioroebe/sequence/alignment.rb', line 183

def run
  first = first?
  # ======================================================================= #
  # === If a file was given, read in that file next.
  # ======================================================================= #
  if first and File.exist?(first)
    dataset = file_readlines(first).map(&:strip)
    work_on_this_array(dataset)
  elsif first.nil? or first.empty?
    erev 'Using the __END__ dataset of '+sfile(__FILE__)+rev+'.'
    e
    work_on_this_array(
      DATA.read.split("\n")
    )
  else
    work_on_this_array(commandline_arguments?)
  end
end

#use_this_as_input(i) ⇒ Object

#

use_this_as_input

This method is assumed to split a String into an Array, before then passing this into work_on_this_array().

#


68
69
70
71
72
# File 'lib/bioroebe/sequence/alignment.rb', line 68

def use_this_as_input(i)
  work_on_this_array(
    i.split("\n")
  )
end

#work_on_this_array(i) ⇒ Object

#

work_on_this_array

#


77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/bioroebe/sequence/alignment.rb', line 77

def work_on_this_array(i)
  @array_A = []
  @array_T = []
  @array_C = []
  @array_G = []
  if i.respond_to? :first
    first = i.first
  else
    first = i
  end
  first.size.times {|index|
    hash = Hash.new(0)
    hash['A'] = 0
    hash['T'] = 0
    hash['C'] = 0
    hash['G'] = 0
    # ===================================================================== #
    # ["A", "C", "A", "A", "C", "C", "A", "G", "G", "G"]
    # ===================================================================== #
    vertical_row = i.map {|entry| entry[index] }
    vertical_row.each {|key| hash[key] += 1 }
    # ===================================================================== #
    # hash may be: { "A"=>4, "C"=>3, "G"=>3 }
    # ===================================================================== #
    hash.each_pair {|key, value|
      total_count = vertical_row.size
      case key
      when 'A'
        @array_A << (value.to_i) / total_count.to_f
      when 'T'
        @array_T << (value.to_i) / total_count.to_f
      when 'C'
        @array_C << (value.to_i) / total_count.to_f
      when 'G'
        @array_G << (value.to_i) / total_count.to_f
      end
    }
  }
  print_row_for('A', @array_A)
  print_row_for('T', @array_T)
  print_row_for('C', @array_C)
  print_row_for('G', @array_G)
  print_consensus_sequence
end