Class: Bioroebe::ShowNucleotideSequence
Overview
Bioroebe::ShowNucleotideSequence
Constant Summary
collapse
- USE_THIS_COLOUR =
#
Bioroebe::ShowNucleotideSequence::USE_THIS_COLOUR
This colour is usually “steelblue”.
#
USE_THIS_COLOUR_FOR_DNA
ColoursForBase::ARRAY_HTML_COLOURS_IN_USE
Constants inherited
from Sequence
Bioroebe::Sequence::REMOVE_INVALID_CHARACTERS, Bioroebe::Sequence::SHALL_WE_UPCASE
Class Method Summary
collapse
-
.[](i = ARGV) ⇒ Object
# === Bioroebe::ShowNucleotideSequence[] ========================================================================= #.
Instance Method Summary
collapse
-
#array_colourize_these_substrings? ⇒ Boolean
# === array_colourize_these_substrings? ========================================================================= #.
-
#clear_padding ⇒ Object
# === clear_padding ========================================================================= #.
-
#colourize_dna_sequence(i = '') ⇒ Object
(also: #colour_for_nucleotides, #colourize_rna_sequence)
# === colourize_dna_sequence.
-
#display_with_prior_formatting(i = sequence_for_display?, , &block) ⇒ Object
-
#do_colourize_the_start_codon ⇒ Object
# === do_colourize_the_start_codon ========================================================================= #.
-
#do_not_report_anything ⇒ Object
# === do_not_report_anything ========================================================================= #.
-
#do_properly_display_this_nucleotide_sequence(i = sequence_for_display?, , padding_to_use = padding_to_use?, , show_ruler = show_ruler?, , show_five_prime_leader = show_five_prime_leader?, , show_three_prime_trailer = show_three_prime_trailer?, , &block) ⇒ Object
(also: #display, #report_this_sequence, #report, #format_this_nucleotide_sequence, #format_this_string, #format)
# === do_properly_display_this_nucleotide_sequence (display tag, report tag).
-
#do_show_the_ruler ⇒ Object
# === do_show_the_ruler ========================================================================= #.
-
#initialize(commandline_arguments = nil, run_already = true) ⇒ ShowNucleotideSequence
constructor
# === initialize.
-
#main_sequence_as_string? ⇒ Boolean
# === main_sequence_as_string? ========================================================================= #.
-
#menu(i = commandline_arguments?.select {|inner_entry| inner_entry.start_with? '--' }) ⇒ Object
-
#padding_to_use? ⇒ Boolean
(also: #padding?)
# === padding_to_use? ========================================================================= #.
-
#reset ⇒ Object
# === reset (reset tag) ========================================================================= #.
-
#return_colour_for_the_dna_sequence ⇒ Object
# === return_colour_for_the_dna_sequence ========================================================================= #.
-
#return_five_prime_leader ⇒ Object
(also: #leader?)
# === return_five_prime_leader ========================================================================= #.
-
#return_three_prime_leader ⇒ Object
# === return_three_prime_leader ========================================================================= #.
-
#return_three_prime_trailer ⇒ Object
(also: #trailer?)
# === return_three_prime_trailer ========================================================================= #.
-
#run ⇒ Object
# === run (run tag) ========================================================================= #.
-
#search_for_this_substring(i) ⇒ Object
(also: #set_search_for, #add_this_substring)
# === search_for_this_substring.
-
#sequence_for_display? ⇒ Boolean
(also: #formatted_sequence?, #sequence_for_display)
# === sequence_for_display?.
-
#set_padding_to_use(i = '') ⇒ Object
(also: #set_padding)
# === set_padding_to_use ========================================================================= #.
-
#set_sequence_for_display(i) ⇒ Object
(also: #set_this_sequence)
# === set_sequence_for_display.
-
#shall_we_report? ⇒ Boolean
(also: #may_we_report?, #shall_we_report)
# === shall_we_report? ========================================================================= #.
-
#show_five_prime_leader? ⇒ Boolean
# === show_five_prime_leader? ========================================================================= #.
-
#show_in_dashed_form? ⇒ Boolean
-
#show_ruler? ⇒ Boolean
# === show_ruler? ========================================================================= #.
-
#show_three_prime_trailer? ⇒ Boolean
# === show_three_prime_trailer? ========================================================================= #.
#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?
#infer_the_namespace, #namespace?
#internal_hash?, #reset_the_internal_hash
#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 inherited from Sequence
#automatic_support_for_nucleotides, #description?, #index, #infer_type, #is_DNA?, #is_RNA?, #is_a_protein?, #is_a_protein_now, #map, #n_uracil?, #randomize, #remove_invalid_entries_from_the_dna_sequence, #remove_invalid_entries_from_the_dna_sequence!, #return_string_nucleotides_or_aminoacids, #sanitize_dataset, #sanitize_rna, #save_sequence_to_this_file, sequence_from_file, #set_description, #set_dna, #set_protein, #set_rna, #set_save_file, #set_sequence, #set_type, #shall_we_upcase?, #size?, #to_genbank, #to_regexp, #type?
Methods inherited from RawSequence
#+, #<<, #[]=, #calculate_levensthein_distance, #chars?, #complement, #composition?, #count, #delete, #delete!, #downcase, #each_char, #empty?, #find_substring_indices, #first_position=, #freeze, #gsub, #gsub!, #include?, #insert_at_this_position, #prepend, #remove_n_characters_from_the_left_side, #reverse, #reverse!, #reverse_complement, #scan, #set_raw_sequence, #shuffle, #size?, #split, #start_with?, #strip, #subseq, #to_s, #to_str, #tr!, #upcase!
Constructor Details
#initialize(commandline_arguments = nil, run_already = true) ⇒ ShowNucleotideSequence
#
initialize
The first argument to this class will become the sequence that is to be displayed, such as ‘ATCG’.
#
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
|
# File 'lib/bioroebe/nucleotides/show_nucleotide_sequence/show_nucleotide_sequence.rb', line 55
def initialize(
commandline_arguments = nil,
run_already = true
)
reset
set_commandline_arguments(
commandline_arguments
)
if block_given?
yielded = yield
if yielded.is_a? Symbol
case yielded
when :colourize_start_codon
do_colourize_the_start_codon
end
elsif yielded.is_a? Hash
if yielded.has_key? :colourize_this_subsequence
search_for_this_substring(
yielded[:colourize_this_subsequence]
)
end
end
end
case run_already
when :do_not_run_yet,
:do_not_run
run_already = false
when :do_not_report_anything
do_not_report_anything
end
run if run_already
end
|
Class Method Details
.[](i = ARGV) ⇒ Object
#
Bioroebe::ShowNucleotideSequence[]
#
651
652
653
|
# File 'lib/bioroebe/nucleotides/show_nucleotide_sequence/show_nucleotide_sequence.rb', line 651
def self.[](i = ARGV)
new(i)
end
|
Instance Method Details
#array_colourize_these_substrings? ⇒ Boolean
#
array_colourize_these_substrings?
#
310
311
312
|
# File 'lib/bioroebe/nucleotides/show_nucleotide_sequence/show_nucleotide_sequence.rb', line 310
def array_colourize_these_substrings?
@internal_hash[:array_colourize_these_substrings]
end
|
#clear_padding ⇒ Object
264
265
266
|
# File 'lib/bioroebe/nucleotides/show_nucleotide_sequence/show_nucleotide_sequence.rb', line 264
def clear_padding
set_padding_to_use('')
end
|
#colourize_dna_sequence(i = '') ⇒ Object
Also known as:
colour_for_nucleotides, colourize_rna_sequence
#
colourize_dna_sequence
This method should be used to colourize the primary DNA/RNA sequence.
#
187
188
189
|
# File 'lib/bioroebe/nucleotides/show_nucleotide_sequence/show_nucleotide_sequence.rb', line 187
def colourize_dna_sequence(i = '')
::Colours.send(USE_THIS_COLOUR, i.dup)
end
|
572
573
574
575
576
577
578
579
580
|
# File 'lib/bioroebe/nucleotides/show_nucleotide_sequence/show_nucleotide_sequence.rb', line 572
def display_with_prior_formatting(
i = sequence_for_display?,
&block
)
do_show_the_ruler
clear_padding
format_this_nucleotide_sequence(i, &block)
report(i) end
|
#do_colourize_the_start_codon ⇒ Object
#
do_colourize_the_start_codon
#
644
645
646
|
# File 'lib/bioroebe/nucleotides/show_nucleotide_sequence/show_nucleotide_sequence.rb', line 644
def do_colourize_the_start_codon
add_this_substring('ATG')
end
|
#do_not_report_anything ⇒ Object
#
do_not_report_anything
#
171
172
173
|
# File 'lib/bioroebe/nucleotides/show_nucleotide_sequence/show_nucleotide_sequence.rb', line 171
def do_not_report_anything
@internal_hash[:shall_we_report] = false
end
|
#do_properly_display_this_nucleotide_sequence(i = sequence_for_display?,
, padding_to_use = padding_to_use?,
, show_ruler = show_ruler?,
, show_five_prime_leader = show_five_prime_leader?,
, show_three_prime_trailer = show_three_prime_trailer?,
, &block) ⇒ Object
Also known as:
display, report_this_sequence, report, format_this_nucleotide_sequence, format_this_string, format
#
do_properly_display_this_nucleotide_sequence (display tag, report tag)
The first argument to this method is the sequence (DNA or RNA) that should be displayed.
This method will only do the reporting by default - not a new format-operation, unless a block has been given to it.
Usage example for this method:
@show_nucleotide_sequence.report_this_sequence(input) {{ padding_to_use: padding? }}
#
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
|
# File 'lib/bioroebe/nucleotides/show_nucleotide_sequence/show_nucleotide_sequence.rb', line 335
def do_properly_display_this_nucleotide_sequence(
i = sequence_for_display?,
padding_to_use = padding_to_use?,
show_ruler = show_ruler?,
show_five_prime_leader = show_five_prime_leader?,
show_three_prime_trailer = show_three_prime_trailer?,
&block
)
result = ''.dup
if i.nil? and string?
i = string?
end
if block_given?
yielded = yield
case yielded
when :use_colours
disable_colours { :be_quiet }
when :colourize_start_codon
do_colourize_the_start_codon
when :show_ruler
show_ruler = true
when :without_colours
show_ruler = yielded
do_show_the_ruler
when :complementary_strand
result << return_three_prime_leader
i = complementary_strand(
i.chars
)
show_five_prime_leader = false
show_three_prime_trailer = :use_five_prime_trailer
when :to_rna,
:rna
i = to_rna(i)
else
if yielded.is_a? Hash
if yielded.has_key? :use_colours
set_use_colours(yielded.delete(:use_colours))
end
if yielded.has_key? :use_this_as_padding
padding_to_use = yielded[:use_this_as_padding]
end
if yielded.has_key? :colourize_this_subsequence
set_search_for(yielded[:colourize_this_subsequence])
end
if yielded.has_key? :ruler
_ = yielded.delete(:ruler)
case _
when :without_colours
show_ruler = _
end
end
end
end
end
if show_in_dashed_form?
use_this_token_for_rejoining = '-' group_by_n_tokens = 3
n_times = '.' * group_by_n_tokens.to_i use_this_regex = /#{n_times}/ i = i.scan(use_this_regex).
join(use_this_token_for_rejoining) end
result << rev if use_colours?
result << "#{padding_to_use}"
if show_ruler
print "#{rev}#{padding_to_use}"
if show_five_prime_leader
ee(' '*"#{leader?}".size)
end
e ::Bioroebe::Ruler.new(i, :default) {{
ruler: show_ruler
}}.result_as_string?
end
if show_five_prime_leader
result << "#{leader?}"
end
if block_given?
yielded = yield
if yielded.is_a? Symbol
case yielded
when :piped
i.gsub!(/(...)/, "\\1|") when :colourize_start_codon
do_colourize_the_start_codon
when :complementary_strand
i = ::Bioroebe.complementary_strand(i)
end
elsif yielded.is_a? Hash
if yielded.has_key? :colourize_this_subsequence
search_for_this_substring(
yielded[:colourize_this_subsequence]
)
end
if yielded.has_key?(:show_piped_output) and
(yielded[:show_piped_output] == true)
i.gsub!(/(...)/, "\\1|") end
if yielded.has_key? :padding_to_use
set_padding(yielded.delete(:padding_to_use))
end
end
end
if use_colours? and !array_colourize_these_substrings?.empty?
array_colourize_these_substrings?.each {|this_substring|
if i and i.include?(this_substring) i = i.dup if i.frozen?
i.prepend(return_colour_for_the_dna_sequence)
i.gsub!(
/(#{this_substring})/,
crimson('\1')+
remove_trailing_escape_part(colour_for_nucleotides)
)
end
}
end
result << colourize_dna_sequence(i)
if show_three_prime_trailer
case show_three_prime_trailer
when :use_five_prime_trailer
result << "#{rev} - 5'"
else
result << "#{rev}#{trailer?}"
end
end
e result if may_we_report?
end
|
#do_show_the_ruler ⇒ Object
303
304
305
|
# File 'lib/bioroebe/nucleotides/show_nucleotide_sequence/show_nucleotide_sequence.rb', line 303
def do_show_the_ruler
@internal_hash[:show_ruler] = true
end
|
#main_sequence_as_string? ⇒ Boolean
#
main_sequence_as_string?
#
317
318
319
|
# File 'lib/bioroebe/nucleotides/show_nucleotide_sequence/show_nucleotide_sequence.rb', line 317
def main_sequence_as_string?
sequence_for_display?.to_s
end
|
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
|
# File 'lib/bioroebe/nucleotides/show_nucleotide_sequence/show_nucleotide_sequence.rb', line 585
def (
i = commandline_arguments?.select {|inner_entry| inner_entry.start_with? '--' }
)
if i and i.is_a?(Array)
i.each {|entry| (entry) }
else
case i when /^-?-?ruler$/i
@internal_hash[:show_ruler] = true
end
end
end
|
#padding_to_use? ⇒ Boolean
Also known as:
padding?
257
258
259
|
# File 'lib/bioroebe/nucleotides/show_nucleotide_sequence/show_nucleotide_sequence.rb', line 257
def padding_to_use?
@internal_hash[:padding_to_use]
end
|
#reset ⇒ Object
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
# File 'lib/bioroebe/nucleotides/show_nucleotide_sequence/show_nucleotide_sequence.rb', line 120
def reset
reset_the_internal_hash infer_the_namespace
enable_colours set_padding_to_use(7) @internal_hash[:show_in_dashed_form] = false
@internal_hash[:sequence_for_display] = nil
@internal_hash[:show_ruler] = false
@internal_hash[:show_five_prime_leader] = true
@internal_hash[:shall_we_report] = true
@internal_hash[:show_three_prime_trailer] = true
@internal_hash[:array_colourize_these_substrings] = []
end
|
#return_colour_for_the_dna_sequence ⇒ Object
#
return_colour_for_the_dna_sequence
#
195
196
197
198
199
200
|
# File 'lib/bioroebe/nucleotides/show_nucleotide_sequence/show_nucleotide_sequence.rb', line 195
def return_colour_for_the_dna_sequence
result = Colours.remove_trailing_code(
::Colours.send(USE_THIS_COLOUR)
)
return result
end
|
#return_five_prime_leader ⇒ Object
Also known as:
leader?
#
return_five_prime_leader
#
230
231
232
|
# File 'lib/bioroebe/nucleotides/show_nucleotide_sequence/show_nucleotide_sequence.rb', line 230
def return_five_prime_leader
"5' - "
end
|
#return_three_prime_leader ⇒ Object
#
return_three_prime_leader
#
223
224
225
|
# File 'lib/bioroebe/nucleotides/show_nucleotide_sequence/show_nucleotide_sequence.rb', line 223
def return_three_prime_leader
"3' - "
end
|
#return_three_prime_trailer ⇒ Object
Also known as:
trailer?
#
return_three_prime_trailer
#
237
238
239
|
# File 'lib/bioroebe/nucleotides/show_nucleotide_sequence/show_nucleotide_sequence.rb', line 237
def return_three_prime_trailer
" - 3'"
end
|
#run ⇒ Object
626
627
628
629
630
631
632
633
634
635
636
637
638
639
|
# File 'lib/bioroebe/nucleotides/show_nucleotide_sequence/show_nucleotide_sequence.rb', line 626
def run
(
commandline_arguments?
)
_ = first_argument?
if _.nil? or _.empty?
erev 'Nothing to display.'
else
set_sequence_for_display(_) if shall_we_report?
do_properly_display_this_nucleotide_sequence(_)
end
end
end
|
#search_for_this_substring(i) ⇒ Object
Also known as:
set_search_for, add_this_substring
#
search_for_this_substring
This method can be used to search for substrings, aka matches.
#
611
612
613
614
615
616
617
618
619
620
|
# File 'lib/bioroebe/nucleotides/show_nucleotide_sequence/show_nucleotide_sequence.rb', line 611
def search_for_this_substring(i)
if i.is_a? Array
i.each {|entry| search_for_this_substring(entry) }
else
unless @internal_hash[:array_colourize_these_substrings].include? i
@internal_hash[:array_colourize_these_substrings] << i
@internal_hash[:array_colourize_these_substrings].compact! end
end
end
|
#sequence_for_display? ⇒ Boolean
Also known as:
formatted_sequence?, sequence_for_display
#
sequence_for_display?
This method will return the sequence that will be displayed on the commandline, for instance.
#
215
216
217
|
# File 'lib/bioroebe/nucleotides/show_nucleotide_sequence/show_nucleotide_sequence.rb', line 215
def sequence_for_display?
@internal_hash[:sequence_for_display]
end
|
#set_padding_to_use(i = '') ⇒ Object
Also known as:
set_padding
244
245
246
247
248
249
250
251
252
|
# File 'lib/bioroebe/nucleotides/show_nucleotide_sequence/show_nucleotide_sequence.rb', line 244
def set_padding_to_use(
i = ''
)
if i and i.to_s =~ /^\d+$/i i = ' ' * i.to_i
end
i = i.dup if i and i.frozen?
@internal_hash[:padding_to_use] = i
end
|
#set_sequence_for_display(i) ⇒ Object
Also known as:
set_this_sequence
#
set_sequence_for_display
This is the raw sequence that will be displayed. Only store the nucleotides, NOT 5’ and 3’ primer/trailer.
#
289
290
291
|
# File 'lib/bioroebe/nucleotides/show_nucleotide_sequence/show_nucleotide_sequence.rb', line 289
def set_sequence_for_display(i)
@internal_hash[:sequence_for_display] = i
end
|
#shall_we_report? ⇒ Boolean
Also known as:
may_we_report?, shall_we_report
278
279
280
|
# File 'lib/bioroebe/nucleotides/show_nucleotide_sequence/show_nucleotide_sequence.rb', line 278
def shall_we_report?
@internal_hash[:shall_we_report]
end
|
#show_five_prime_leader? ⇒ Boolean
#
show_five_prime_leader?
#
178
179
180
|
# File 'lib/bioroebe/nucleotides/show_nucleotide_sequence/show_nucleotide_sequence.rb', line 178
def show_five_prime_leader?
@internal_hash[:show_five_prime_leader]
end
|
205
206
207
|
# File 'lib/bioroebe/nucleotides/show_nucleotide_sequence/show_nucleotide_sequence.rb', line 205
def show_in_dashed_form?
@internal_hash[:show_in_dashed_form]
end
|
#show_ruler? ⇒ Boolean
296
297
298
|
# File 'lib/bioroebe/nucleotides/show_nucleotide_sequence/show_nucleotide_sequence.rb', line 296
def show_ruler?
@internal_hash[:show_ruler]
end
|
#show_three_prime_trailer? ⇒ Boolean
#
show_three_prime_trailer?
#
271
272
273
|
# File 'lib/bioroebe/nucleotides/show_nucleotide_sequence/show_nucleotide_sequence.rb', line 271
def show_three_prime_trailer?
@internal_hash[:show_three_prime_trailer]
end
|