Class: Bioroebe::ShowOrf

Inherits:
CommandlineApplication show all
Defined in:
lib/bioroebe/utility_scripts/showorf/run.rb,
lib/bioroebe/utility_scripts/showorf/help.rb,
lib/bioroebe/utility_scripts/showorf/menu.rb,
lib/bioroebe/utility_scripts/showorf/show.rb,
lib/bioroebe/utility_scripts/showorf/reset.rb,
lib/bioroebe/utility_scripts/showorf/showorf.rb,
lib/bioroebe/utility_scripts/showorf/constants.rb,
lib/bioroebe/utility_scripts/showorf/initialize.rb

Overview

Bioroebe::ShowOrf

Constant Summary collapse

COLOURIZE_VERTICAL_TOKEN =
#

COLOURIZE_VERTICAL_TOKEN

#
true
LIMIT_AT_N_NUCLEOTIDES =
#

LIMIT_AT_N_NUCLEOTIDES

How many nucleotides we will display per given row.

This should not be a too high value, because it may otherwise overflow into the next line.

#
100
COLOURIZE_STOP_CODONS_IN_RED =
#

COLOURIZE_STOP_CODONS_IN_RED

If true then all '*' will become red.

#
true

Constants inherited from CommandlineApplication

CommandlineApplication::OLD_VERBOSE_VALUE

Constants included from ColoursForBase

ColoursForBase::ARRAY_HTML_COLOURS_IN_USE

Constants inherited from Base

Base::NAMESPACE

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, #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, #opne, #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, #set_be_verbose, #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 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_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?, #file_readlines, #infer_the_namespace, #is_on_roebe?, #is_palindrome?, #main_encoding?, #mkdir, #move_file, #mv, #namespace?, #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

Constructor Details

#initialize(i = ARGV, show_these_frames = [:frame1], run_already = true) ⇒ ShowOrf

#

initialize

The first argument to this method should be the DNA nucleotide string whose ORF you wish to show.

The second argument to this method determines which frames to show.

The class assumes that the first input given is an Array, such as ARGV in particular.

#

20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/bioroebe/utility_scripts/showorf/initialize.rb', line 20

def initialize(
    i                 = ARGV,     # The input should be an Array.
    show_these_frames = [:frame1],
    run_already       = true
  )
  reset
  # ======================================================================= #
  # First set up the default frames. This can be overruled lateron,
  # in particular upon the invocation of the method called
  # obtain_commandline_arguments_and_reject_double_separators.
  # ======================================================================= #
  set_show_these_frames(show_these_frames)
  # ======================================================================= #
  # Handle blocks Next.
  # ======================================================================= #
  if block_given?
    yielded = yield
    case yielded
    when :show_three_frames
      set_show_these_frames(:show_three_frames)
    else
      set_show_these_frames(yielded)
    end
  end
  # ======================================================================= #
  # Next, set the input sequence.
  # ======================================================================= #
  i = obtain_commandline_arguments_and_reject_double_separators(i)
  set_input_sequence(i)
  run if run_already
end

Instance Method Details

#colourize_stop_codons_in_red?Boolean

#

colourize_stop_codons_in_red?

#

Returns:

  • (Boolean)

298
299
300
# File 'lib/bioroebe/utility_scripts/showorf/showorf.rb', line 298

def colourize_stop_codons_in_red?
  COLOURIZE_STOP_CODONS_IN_RED
end

#complement(i) ⇒ Object

#

complement

#

469
470
471
# File 'lib/bioroebe/utility_scripts/showorf/showorf.rb', line 469

def complement(i)
  ::Bioroebe.complement(i)
end

#default_padding(optional_remove_last_character_n_times = false) ⇒ Object Also known as: pad

#

default_padding (padding tag, pad tag)

#

278
279
280
281
282
283
284
285
286
# File 'lib/bioroebe/utility_scripts/showorf/showorf.rb', line 278

def default_padding(
    optional_remove_last_character_n_times = false
  )
  result = '        '.dup
  if optional_remove_last_character_n_times
    optional_remove_last_character_n_times.abs.times { result.chop! }
  end
  return result
end

#frame_1?Boolean Also known as: frame_1, frame1

#

frame_1?

#

Returns:

  • (Boolean)

305
306
307
# File 'lib/bioroebe/utility_scripts/showorf/showorf.rb', line 305

def frame_1?
  @frame_1
end

#frame_2?Boolean Also known as: frame_2, frame2

#

frame_2?

#

Returns:

  • (Boolean)

313
314
315
# File 'lib/bioroebe/utility_scripts/showorf/showorf.rb', line 313

def frame_2?
  @frame_2
end

#frame_3?Boolean Also known as: frame_3, frame3

#

frame_3?

#

Returns:

  • (Boolean)

321
322
323
# File 'lib/bioroebe/utility_scripts/showorf/showorf.rb', line 321

def frame_3?
  @frame_3
end

#hor_bar(i, how_many_times) ⇒ Object

#

hor_bar

This method is used to generate a horizontal bar.

The second argument tells it how many times to repeat the main token.

#

451
452
453
454
455
456
457
458
459
460
461
462
463
464
# File 'lib/bioroebe/utility_scripts/showorf/showorf.rb', line 451

def hor_bar(
    i,
    how_many_times
  )
  use_this_token = '-'
  # ======================================================================= #
  # Next, return the assembly.
  # ======================================================================= #
  token_pad+
  use_this_token+
  use_this_token+
  use_this_token+
  (i * how_many_times)
end

#inner_strip(i) ⇒ Object

#

inner_strip

#

145
146
147
# File 'lib/bioroebe/utility_scripts/showorf/showorf.rb', line 145

def inner_strip(i)
  i.delete(' ')
end

#input_sequence?Boolean Also known as: input?

#

input_sequence?

#

Returns:

  • (Boolean)

165
166
167
# File 'lib/bioroebe/utility_scripts/showorf/showorf.rb', line 165

def input_sequence?
  @input_sequence
end

#max_allowed_size_per_lineObject

#

max_allowed_size_per_line

This method will return a number, which states how many characters are allowed in the main header, above frame 1.

#

343
344
345
346
347
# File 'lib/bioroebe/utility_scripts/showorf/showorf.rb', line 343

def max_allowed_size_per_line
  _ = input?
  n_nucleotides = _.size + 2 + _.size.to_s.size
  return n_nucleotides
end
#

menu (menu tag)

By default, the input to this menu will be solely commandline arguments that have '–' as part of their name.

#

15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/bioroebe/utility_scripts/showorf/menu.rb', line 15

def menu(
    i = commandline_arguments?
  )
  if i.is_a? Array
    i.each {|entry| menu(entry) }
  else
    case i # case tag
    # ===================================================================== #
    # === showorf CACAGCAGCAGGCCCTCGGTCGTCGCTCCACATCAGCCGTCACATAGAGCTGATAG --all
    # ===================================================================== #
    when /^-?-?all$/
      set_show_these_frames(:all_frames)
    # ===================================================================== #
    # === showorf CACAGCAGCAGGCCCGTCACATAGAGCTGATAG --frame3
    # ===================================================================== #
    when /^-?-?frame3$/,
         /^-?-?show-?only-?frame-?3$/,
         /^-?-?f3$/
      set_show_these_frames(:f3)
    # ===================================================================== #
    # === showorf --frame2
    # ===================================================================== #
    when /^-?-?frame2$/,
         /^-?-?show-?only-?frame-?2$/,
         /^-?-?f2$/
      set_show_these_frames(:f2)
    # ===================================================================== #
    # === showorf --frames_1_2_3
    # ===================================================================== #
    when /^-?-?frames_?1_?2_?3/,
         /^-?-?show-?frame-?1-?2-?3/
      set_show_these_frames(:f1_and_f2_and_f3)
    # ===================================================================== #
    # === showorf --frame1-and-2
    # ===================================================================== #
    when /^-?-?frame-?1(_|-)?and(_|-)?2/
      set_show_these_frames(:f1_and_f2)
    # ===================================================================== #
    # === showorf --frame1
    # ===================================================================== #
    when /^-?-?frame1$/,
         /-?-?show-?only-?frame-?1/
      set_show_these_frames(:f1)
    # ===================================================================== #
    # === showorf --help
    # ===================================================================== #
    when /help/
      show_help
      exit
    end
  end
end

#n_nucleotides?Boolean

#

n_nucleotides?

#

Returns:

  • (Boolean)

291
292
293
# File 'lib/bioroebe/utility_scripts/showorf/showorf.rb', line 291

def n_nucleotides?
  input?.size
end

#obtain_commandline_arguments_and_reject_double_separators(i) ⇒ Object

#

obtain_commandline_arguments_and_reject_double_separators

Presently, we only work on Arrays as input.

#

131
132
133
134
135
136
137
138
139
140
# File 'lib/bioroebe/utility_scripts/showorf/showorf.rb', line 131

def obtain_commandline_arguments_and_reject_double_separators(i)
  _ = i
  if i.is_a? Array
    if _.any? {|entry| entry.include? '--' }
      @commandline_arguments = _.select {|line| line.include? '--'}
      _.reject! {|line| line.include? '--'}
    end
  end
  return _
end

#orange_f1Object Also known as: f1

#

orange_f1

#

12
13
14
# File 'lib/bioroebe/utility_scripts/showorf/show.rb', line 12

def orange_f1
  orange('  F1  ')+rev
end

#orange_f2Object Also known as: f2

#

orange_f2

#

19
20
21
# File 'lib/bioroebe/utility_scripts/showorf/show.rb', line 19

def orange_f2
  orange('  F2  ')+rev
end

#orange_f3Object Also known as: f3

#

orange_f3

#

26
27
28
# File 'lib/bioroebe/utility_scripts/showorf/show.rb', line 26

def orange_f3
  orange('  F3  ')+rev
end

#r1Object

#

r1

#

33
34
35
# File 'lib/bioroebe/utility_scripts/showorf/show.rb', line 33

def r1
  orangered('  R1  ')+rev
end

#r2Object

#

r2

#

40
41
42
# File 'lib/bioroebe/utility_scripts/showorf/show.rb', line 40

def r2
  orangered('  R2  ')+rev
end

#r3Object

#

r3

#

47
48
49
# File 'lib/bioroebe/utility_scripts/showorf/show.rb', line 47

def r3
  orangered('  R3  ')+rev
end

#remove_newlines(i) ⇒ Object

#

remove_newlines

This method will simply remove all newlines.

#

174
175
176
177
178
179
180
# File 'lib/bioroebe/utility_scripts/showorf/showorf.rb', line 174

def remove_newlines(i)
  if i.is_a? Array
    i.flatten.map {|entry| remove_newlines(entry)}
  else
    i.delete(N)
  end
end

#resetObject

#

reset

#

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/bioroebe/utility_scripts/showorf/reset.rb', line 12

def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === @show_these_frames
  #
  # Specify which frames are to be shown.
  #
  # By default, we will show all 3 forward and all 3 reverse frames.
  #
  # This can change on the commandline. For example,
  # showorf ATGCGC --only-frame-1 would keep only :frame1
  # in this array.  
  # ======================================================================= #
  @show_these_frames = [
    :frame1,
    :frame2,
    :frame3,
    :reverse_frame1,
    :reverse_frame2,
    :reverse_frame3,
  ]
end

#return_horizontal_bar(i = input?) ) ⇒ Object

#

return_horizontal_bar

#

432
433
434
435
436
437
438
439
440
441
442
# File 'lib/bioroebe/utility_scripts/showorf/showorf.rb', line 432

def return_horizontal_bar(i = input?)
  _ = return_spacer * i.size
  # ======================================================================= #
  # Next, at every 10th position, replace.
  # ======================================================================= #
  _.gsub!(/----------/, '---------'+return_vertical_token)
  if _.size > LIMIT_AT_N_NUCLEOTIDES
    _ = _[0, LIMIT_AT_N_NUCLEOTIDES]
  end
  return _
end

#return_numbers_based_on_this_input(i) ⇒ Object

#

return_numbers_based_on_this_input

#

248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# File 'lib/bioroebe/utility_scripts/showorf/showorf.rb', line 248

def return_numbers_based_on_this_input(i)
  _ = ''.dup
  case i.size
  when 11..20
    _ << '10'+pad
  when 21..29
    _ << '10'+pad+'20'+pad
  when 30..39
    _ << '10'+pad+'20'+pad+'30'+pad
  when 40..49
    _ << '10'+pad+'20'+pad+'30'+pad+'40'+pad
  when 50..59
    _ << '10'+pad+'20'+pad+'30'+pad+'40'+pad+'50'+pad
  when 60..69
    _ << '10'+pad+'20'+pad+'30'+pad+'40'+pad+'50'+pad+'60'+pad
  when 70..79
    _ << '10'+pad+'20'+pad+'30'+pad+'40'+pad+'50'+pad+'60'+pad+'70'+pad
  when 80..89
    _ << '10'+pad+'20'+pad+'30'+pad+'40'+pad+'50'+pad+'60'+pad+'70'+pad+'80'+pad
  when 90..99
    _ << '10'+pad+'20'+pad+'30'+pad+'40'+pad+'50'+pad+'60'+pad+'70'+pad+'80'+pad+'90'+pad
  else
    _ << '10'+pad+'20'+pad+'30'+pad+'40'+pad+'50'+pad+'60'+pad+'70'+pad+'80'+pad+'90'+pad(-1)+'100'+pad
  end
  return _ # Return it here.
end

#return_properly_formated_spacer_tokens(i) ⇒ Object

#

return_properly_formated_spacer_tokens

Input how many '-' tokens you need to have for this line.

#

424
425
426
427
# File 'lib/bioroebe/utility_scripts/showorf/showorf.rb', line 424

def return_properly_formated_spacer_tokens(i)
  _ = return_spacer(i)
  _.gsub(/----------/, '---------'+return_vertical_token)
end

#return_spacer(n_spacer_tokens = 100) ⇒ Object

#

return_spacer

#

227
228
229
# File 'lib/bioroebe/utility_scripts/showorf/showorf.rb', line 227

def return_spacer(n_spacer_tokens = 100)
  '-' * n_spacer_tokens.abs
end

#return_vertical_tokenObject

#

return_vertical_token

If we want to return a colourized '|' token.

#

331
332
333
334
335
# File 'lib/bioroebe/utility_scripts/showorf/showorf.rb', line 331

def return_vertical_token
  _ = '|'
  _ = palegreen(_)+rev if COLOURIZE_VERTICAL_TOKEN
  return _
end

#reverse_complement(i) ⇒ Object

#

reverse_complement

#

241
242
243
# File 'lib/bioroebe/utility_scripts/showorf/showorf.rb', line 241

def reverse_complement(i)
  i = complement(i.reverse)
end

#runObject

#

run

#

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/bioroebe/utility_scripts/showorf/run.rb', line 12

def run
  menu
  _ = input?.dup # Keep a pointer to the input given to us.
  n_nucleotides = _.size.to_s
  # ======================================================================= #
  # Chop the main string up into chunks of 100 each.
  # ======================================================================= #
  chopped_input = _.scan(/.{1,100}/m)
  converted_sequence_for_frame_1 = to_frame1(_)
  converted_sequence_for_frame_2 = to_frame2(_)
  converted_sequence_for_frame_3 = to_frame3(_)
  converted_sequence_for_reverse_frame_1 = to_reverse_frame1(_)
  converted_sequence_for_reverse_frame_2 = to_reverse_frame2(_)
  converted_sequence_for_reverse_frame_3 = to_reverse_frame3(_)
  e
  e "#{rev}Translation of requested code (5' #{steelblue('')} #{rev}3') "\
    "for #{simp(n_nucleotides)}#{rev} nucleotides.#{N}"
  e
  # ======================================================================= #
  # Next, we build up the 3 different frames. In order to do so,
  # we will first insert two ' ' after every position.
  # ======================================================================= #
  converted_sequence_for_frame_1 = converted_sequence_for_frame_1.chars.map {|entry|
    entry+'  '
  }.join
  converted_sequence_for_frame_2 = ' '+converted_sequence_for_frame_2.chars.map {|entry|
    entry+'  '
  }.join
  converted_sequence_for_frame_3 = '  '+converted_sequence_for_frame_3.chars.map {|entry|
    entry+'  '
  }.join
  converted_sequence_for_reverse_frame_1 = converted_sequence_for_reverse_frame_1.chars.map {|entry|
    entry+'  '
  }.join
  converted_sequence_for_reverse_frame_2 = ' '+converted_sequence_for_reverse_frame_2.chars.map {|entry|
    entry+'  '
  }.join
  converted_sequence_for_reverse_frame_3 = '  '+converted_sequence_for_reverse_frame_3.chars.map {|entry|
    entry+'  '
  }.join
  # ======================================================================= #
  # We will chop them up into runs of 100, but only display
  # for how many we get. The seagreen bar is on the very top,
  # the "10    20" and so on.
  # ======================================================================= #
  e '                    '+
    seagreen(
      return_numbers_based_on_this_input(_)
    )+
    rev
  # ======================================================================= #
  # === Get rid of newlines
  # ======================================================================= #
  if chopped_input.any? {|entry| entry.include? N }
    chopped_input = remove_newlines(chopped_input)
  end
  chopped_input = strip(chopped_input)
  chopped_input.each_with_index {|aminoacids_in_this_line, index|

    left_nucleotide_position = ((index * 100)+1).to_s.rjust(3)
    right_position = ((100 * index)+aminoacids_in_this_line.size).to_s

    # ===================================================================== #
    # Return the properly formated spacer tokens next. We need to find
    # out how many tokens we have to display.
    # ===================================================================== #
    display_n_tokens = (right_position.to_i+1 - left_nucleotide_position.strip.to_i)

    # ===================================================================== #
    # Display the first frame next, then the other two frames.
    # ===================================================================== #
    set_frame_1(
      converted_sequence_for_frame_1[(100 * index)..((100 * index)+100-1)]
    ) if show_frame_1?

    set_frame_2(
      converted_sequence_for_frame_2[(100 * index)..((100 * index)+100-1)]
    ) if show_frame_2?

    set_frame_3(
      converted_sequence_for_frame_3[(100 * index)..((100 * index)+100-1)]
    ) if show_frame_3?
    # ===================================================================== #
    # Next add the '----|' separators.
    # ===================================================================== #
    e "           #{return_properly_formated_spacer_tokens(display_n_tokens)}"
    # ===================================================================== #
    # === Next show the main nucleotide sequence
    # ===================================================================== #
    e '      '+
      mediumspringgreen(left_nucleotide_position)+rev+
      '  '+
      mediumseagreen(aminoacids_in_this_line.upcase)+rev+'  '+
      mediumspringgreen( # <- This here is the end-part that is colourized.
        ((100 * index)+aminoacids_in_this_line.size).to_s
      )
    # ===================================================================== #
    # The number should be reset after a '*' character.
    # ===================================================================== #

    # ===================================================================== #
    # === Handle Frame1 next
    # ===================================================================== #
    if show_frame_1?
      show_this_frame(frame_1, :frame1)
    end

    # ===================================================================== #
    # === Handle Frame2
    # ===================================================================== #
    if show_frame_2?
      show_this_frame(frame_2, :frame2)
    end

    # ===================================================================== #
    # === Handle Frame3
    # ===================================================================== #
    if show_frame_3?
      show_this_frame(frame_3, :frame3)
    end

    # ===================================================================== #
    # Next, consider showing the reverse frames.
    # ===================================================================== #
    if show_reverse_frame_1?
      e r1+'     '+converted_sequence_for_reverse_frame_1
    end

    if show_reverse_frame_2?
      e r2+'     '+converted_sequence_for_reverse_frame_2
    end

    if show_reverse_frame_3?
      e r3+'     '+converted_sequence_for_reverse_frame_3
    end

    e
  }
end

#set_frame_1(i) ⇒ Object

#

set_frame_1

#

196
197
198
199
# File 'lib/bioroebe/utility_scripts/showorf/showorf.rb', line 196

def set_frame_1(i)
  i = i.to_s
  @frame_1 = i
end

#set_frame_2(i) ⇒ Object

#

set_frame_2

#

204
205
206
207
# File 'lib/bioroebe/utility_scripts/showorf/showorf.rb', line 204

def set_frame_2(i)
  i = i.to_s
  @frame_2 = i
end

#set_frame_3(i) ⇒ Object

#

set_frame_3

#

212
213
214
215
# File 'lib/bioroebe/utility_scripts/showorf/showorf.rb', line 212

def set_frame_3(i)
  i = i.to_s
  @frame_3 = i
end

#set_input_sequence(i) ⇒ Object

#

set_input_sequence

Set the DNA sequence here.

#

154
155
156
157
158
159
160
# File 'lib/bioroebe/utility_scripts/showorf/showorf.rb', line 154

def set_input_sequence(i)
  i = i.join if i.is_a? Array
  i = remove_newlines(i)
  i = strip(i) # Get rid of trailing thingies.
  i = inner_strip(i)
  @input_sequence = i
end

#set_show_these_frames(i) ⇒ Object

#

set_show_these_frames

#

33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/bioroebe/utility_scripts/showorf/showorf.rb', line 33

def set_show_these_frames(i)
  case i # case tag
  # ======================================================================= #
  # === frame1
  # ======================================================================= #
  when :frame1,
       :f1
    @show_these_frames = [:frame1]
  # ======================================================================= #
  # === frame2
  # ======================================================================= #
  when :frame2,
       :f2
    @show_these_frames = [:frame2]
  # ======================================================================= #
  # === frame3
  # ======================================================================= #
  when :frame3,
       :f3
    @show_these_frames = [:frame3]
  # ======================================================================= #
  # === frame1_frame
  # ======================================================================= #
  when :frame1_frame2,
       :f1_and_f2
    @show_these_frames = [:frame1, :frame2]
  # ======================================================================= #
  # === f1_and_f2_and_f3
  # ======================================================================= #
  when :f1_and_f2_and_f3
    @show_these_frames = [:frame1, :frame2, :frame3]
  # ======================================================================= #
  # === all_frames                                                (all tag)
  #
  # Use this when you wish to show all 6 reading frames.
  # ======================================================================= #
  when :all_frames,
       :show_three_frames,
       :frame1_frame2_frame3,
       :frame1_frame2_frame2_reverse1_reverse2_reverse3
    @show_these_frames = [
      :frame1,
      :frame2,
      :frame3,
      :reverse_frame1,
      :reverse_frame2,
      :reverse_frame3
    ]
  end
end

#show_frame_1?Boolean

#

show_frame_1?

#

Returns:

  • (Boolean)

87
88
89
# File 'lib/bioroebe/utility_scripts/showorf/showorf.rb', line 87

def show_frame_1?
  @show_these_frames.include? :frame1
end

#show_frame_2?Boolean

#

show_frame_2?

#

Returns:

  • (Boolean)

94
95
96
# File 'lib/bioroebe/utility_scripts/showorf/showorf.rb', line 94

def show_frame_2?
  @show_these_frames.include? :frame2
end

#show_frame_3?Boolean

#

show_frame_3?

#

Returns:

  • (Boolean)

101
102
103
# File 'lib/bioroebe/utility_scripts/showorf/showorf.rb', line 101

def show_frame_3?
  @show_these_frames.include? :frame3
end

#show_helpObject

#

show_help (help tag)

Invocation example:

showorf --help
#

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/bioroebe/utility_scripts/showorf/help.rb', line 17

def show_help
  e
  opnn; erev 'This class is capable of showing the ORF (open '\
             'reading frame) from the'
  opnn; erev 'given input string (which is assumed to be a '\
             'nucleotide sequence).'
  e
  opnn; erev 'By default, this class will show all 3 reading frames, but'
  opnn; erev 'you can also selectively show only one frame. Examples:'
  e
  opnn; erev '  --frame1 # show reading frame1 (forward frame 1)'
  opnn; erev '  --frame2 # show reading frame1 (forward frame 2)'
  opnn; erev '  --frame3 # show reading frame1 (forward frame 3)'
  e
end

#show_reverse_frame_1?Boolean

#

show_reverse_frame_1?

#

Returns:

  • (Boolean)

108
109
110
# File 'lib/bioroebe/utility_scripts/showorf/showorf.rb', line 108

def show_reverse_frame_1?
  @show_these_frames.include? :reverse_frame1
end

#show_reverse_frame_2?Boolean

#

show_reverse_frame_2?

#

Returns:

  • (Boolean)

115
116
117
# File 'lib/bioroebe/utility_scripts/showorf/showorf.rb', line 115

def show_reverse_frame_2?
  @show_these_frames.include? :reverse_frame2
end

#show_reverse_frame_3?Boolean

#

show_reverse_frame_3?

#

Returns:

  • (Boolean)

122
123
124
# File 'lib/bioroebe/utility_scripts/showorf/showorf.rb', line 122

def show_reverse_frame_3?
  @show_these_frames.include? :reverse_frame3
end

#show_this_frame(i = frame_1, which_frame = :frame1) ⇒ Object

#

show_this_frame

#

54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/bioroebe/utility_scripts/showorf/show.rb', line 54

def show_this_frame(
    i           = frame_1,
    which_frame = :frame1
  )
  _ = max_allowed_size_per_line
  n_aminoacids = i.delete(' ').chars.size.to_s
  right_padding = '  '.dup
  case which_frame
  when :frame1
    which_frame = orange_f1
    right_padding << '  '
  when :frame2
    which_frame = orange_f2
    right_padding << ' '
  when :frame3
    which_frame = orange_f3
  end
  leading_part = which_frame+(' ' * 3)+'  '+i
  # ======================================================================= #
  # === Colourize stop codons in the colour red
  # ======================================================================= #
  if colourize_stop_codons_in_red? and use_colours?
    leading_part.gsub!(/(\*)/, swarn('\\1')+rev)
  end
  leading_part << right_padding
  # ======================================================================= #
  # We may have to modify the variable n_aminoacids if there is a stop
  # codon.
  # ======================================================================= #
  if i.include? '*'
    n_aminoacids = i[(i.rindex('*')+1) .. i.size].delete(' ').size.to_s.
                   rjust(i.size.to_s.size)
  end
  # ======================================================================= #
  # Next also append how many aminoacids are part of this squence:
  # ======================================================================= #
  string = leading_part+
           darkolivegreen(
             n_aminoacids.to_s+' aminoacids'
           )+rev
  e string
end

#strip(i) ⇒ Object

#

strip

#

185
186
187
188
189
190
191
# File 'lib/bioroebe/utility_scripts/showorf/showorf.rb', line 185

def strip(i)
  if i.is_a? Array
    i.map {|entry| strip(entry) }
  else
    i.strip
  end
end

#to_frame1(i) ⇒ Object

#

to_frame1

Frame1 requires no change, so we can simply pass it into the method Bioroebe.translate_dna_into_aminoacid().

#

355
356
357
358
359
# File 'lib/bioroebe/utility_scripts/showorf/showorf.rb', line 355

def to_frame1(i)
  return ::Bioroebe.translate_dna_into_aminoacid(
    i
  ) # We need the module-method here.
end

#to_frame2(i) ⇒ Object

#

to_frame2

Frame2 requires a change, hence the second line in the method body.

#

366
367
368
369
370
371
372
# File 'lib/bioroebe/utility_scripts/showorf/showorf.rb', line 366

def to_frame2(i)
  i = i.dup
  i[0,1] = '' # Chop off the first character.
  return ::Bioroebe.translate_dna_into_aminoacid(
    i
  )
end

#to_frame3(i) ⇒ Object

#

to_frame3

Frame3 requires a change.

#

379
380
381
382
383
384
385
386
# File 'lib/bioroebe/utility_scripts/showorf/showorf.rb', line 379

def to_frame3(i)
  i = i.dup
  i[0,1] = '' # Chop off the first character.
  i[0,1] = '' # And again.
  return ::Bioroebe.translate_dna_into_aminoacid(
    i
  )
end

#to_reverse_frame1(i) ⇒ Object

#

to_reverse_frame1

#

399
400
401
402
403
404
405
# File 'lib/bioroebe/utility_scripts/showorf/showorf.rb', line 399

def to_reverse_frame1(i)
  i = reverse_complement(i).dup
  i[0,1] = ''
  return ::Bioroebe.translate_dna_into_aminoacid(
    i
  )
end

#to_reverse_frame2(i) ⇒ Object

#

to_reverse_frame2

#

410
411
412
413
414
415
416
417
# File 'lib/bioroebe/utility_scripts/showorf/showorf.rb', line 410

def to_reverse_frame2(i)
  i = reverse_complement(i).dup
  i[0,1] = ''
  i[0,1] = ''
  return ::Bioroebe.translate_dna_into_aminoacid(
    i
  )
end

#to_reverse_frame3(i) ⇒ Object

#

to_reverse_frame3

#

391
392
393
394
# File 'lib/bioroebe/utility_scripts/showorf/showorf.rb', line 391

def to_reverse_frame3(i)
  i = reverse_complement(i).dup
  return ::Bioroebe.translate_dna_into_aminoacid(i)
end

#token_padObject

#

token_pad

#

234
235
236
# File 'lib/bioroebe/utility_scripts/showorf/showorf.rb', line 234

def token_pad
  '--------' # Horizontal padding.
end

#total_length?Boolean Also known as: total_size?

#

total_length?

#

Returns:

  • (Boolean)

220
221
222
# File 'lib/bioroebe/utility_scripts/showorf/showorf.rb', line 220

def total_length?
  input?.size
end