bioroebe 0.10.80 → 0.11.12

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of bioroebe might be problematic. Click here for more details.

Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +507 -310
  3. data/bioroebe.gemspec +3 -3
  4. data/doc/README.gen +506 -309
  5. data/doc/todo/bioroebe_todo.md +29 -40
  6. data/lib/bioroebe/aminoacids/display_aminoacid_table.rb +1 -0
  7. data/lib/bioroebe/base/colours_for_base/colours_for_base.rb +18 -8
  8. data/lib/bioroebe/base/commandline_application/commandline_arguments.rb +13 -11
  9. data/lib/bioroebe/base/commandline_application/misc.rb +18 -8
  10. data/lib/bioroebe/base/prototype/misc.rb +1 -1
  11. data/lib/bioroebe/codons/show_codon_tables.rb +6 -2
  12. data/lib/bioroebe/constants/aminoacids_and_proteins.rb +1 -0
  13. data/lib/bioroebe/constants/files_and_directories.rb +8 -1
  14. data/lib/bioroebe/count/count_amount_of_nucleotides.rb +3 -0
  15. data/lib/bioroebe/gui/gtk3/protein_to_DNA/protein_to_DNA.rb +18 -18
  16. data/lib/bioroebe/gui/shared_code/protein_to_DNA/protein_to_DNA_module.rb +14 -14
  17. data/lib/bioroebe/parsers/genbank_parser.rb +353 -24
  18. data/lib/bioroebe/python/README.md +1 -0
  19. data/lib/bioroebe/python/__pycache__/mymodule.cpython-39.pyc +0 -0
  20. data/lib/bioroebe/python/gui/gtk3/widget1.py +22 -0
  21. data/lib/bioroebe/python/mymodule.py +8 -0
  22. data/lib/bioroebe/python/protein_to_dna.py +30 -0
  23. data/lib/bioroebe/python/shell/shell.py +19 -0
  24. data/lib/bioroebe/python/to_rna.py +14 -0
  25. data/lib/bioroebe/python/toplevel_methods/to_camelcase.py +11 -0
  26. data/lib/bioroebe/sequence/nucleotide_module/nucleotide_module.rb +28 -25
  27. data/lib/bioroebe/sequence/sequence.rb +54 -2
  28. data/lib/bioroebe/shell/menu.rb +3336 -3304
  29. data/lib/bioroebe/shell/readline/readline.rb +1 -1
  30. data/lib/bioroebe/shell/shell.rb +11233 -28
  31. data/lib/bioroebe/siRNA/siRNA.rb +81 -1
  32. data/lib/bioroebe/string_matching/find_longest_substring.rb +3 -2
  33. data/lib/bioroebe/toplevel_methods/aminoacids_and_proteins.rb +31 -24
  34. data/lib/bioroebe/toplevel_methods/nucleotides.rb +22 -5
  35. data/lib/bioroebe/toplevel_methods/open_in_browser.rb +2 -0
  36. data/lib/bioroebe/toplevel_methods/to_camelcase.rb +5 -0
  37. data/lib/bioroebe/version/version.rb +2 -2
  38. data/lib/bioroebe/yaml/configuration/browser.yml +1 -1
  39. data/lib/bioroebe/yaml/restriction_enzymes/restriction_enzymes.yml +3 -3
  40. metadata +17 -36
  41. data/doc/setup.rb +0 -1655
  42. data/lib/bioroebe/genbank/genbank_parser.rb +0 -291
  43. data/lib/bioroebe/shell/add.rb +0 -108
  44. data/lib/bioroebe/shell/assign.rb +0 -360
  45. data/lib/bioroebe/shell/chop_and_cut.rb +0 -281
  46. data/lib/bioroebe/shell/constants.rb +0 -166
  47. data/lib/bioroebe/shell/download.rb +0 -335
  48. data/lib/bioroebe/shell/enable_and_disable.rb +0 -158
  49. data/lib/bioroebe/shell/enzymes.rb +0 -310
  50. data/lib/bioroebe/shell/fasta.rb +0 -345
  51. data/lib/bioroebe/shell/gtk.rb +0 -76
  52. data/lib/bioroebe/shell/history.rb +0 -132
  53. data/lib/bioroebe/shell/initialize.rb +0 -217
  54. data/lib/bioroebe/shell/loop.rb +0 -74
  55. data/lib/bioroebe/shell/misc.rb +0 -4341
  56. data/lib/bioroebe/shell/prompt.rb +0 -107
  57. data/lib/bioroebe/shell/random.rb +0 -289
  58. data/lib/bioroebe/shell/reset.rb +0 -335
  59. data/lib/bioroebe/shell/scan_and_parse.rb +0 -135
  60. data/lib/bioroebe/shell/search.rb +0 -337
  61. data/lib/bioroebe/shell/sequences.rb +0 -200
  62. data/lib/bioroebe/shell/show_report_and_display.rb +0 -2901
  63. data/lib/bioroebe/shell/startup.rb +0 -127
  64. data/lib/bioroebe/shell/taxonomy.rb +0 -14
  65. data/lib/bioroebe/shell/tk.rb +0 -23
  66. data/lib/bioroebe/shell/user_input.rb +0 -88
  67. data/lib/bioroebe/shell/xorg.rb +0 -45
@@ -1,4341 +0,0 @@
1
- #!/usr/bin/ruby -w
2
- # Encoding: UTF-8
3
- # frozen_string_literal: true
4
- # =========================================================================== #
5
- # === Bioroebe::Shell
6
- #
7
- # This shell wraps together all related Bio tasks. It contains the
8
- # the core-functionality for the Bioroebe::Shell interface.
9
- #
10
- # To use it in one of your projects, do:
11
- #
12
- # require 'bioroebe'; Bioroebe::Shell.new
13
- #
14
- # =========================================================================== #
15
- # require 'bioroebe/shell/misc.rb'
16
- # =========================================================================== #
17
- module Bioroebe
18
-
19
- class Shell < ::Bioroebe::CommandlineApplication
20
-
21
- alias ee print
22
-
23
- require 'bioroebe/toplevel_methods/misc.rb'
24
- require 'bioroebe/string_matching/find_longest_substring.rb'
25
-
26
- begin
27
- require 'advanced_clipboard'
28
- rescue LoadError; end
29
-
30
- require 'bioroebe/configuration/configuration.rb'
31
-
32
- if Bioroebe.is_on_roebe?
33
- # ======================================================================= #
34
- # Load up support for FtpParadise, but only on roebe-systems.
35
- # ======================================================================= #
36
- begin
37
- require 'ftp_paradise'
38
- rescue LoadError; end
39
- end
40
-
41
- # ========================================================================= #
42
- # === Bioroebe::Shell.upload_this_pdf_file
43
- #
44
- # Use this method to upload the .pdf tutorial or any other .pdf
45
- # file. This is primarily useful on my home system and may have
46
- # very little value to other people.
47
- # ========================================================================= #
48
- def self.upload_this_pdf_file(path)
49
- # ======================================================================= #
50
- # ^^^ This will have generated the .pdf.
51
- # ======================================================================= #
52
- # Hardcoded for now where the .pdf will reside.
53
- # ======================================================================= #
54
- if Object.const_defined? :FtpParadise
55
- ftp = FtpParadise.new(:shevy, :dont_run_yet)
56
- ftp.do_login
57
- ftp.upload_this_binary_file(path)
58
- e 'Finished uploading!'
59
- end
60
- end
61
-
62
- # ========================================================================= #
63
- # === Bioroebe::Shell.generate_pdf_tutorial
64
- #
65
- # You can use this method to simply generate a new .pdf file, then
66
- # upload it anyway.
67
- # ========================================================================= #
68
- def self.generate_pdf_tutorial(
69
- also_upload_the_tutorial = true
70
- )
71
- url = ::Bioroebe.try_to_pass_through_beautiful_url('bioroebe_tutorial?pdf')
72
- url = url.first if url.is_a? Array
73
- url.gsub!(/^\/home\/x\/DATA\//, LOCALHOST) if url.include? HOME_DIRECTORY_OF_USER_X+'DATA/'
74
- OpenURI.send(:open, url)
75
- # ======================================================================= #
76
- # === Designate where the tutorial can be found locally
77
- # ======================================================================= #
78
- path = FILE_BIOROEBE_TUTORIAL
79
- if also_upload_the_tutorial
80
- if File.exist? path
81
- ::Bioroebe.upload_this_pdf_file(path)
82
- else
83
- e "Can not upload from #{sfile(path.to_s)} as this "\
84
- "path does not exist."
85
- end
86
- end
87
- end
88
-
89
- require 'bioroebe/calculate/calculate_gc_content.rb'
90
- # ========================================================================= #
91
- # === calculcate_gc_content
92
- #
93
- # Use this method to calculate the GC content of a DNA sequence.
94
- #
95
- # If you need the number, you can use this piece of code:
96
- #
97
- # CalculateGCContent.gc_percentage(i) # Will return the percentage number.
98
- #
99
- # ========================================================================= #
100
- def calculcate_gc_content(
101
- i = dna_sequence_as_string?
102
- )
103
- if i.nil? or i.empty? # The second check also checks for empty Arrays.
104
- i = dna_sequence_as_string? # bl $BIOROEBE/calculate/calculate_gc_content.rb
105
- end
106
- CalculateGCContent.new(i)
107
- end
108
-
109
- require 'bioroebe/nucleotides/most_likely_nucleotide_sequence_for_this_aminoacid_sequence.rb'
110
- # ========================================================================= #
111
- # === aa_to_dna
112
- # ========================================================================= #
113
- def aa_to_dna(i)
114
- if i.is_a? Array
115
- i = i.join.strip
116
- end
117
- i = ::Bioroebe.aa_to_dna(i)
118
- if i.is_a? Array
119
- i = i.join.strip
120
- end
121
- e i
122
- end
123
-
124
- # ========================================================================= #
125
- # === load_dna
126
- #
127
- # This method will assign from the default file.
128
- # ========================================================================= #
129
- def load_dna
130
- _ = file_dna_string_saved?
131
- if File.exist? _
132
- erev "Now loading from the file #{sfile(_)}#{rev}."
133
- assign(_)
134
- end
135
- end
136
-
137
- # ========================================================================= #
138
- # === file_dna_string_saved?
139
- # ========================================================================= #
140
- def file_dna_string_saved?
141
- @internal_hash[:file_dna_string_saved]
142
- end
143
-
144
- # ========================================================================= #
145
- # === to_talen
146
- # ========================================================================= #
147
- def to_talen(
148
- i = dna_sequence?
149
- )
150
- i = dna_sequence? if i.nil? # Obtain the DNA sequence.
151
- talen_sequence = '' # This will contain our final talen-sequence.
152
- talens = YAML.load_file(::Bioroebe.file_talens)
153
- i.scan(/./).each {|char|
154
- talen_sequence << "{ #{talens[char]} }"
155
- }
156
- pp talen_sequence
157
- end
158
-
159
- # ========================================================================= #
160
- # === bioshell_log_dir?
161
- #
162
- # This method will return where the bioshell/ log dir is kept.
163
- # ========================================================================= #
164
- def bioshell_log_dir?
165
- "#{log_dir?}bioshell/"
166
- end
167
-
168
- # ========================================================================= #
169
- # === dna_translate
170
- # ========================================================================= #
171
- def dna_translate(i)
172
- i = i.join(' ').strip if i.is_a? Array
173
- if i.nil? or i.empty?
174
- if dna_sequence_as_string?
175
- i = dna_sequence_as_string?
176
- erev 'Using the current DNA sequence (size: '+
177
- i.size.to_s+' nucleotides)'
178
- # =================================================================== #
179
- # assign_dna_sequence(i, :be_verbose) # First assign
180
- # ^^^ Why would we want to re-assign here? Makes no sense, thus it
181
- # was disabled as of December 2021.
182
- # =================================================================== #
183
- end
184
- end
185
- # ======================================================================= #
186
- # Find and display the complement to this DNA sequence:
187
- # ======================================================================= #
188
- erev "The #{orange('complementary DNA Strand')}#{rev} is:"
189
- e
190
- show_nucleotide_sequence?.display(i) { :complementary_strand }
191
- e
192
- end
193
-
194
- # ========================================================================= #
195
- # === open_in_browser_tab
196
- # ========================================================================= #
197
- def open_in_browser_tab(i)
198
- open_in_browser(i) # Defined in base.rb
199
- end
200
-
201
- # ========================================================================= #
202
- # === set_mode
203
- # ========================================================================= #
204
- def set_mode(i = :dna)
205
- case i
206
- when :protein, :proteins # Aliases.
207
- i = :aminoacids
208
- end
209
- @internal_hash[:mode] = i
210
- end
211
-
212
- # ========================================================================= #
213
- # === mode?
214
- # ========================================================================= #
215
- def mode?
216
- @internal_hash[:mode]
217
- end
218
-
219
- # ========================================================================= #
220
- # === only_valid_nucleotides?
221
- #
222
- # This method will determine whether our input string (the argument in
223
- # question) contains only valid nucleotides or whether it does not.
224
- # ========================================================================= #
225
- def only_valid_nucleotides?(i)
226
- i = i.first if i.is_a? Array
227
- if i.is_a? String
228
- i = i.delete("\n ").chars
229
- end
230
- uniq = i.uniq
231
- if uniq.all? {|entry| POSSIBLE_DNA_NUCLEOTIDES.include? entry }
232
- return true
233
- else
234
- return false
235
- end
236
- end; alias only_valid_dna_nucleotides? only_valid_nucleotides? # === only_valid_dna_nucleotides?
237
-
238
- require 'bioroebe/shell/fasta.rb'
239
- # ========================================================================= #
240
- # === to_genbank
241
- #
242
- # This method will generate, or rather output, the GenBank file format.
243
- # ========================================================================= #
244
- def to_genbank(
245
- this_sequence = dna_sequence_as_string?
246
- )
247
- if fasta?
248
- id = fasta?.sequence_id?
249
- # ======================================================================= #
250
- # bl $BIOROEBE/genbank/genbank_flat_file_format_generator.rb
251
- # ======================================================================= #
252
- _ = GenbankFlatFileFormatGenerator.new(this_sequence, :do_not_run_yet)
253
- _.use_this_as_id = id
254
- _.run
255
- elsif !this_sequence.empty?
256
- GenbankFlatFileFormatGenerator.new(this_sequence)
257
- else
258
- erev 'There does not seem to be any FASTA sequence assigned.'
259
- end
260
- end
261
-
262
- # ========================================================================= #
263
- # === config?
264
- # ========================================================================= #
265
- def config?
266
- @config
267
- end
268
-
269
- # ========================================================================= #
270
- # === find_shine_dalgarno_sequence
271
- #
272
- # Use this method to attempt to try and find a SD-sequence.
273
- # ========================================================================= #
274
- def find_shine_dalgarno_sequence(
275
- i = dna_sequence_as_string?
276
- )
277
- i.upcase! # Need to ensure upcased input.
278
- pure_sd_sequence = 'AGGAGGU'.dup
279
- if is_dna?
280
- pure_sd_sequence.tr!('U','T')
281
- end
282
- if i.nil?
283
- report_that_a_string_must_be_assigned_first
284
- else
285
- sd_sequence = steelblue(
286
- dna_padding(pure_sd_sequence, :no_spaces).lstrip
287
- )
288
- if i.include? 'T' # Assume that we have a DNA string rather than RNA.
289
- pure_sd_sequence = 'AGGAGGT'
290
- sd_sequence = steelblue(
291
- dna_padding(pure_sd_sequence, :no_spaces).lstrip
292
- )
293
- end
294
- if i.include? pure_sd_sequence
295
- erev "Yes, our string contains at least one Shine Dalgarno "\
296
- "(#{sd_sequence}#{rev}) sequence."
297
- n_sd_sequences = i.scan(/#{pure_sd_sequence}/).size.to_s
298
- erev 'We have found '+sfancy(n_sd_sequences)+rev+' instance(s) of '\
299
- 'Shine Dalgarno ('+sd_sequence+rev+') Sites.'
300
- erev 'We will next show the particular sequence in '\
301
- 'question ('+simp(pure_sd_sequence)+rev+').'
302
- # =================================================================== #
303
- # Next, try to find restriction enzymes that cut at the
304
- # Shine-Dalgarno site.
305
- # =================================================================== #
306
- try_to_find_restriction_enzymes_for(:shine_dalgarno)
307
- else
308
- erev "We did not find a Shine Dalgarno ("\
309
- "#{simp(sd_sequence)}#{rev}) sequence."
310
- end
311
- end
312
- end
313
-
314
- # ========================================================================= #
315
- # === raw_aminoacid_sequence?
316
- #
317
- # Reader method over the aminoacid sequence.
318
- # ========================================================================= #
319
- def raw_aminoacid_sequence?
320
- @internal_hash[:array_aminoacid_sequence].last
321
- end; alias aminoacids? raw_aminoacid_sequence? # === aminoacids? # def aminoacids?
322
- alias amino_acid_sequence? raw_aminoacid_sequence? # === amino_acid_sequence?
323
- alias aminoacid_sequence? raw_aminoacid_sequence? # === aminoacid_sequence?
324
- alias aa_sequence? raw_aminoacid_sequence? # === aa_sequence?
325
- alias aa? raw_aminoacid_sequence? # === aa?
326
-
327
- # ========================================================================= #
328
- # === codon
329
- #
330
- # This method will identify codons.
331
- #
332
- # Usage example from within the Shell:
333
- #
334
- # codon AAAGUCCAU
335
- #
336
- # ========================================================================= #
337
- def codon(
338
- i = sequence?
339
- )
340
- if i.is_a? Array # We don't want Arrays here.
341
- i = i.join.strip
342
- end
343
- if i.nil?
344
- i = sequence?
345
- else
346
- if i.is_a? String
347
- i = sequence? if i.empty?
348
- end
349
- end
350
- _ = nucleotides_to_aminoacid(i)
351
- erev _
352
- end; alias codons codon # === codons
353
- alias codon? codon # === codon?
354
- alias codons? codon # === codons?
355
-
356
- # ========================================================================= #
357
- # === calculate_atp_cost_for
358
- #
359
- # This method can be used to calculate the ATP cost in order to synthesize
360
- # a protein.
361
- # ========================================================================= #
362
- def calculate_atp_cost_for(i = aminoacid_sequence?)
363
- i = i.join.strip if i.is_a? Array
364
- if i.nil?
365
- i = aminoacid_sequence?
366
- end
367
- end
368
-
369
- # ========================================================================= #
370
- # === use_xsel?
371
- # ========================================================================= #
372
- def use_xsel?
373
- @internal_hash[:use_xsel]
374
- end
375
-
376
- # ========================================================================= #
377
- # === all_arguments?
378
- # ========================================================================= #
379
- def all_arguments?
380
- @internal_hash[:all_arguments]
381
- end; alias a? all_arguments? # === a?
382
- # alias a all_arguments? # === a
383
-
384
- require 'bioroebe/utility_scripts/check_for_mismatches/check_for_mismatches.rb'
385
- # ========================================================================= #
386
- # === check_for_mismatches
387
- # ========================================================================= #
388
- def check_for_mismatches
389
- CheckForMismatches.new
390
- end
391
-
392
- require 'bioroebe/toplevel_methods/nucleotides.rb'
393
- # ========================================================================= #
394
- # === only_nucleotides?
395
- #
396
- # Just a wrapper over the corresponding module-method.
397
- # ========================================================================= #
398
- def only_nucleotides?(i)
399
- ::Bioroebe.only_nucleotides?(i)
400
- end
401
-
402
- # ========================================================================= #
403
- # === exit_the_shell_how?
404
- # ========================================================================= #
405
- def exit_the_shell_how?
406
- @internal_hash[:exit_the_shell_how]
407
- end
408
-
409
- # ========================================================================= #
410
- # === do_quit (exit tag, quit tag)
411
- #
412
- # Consistently use this method when quitting from the shell. No
413
- # exception!
414
- #
415
- # On quitting, we may copy the bioroebe-files.
416
- #
417
- # We may either return a symbol, or we may simply call exit.
418
- # ========================================================================= #
419
- def do_quit(
420
- # ===================================================================== #
421
- # The variable that comes next is usually a Symbol.
422
- # ===================================================================== #
423
- determine_what_to_do = exit_the_shell_how?
424
- )
425
- # ======================================================================= #
426
- # We can also copy the content of the Bioroebe-Project - but I am
427
- # not sure if this is worth the trade-off, so it was disabled again.
428
- # ======================================================================= #
429
- # copy_bioroebe_shell_before_quitting
430
- # ======================================================================= #
431
- considering_changing_the_title_of_the_kde_konsole_tab('')
432
- case determine_what_to_do
433
- when :instantly
434
- :break
435
- else # This is valid for :exit_gracefully.
436
- return determine_what_to_do # Allo a graceful exit.
437
- end
438
- end
439
-
440
- # ========================================================================= #
441
- # === handle_this_file
442
- #
443
- # This method can be used to handle a file in general.
444
- # ========================================================================= #
445
- def handle_this_file(this_file)
446
- if File.exist?
447
- e File.read(this_file)
448
- end
449
- end
450
-
451
- # ========================================================================= #
452
- # === remove_question_mark?
453
- # ========================================================================= #
454
- def remove_question_mark?
455
- @internal_hash[:remove_last_character_if_it_is_a_question_mark]
456
- end
457
-
458
- # ========================================================================= #
459
- # === default_length?
460
- # ========================================================================= #
461
- def default_length?
462
- @internal_hash[:default_length]
463
- end
464
-
465
- # ========================================================================= #
466
- # === set_default_length
467
- # ========================================================================= #
468
- def set_default_length(
469
- i = DEFAULT_LENGTH_FOR_DNA, be_verbose = false
470
- )
471
- case be_verbose
472
- when :be_verbose
473
- be_verbose = true
474
- end
475
- if i.is_a? Array
476
- i = i.join(' ').strip
477
- end
478
- i = i.to_i
479
- if be_verbose
480
- erev 'Setting to a default length of `'+simp(i.to_s)+rev+'` next.'
481
- end
482
- @internal_hash[:default_length] = i
483
- end; alias set_maxlength set_default_length # === set_maxlength
484
-
485
- # ========================================================================= #
486
- # === second_argument?
487
- # ========================================================================= #
488
- def second_argument?
489
- @internal_hash[:all_arguments][1]
490
- end; alias second_argument second_argument? # === second_argument
491
-
492
- # ========================================================================= #
493
- # === initialize_clipboard
494
- # ========================================================================= #
495
- def initialize_clipboard
496
- begin
497
- require 'roebe/classes/clipboard.rb'
498
- rescue LoadError; end
499
- if Object.const_defined?(:Roebe) and
500
- Roebe.const_defined?(:Clipboard)
501
- @clipboard = Roebe::Clipboard.new
502
- else
503
- @clipboard = nil
504
- end
505
- end
506
-
507
- require 'bioroebe/version/version.rb'
508
- # ========================================================================= #
509
- # === version?
510
- # ========================================================================= #
511
- def version?
512
- ::Bioroebe.version
513
- end
514
-
515
- # ========================================================================= #
516
- # === silent_startup?
517
- # ========================================================================= #
518
- def silent_startup?
519
- @internal_hash and @internal_hash[:silent_startup]
520
- end
521
-
522
- # ========================================================================= #
523
- # === say_goodbye
524
- # ========================================================================= #
525
- def say_goodbye
526
- _ = ' '+version?.to_s
527
- _ = '' if _.size == 1
528
- erev "Bye from the BioShell#{_}!"
529
- end
530
-
531
- # ========================================================================= #
532
- # === set_raw_sequence
533
- # ========================================================================= #
534
- def set_raw_sequence(i)
535
- @internal_hash[:raw_sequence].assign(i)
536
- end
537
-
538
- # ========================================================================= #
539
- # === raw_sequence?
540
- # ========================================================================= #
541
- def raw_sequence?
542
- @internal_hash[:raw_sequence]
543
- end
544
-
545
- # ========================================================================= #
546
- # === adenin?
547
- #
548
- # This will return e. g. "C5H5N5".
549
- # ========================================================================= #
550
- def adenin?
551
- YAML.load_file(FILE_NUCLEOTIDES)['Adenin']
552
- end
553
-
554
- # ========================================================================= #
555
- # === thymin?
556
- # ========================================================================= #
557
- def thymin?
558
- YAML.load_file(FILE_NUCLEOTIDES)['Thymin']
559
- end
560
-
561
- # ========================================================================= #
562
- # === cytosin?
563
- # ========================================================================= #
564
- def cytosin?
565
- YAML.load_file(FILE_NUCLEOTIDES)['Cytosin']
566
- end
567
-
568
- # ========================================================================= #
569
- # === guanin?
570
- # ========================================================================= #
571
- def guanin?
572
- YAML.load_file(FILE_NUCLEOTIDES)['Guanin']
573
- end
574
-
575
- # ========================================================================= #
576
- # === weight_of_adenin?
577
- # ========================================================================= #
578
- def weight_of_adenin?
579
- ChemistryParadise::CalculateAtomicMass[adenin?].to_s.ljust(7,'0')
580
- end
581
-
582
- # ========================================================================= #
583
- # === weight_of_thymin?
584
- # ========================================================================= #
585
- def weight_of_thymin?
586
- ChemistryParadise::CalculateAtomicMass[thymin?].to_s.ljust(7,'0')
587
- end
588
-
589
- # ========================================================================= #
590
- # === weight_of_cytosin?
591
- # ========================================================================= #
592
- def weight_of_cytosin?
593
- ChemistryParadise::CalculateAtomicMass[cytosin?].to_s.ljust(7,'0')
594
- end
595
-
596
- # ========================================================================= #
597
- # === weight_of_guanin?
598
- # ========================================================================= #
599
- def weight_of_guanin?
600
- ChemistryParadise::CalculateAtomicMass[guanin?].to_s.ljust(7,'0')
601
- end
602
-
603
- # ========================================================================= #
604
- # === colourize_nucleotide
605
- #
606
- # Assemble 5'-sequence-3', with colours.
607
- # ========================================================================= #
608
- def colourize_nucleotide(
609
- i,
610
- add_leading_five_and_trailing_three_primes = true
611
- )
612
- case add_leading_five_and_trailing_three_primes
613
- # ======================================================================= #
614
- # === :do_not_add_anything_else
615
- # ======================================================================= #
616
- when :do_not_add_anything_else,
617
- :make_no_modifications
618
- add_leading_five_and_trailing_three_primes = false
619
- end
620
- if add_leading_five_and_trailing_three_primes
621
- leading_5_prime+
622
- sfancy(i)+
623
- rev+
624
- trailing_3_prime
625
- else
626
- sfancy(i)+
627
- rev
628
- end
629
- end; alias colourize_nucleotide_sequence colourize_nucleotide # === colourize_nucleotide_sequence
630
-
631
- # ========================================================================= #
632
- # === do_start_the_sinatra_interface
633
- # ========================================================================= #
634
- def do_start_the_sinatra_interface
635
- require 'bioroebe/requires/require_the_bioroebe_sinatra_components.rb'
636
- ::Bioroebe.start_sinatra_interface
637
- end
638
-
639
- require 'bioroebe/utility_scripts/punnet/punnet.rb'
640
- # ========================================================================= #
641
- # === punnet
642
- #
643
- # This method will show a Punnet square.
644
- # ========================================================================= #
645
- def punnet(i)
646
- ::Bioroebe::Punnet.new(i)
647
- end
648
-
649
- # ========================================================================= #
650
- # === mass_weight (mass_weight tag)
651
- #
652
- # This will calculate the weight of some Aminoacids.
653
- # ========================================================================= #
654
- def mass_weight(
655
- i = aminoacids?,
656
- be_verbose = true
657
- )
658
- if i.nil? and aminoacids?
659
- i = aminoacids?
660
- end
661
- if i.nil?
662
- erev 'Please first assign some aminoacids, like GGG.'
663
- else
664
- erev 'Now calculating the weight of `'+sfancy(i)+rev+'`.'
665
- e
666
- sum = 0
667
- i.split(//).each {|aminoacid|
668
- if aminoacid
669
- weight = ::Bioroebe::AMINO_ACIDS_MASS_TABLE[aminoacid]
670
- if be_verbose
671
- erev ' The weight for '+royalblue(aminoacid)+
672
- rev+
673
- ' is: '+
674
- sfancy(
675
- weight.to_s.ljust(6,'0').rjust(10)
676
- )+rev
677
- end
678
- sum += weight
679
- end
680
- }
681
- rounded_sum = sum.round
682
- n_aminoacids = i.to_s.chars.size
683
- erev ' The total sum of these '+simp(n_aminoacids)+rev+
684
- ' aminoacids (the raw weight) is: '+sfancy(rounded_sum.to_s)
685
- adjusted_value = sum - ((n_aminoacids - 1) * 18) # 18 for the H2O molecule.
686
- erev ' The adjusted value (including loss of water '\
687
- 'molecules in the peptide bonds) is: '+
688
- sfancy(adjusted_value.round(1).to_s)
689
- e
690
- end
691
- end
692
-
693
- # ========================================================================= #
694
- # === bisulfite
695
- # ========================================================================= #
696
- def bisulfite(i)
697
- return ::Bioroebe.bisulfite_treatment(i)
698
- end
699
-
700
- require 'bioroebe/utility_scripts/compseq/compseq.rb'
701
- # ========================================================================= #
702
- # === compseq
703
- #
704
- # Analyze a given sequence via compseq.
705
- # ========================================================================= #
706
- def compseq(i = dna_sequence?)
707
- i = dna_sequence? if i.nil?
708
- ::Bioroebe::Compseq.new(i) # bl $BIOROEBE/compseq.rb
709
- end
710
-
711
- require 'bioroebe/utility_scripts/move_file_to_its_correct_location.rb'
712
- # ========================================================================= #
713
- # === move_file_to_its_correct_location
714
- # ========================================================================= #
715
- def move_file_to_its_correct_location(i)
716
- ::Bioroebe::MoveFileToItsCorrectLocation.new(i)
717
- end
718
-
719
- require 'bioroebe/pdb/fetch_fasta_sequence_from_pdb.rb'
720
- # ========================================================================= #
721
- # === fetch_from_pdb
722
- #
723
- # This method can obtain a .pdb file from the pdb website.
724
- #
725
- # It can also return the aminoacid sequence.
726
- #
727
- # A URL for the .pdb may be available like this:
728
- #
729
- # https://files.rcsb.org/view/2BTS.pdb
730
- # https://files.rcsb.org/view/355D.pdb
731
- #
732
- # For the FASTA sequence, try:
733
- #
734
- # https://www.rcsb.org/fasta/entry/2BTS/display
735
- #
736
- # ========================================================================= #
737
- def fetch_from_pdb(i)
738
- if i.is_a? Array
739
- i = i.join(' ').strip
740
- end
741
- i.upcase!
742
- remote_url = 'https://www.rcsb.org/structure/'+i
743
- erev 'Looking for the protein called '+steelblue(i)+rev+
744
- 'at pdb next. (URL: '+royalblue(remote_url)+rev+')'
745
- e
746
- open_in_browser(remote_url)
747
- e
748
- remote_url_to_the_pdb_file = "https://files.rcsb.org/view/#{i}.pdb"
749
- esystem "wget #{remote_url_to_the_pdb_file}"
750
- e
751
- begin
752
- erev 'The fasta sequence, obtained from '+remote_url+', is:'
753
- e
754
- result = ::Bioroebe.return_fasta_sequence_from_this_pdb_file(remote_url)
755
- e result
756
- e
757
- set_aminoacid_sequence(result) # And assign it as well.
758
- rescue Exception => error
759
- pp error
760
- end
761
- # ======================================================================= #
762
- # The file may be without a .pdb entry, so rename it in that case.
763
- # ======================================================================= #
764
- target = File.basename(remote_url_to_the_pdb_file)
765
- if File.exist? target
766
- unless target.end_with? '.pdb'
767
- unless File.exist? target+'.pdb'
768
- new_location = target
769
- rename_file(i, new_location) unless File.exist?(new_location)
770
- target = new_location
771
- end
772
- end
773
- move_file_to_its_correct_location(target)
774
- end
775
- end
776
-
777
- # ========================================================================= #
778
- # === prepend
779
- #
780
- # You can use this to simply prepend to the main string.
781
- # ========================================================================= #
782
- def prepend(i)
783
- @sequence.prepend(i)
784
- end
785
-
786
- # ========================================================================= #
787
- # === ereturn
788
- # ========================================================================= #
789
- def ereturn(i = '')
790
- e i
791
- return
792
- end
793
-
794
- # ========================================================================= #
795
- # === open_expasy
796
- # ========================================================================= #
797
- def open_expasy(i = all_arguments?)
798
- _ = 'https://www.expasy.org/'
799
- open_in_browser(_)
800
- end
801
-
802
- require 'bioroebe/codons/codons.rb'
803
- # ========================================================================= #
804
- # === is_this_a_valid_codon?
805
- #
806
- # This method can determine whether the given input is a valid codon
807
- # or whether it is not.
808
- # ========================================================================= #
809
- def is_this_a_valid_codon?(i)
810
- ::Bioroebe.is_this_a_valid_codon?(i)
811
- end
812
-
813
- require 'bioroebe/toplevel_methods/file_and_directory_related_actions.rb'
814
- # ========================================================================= #
815
- # === chdir (cd tag)
816
- # ========================================================================= #
817
- def chdir(
818
- i = :default
819
- )
820
- if i and i.start_with?('cd ')
821
- i[0,3] = ''
822
- end
823
- case i
824
- # ======================================================================= #
825
- # === :home
826
- # ======================================================================= #
827
- when :home,
828
- ':home'
829
- i = log_dir?
830
- # ======================================================================= #
831
- # === :default
832
- # ======================================================================= #
833
- when :default,
834
- nil
835
- i = File.expand_path('~').to_s
836
- end
837
- if File.directory? i
838
- ::Bioroebe.change_directory(i)
839
- else
840
- e "No directory at #{sdir(File.absolute_path(i))}#{rev} "\
841
- "appears to exist."
842
- end
843
- end; alias cd chdir # === cd
844
-
845
- # ========================================================================= #
846
- # === shuffle_main_string
847
- #
848
- # This method will re-arrange the main DNA sequence.
849
- # ========================================================================= #
850
- def shuffle_main_string
851
- erev 'Shuffling the main DNA string next.'
852
- _ = dna_sequence?.split(//).shuffle.join
853
- set_dna_string(_, :be_quiet)
854
- show_dna_sequence
855
- end
856
-
857
- # ========================================================================= #
858
- # === load (load tag)
859
- #
860
- # This method will try to load from the given input, if this is an
861
- # existing file.
862
- # ========================================================================= #
863
- def load(
864
- i = file_dna_string_saved?
865
- )
866
- if i.nil?
867
- load(file_dna_string_saved?)
868
- # ======================================================================= #
869
- # === Handle Arrays
870
- # ======================================================================= #
871
- elsif i.is_a? Array
872
- if i.nil? or i.empty?
873
- load(file_dna_string_saved?) # Handle default input given.
874
- else # else batch-process the Array next:
875
- i.each {|entry| load(entry) }
876
- end
877
- else
878
- i = i.to_s
879
- # ===================================================================== #
880
- # Check for i being a number:
881
- # ===================================================================== #
882
- if i =~ /^\d+$/i
883
- entries = Dir['*']
884
- sorted_entries = entries.sort_by {|entry|
885
- File.basename(entry).downcase
886
- }
887
- i = sorted_entries[i.to_i - 1]
888
- erev "Using the file #{sfile(i)}.#{rev}"
889
- end
890
- if i
891
- if File.exist? i
892
- data = File.read(i).chomp
893
- assign_sequence data
894
- else
895
- erev 'Can not read from file '+sfile(i)+rev+
896
- ' as it does not exist.'
897
- end
898
- else
899
- load_my_file
900
- end
901
- end
902
- end; alias load_dataset_from load # === load_dataset_from
903
-
904
- # ========================================================================= #
905
- # === load_my_file (load tag)
906
- #
907
- # We will use this method to load the shell-file.
908
- # ========================================================================= #
909
- def load_my_file
910
- assign(save_file?, :do_not_upcase)
911
- end
912
-
913
- # ========================================================================= #
914
- # === is_a_stop_codon?
915
- # ========================================================================= #
916
- def is_a_stop_codon?(i)
917
- ::Bioroebe.is_a_stop_codon?(i)
918
- end
919
-
920
- require 'bioroebe/codons/show_codon_tables.rb'
921
- # ========================================================================= #
922
- # === print_aminoacid_information_table
923
- #
924
- # This method will give us as much information as possible about the
925
- # various different aminoacids in the assumed protein sequence at
926
- # hand.
927
- # ========================================================================= #
928
- def print_aminoacid_information_table
929
- show_mnemo
930
- e
931
- show_aminoacids_mass_table # This will also report the average weight of an aminoacid.
932
- e
933
- show_aminoacids_residues # Show all aminoacid residues (the "Reste").
934
- e
935
- display_all_aminoacids
936
- e
937
- end
938
-
939
- # ========================================================================= #
940
- # === permanently_disable_startup_intro
941
- #
942
- # This method can be used to permanently disable the startup intro.
943
- #
944
- # Invocation example:
945
- #
946
- # bioshell --permanently-disable-startup-intro
947
- #
948
- # ========================================================================= #
949
- def permanently_disable_startup_intro
950
- target_file = Bioroebe.project_base_dir?+
951
- 'shell/configuration/may_we_show_the_startup_information.yml'
952
- what = 'false'
953
- write_what_into(what, target_file)
954
- erev 'Storing into the file '+sfile(target_file)+rev+'.'
955
- if is_on_roebe?
956
- target_file = RUBY_SRC+
957
- 'bioroebe/lib/bioroebe/shell/configuration/may_we_show_the_startup_information.yml'
958
- write_what_into(what, target_file)
959
- erev 'Storing into the file '+sfile(target_file)+rev+'.'
960
- end
961
- end
962
-
963
- # ========================================================================= #
964
- # === may_we_show_the_startup_information?
965
- # ========================================================================= #
966
- def may_we_show_the_startup_information?
967
- @internal_hash[:may_we_show_the_startup_information]
968
- end
969
-
970
-
971
- # ========================================================================= #
972
- # === downcase_main_string (downcase tag, dcase tag)
973
- #
974
- # Use this method to downcase the main sequence.
975
- # ========================================================================= #
976
- def downcase_main_string
977
- downcased_sequence = seq?.downcase
978
- set_sequence(
979
- downcased_sequence
980
- )
981
- end
982
-
983
- # ========================================================================= #
984
- # === set_exit_gracefully
985
- # ========================================================================= #
986
- def set_exit_gracefully
987
- @internal_hash[:exit_the_shell_how] = :exit_gracefully
988
- end
989
-
990
- # ========================================================================= #
991
- # === try_to_compare_these_two_sequences_for_equality
992
- #
993
- # This method will compare two sequences for equality, e. g. will
994
- # return true or false, depending on whether they are equal or
995
- # not.
996
- #
997
- # nil will be returned if the method could not find the necessary
998
- # '==' characters.
999
- #
1000
- # Invocation example from within a running bio-shell:
1001
- #
1002
- # ATCGATCGATCG == ATCGATCG
1003
- #
1004
- # ========================================================================= #
1005
- def try_to_compare_these_two_sequences_for_equality(i)
1006
- i.strip!
1007
- if i.include? '=='
1008
- splitted = i.split('==').map(&:strip)
1009
- # ===================================================================== #
1010
- # Do the comparison next.
1011
- # ===================================================================== #
1012
- splitted.first == splitted.last
1013
- else
1014
- nil
1015
- end
1016
- end
1017
-
1018
-
1019
- # ========================================================================= #
1020
- # === set_padding
1021
- #
1022
- # This method allows us to set the default (left) padding that we may
1023
- # display for DNA strings.
1024
- # ========================================================================= #
1025
- def set_padding(
1026
- i = DEFAULT_PADDING,
1027
- be_verbose = :be_quiet
1028
- )
1029
- case be_verbose
1030
- when :be_quiet
1031
- be_verbose = false
1032
- when :be_verbose
1033
- be_verbose = true
1034
- end
1035
- case i.to_s
1036
- when /(\d{1,3})/
1037
- i = ' ' * $1.to_s.dup.to_i
1038
- when 'default'
1039
- i = DEFAULT_PADDING
1040
- end
1041
- if be_verbose
1042
- erev 'The new padding will have '+sfancy(i.count(' ').to_s)+rev+
1043
- ' space characters.'
1044
- end
1045
- @internal_hash[:padding] = i
1046
- end
1047
-
1048
- # ========================================================================= #
1049
- # === padding? (padding tag)
1050
- # ========================================================================= #
1051
- def padding?
1052
- @internal_hash[:padding]
1053
- end; alias pad padding? # === pad
1054
- alias pad? padding? # === pad?
1055
- alias lpad? padding? # === lpad?
1056
- alias left_pad? padding? # === left_pad?
1057
- alias left_padding? padding? # === left_padding?
1058
- alias default_padding padding? # === default_padding
1059
-
1060
-
1061
- # ========================================================================= #
1062
- # === efancy
1063
- # ========================================================================= #
1064
- def efancy(i)
1065
- e sfancy(i)
1066
- end
1067
-
1068
- # ========================================================================= #
1069
- # === list
1070
- # ========================================================================= #
1071
- def list(i = nil)
1072
- case i
1073
- # ======================================================================= #
1074
- # === list ages
1075
- # ======================================================================= #
1076
- when /^age/
1077
- erev 'We will next list the maximum age of different organisms.'
1078
- if File.exist? BIO_LANG
1079
- hash_results = {}
1080
- dataset = File.read(BIO_LANG)
1081
- n_entries = dataset.scan(/ max_age: /).count
1082
- name_of_organism = ''
1083
- dataset.split(N).each {|line|
1084
- next if line.start_with? '#'
1085
- next if line.empty?
1086
- unless line.start_with?(' ')
1087
- name_of_organism = line.delete(':').strip
1088
- end
1089
- if line.include? ' max_age: '
1090
- its_max_age = line.gsub(/max_age:/,'').strip
1091
- if its_max_age.include? '#'
1092
- its_max_age = its_max_age[0, its_max_age.index('#')]
1093
- end
1094
- its_max_age.strip!
1095
- its_max_age << ' years' unless its_max_age.end_with? 'years'
1096
- hash_results[name_of_organism] = its_max_age
1097
- end
1098
- }
1099
- erev 'We did find '+sfancy(n_entries.to_s)+' results.'
1100
- e
1101
- hash_results.sort_by {|value, key| key }.reverse.each { |name, age|
1102
- erev ' '+(name+':').ljust(30)+' '+sfancy(age.rjust(12))
1103
- }; e # Trailing newline looks nice.
1104
- end
1105
- end
1106
- end
1107
-
1108
- # ========================================================================= #
1109
- # === toggle_mode
1110
- # ========================================================================= #
1111
- def toggle_mode
1112
- if @internal_hash[:mode] == :dna
1113
- set_mode(:aminoacid)
1114
- else
1115
- set_mode(:dna)
1116
- end
1117
- end
1118
-
1119
- # ========================================================================= #
1120
- # === report_syntax_help_for_frameshift_action
1121
- # ========================================================================= #
1122
- def report_syntax_help_for_frameshift_action
1123
- erev 'You can provide these options for the frameshifting menu:'
1124
- erev ' +1'
1125
- erev ' +2'
1126
- erev ' +3'
1127
- erev ' all'
1128
- end
1129
-
1130
- # ========================================================================= #
1131
- # === include?
1132
- #
1133
- # This can be used to check if we include a string or not.
1134
- # ========================================================================= #
1135
- def include?(i)
1136
- _ = dna_string?
1137
- if _
1138
- if _.include? i
1139
- erev 'Yes, we found it. It is at:'
1140
- pp _.scan(/#{i}/)
1141
- else
1142
- erev 'No, we did not find it.'
1143
- end
1144
- else
1145
- erev 'It seems as if you yet have not defined a main string.'
1146
- erev 'Please do so first, via assign() or random().'
1147
- end
1148
- end
1149
-
1150
- # ========================================================================= #
1151
- # === efetch
1152
- #
1153
- # Invocation example:
1154
- #
1155
- # efetch https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=nuccore&id=189458859&rettype=fasta&retmode=text
1156
- #
1157
- # ========================================================================= #
1158
- def efetch(i)
1159
- if i.is_a? Array
1160
- i.each {|entry| efetch(entry) }
1161
- else
1162
- ::Bioroebe::Ncbi.efetch_by_url(i)
1163
- end
1164
- end
1165
-
1166
- # ========================================================================= #
1167
- # === generate_palindrome
1168
- #
1169
- # This method will generate a Palindrome sequence.
1170
- # ========================================================================= #
1171
- def generate_palindrome(i)
1172
- i = i.join.strip if i.is_a? Array
1173
- ::Bioroebe::PalindromeGenerator.new(i).report
1174
- end
1175
-
1176
- # ========================================================================= #
1177
- # === is_palindrome?
1178
- # ========================================================================= #
1179
- def is_palindrome?(i)
1180
- erev ::Bioroebe.is_palindrome?(i) # is_palindrome? GATC
1181
- end
1182
-
1183
- # ========================================================================= #
1184
- # === discover_all_palindromes
1185
- #
1186
- # We need to discover all palindromes. For this, we need a
1187
- # min and a max value.
1188
- # ========================================================================= #
1189
- def discover_all_palindromes(
1190
- i = dna_sequence?,
1191
- min = 4,
1192
- max = 10
1193
- )
1194
- i = dna_sequence? unless i
1195
- case i # case tag
1196
- when 'default',
1197
- ':default'
1198
- i = dna_sequence?
1199
- end
1200
- @array_palindromes = [] # We store the Palindromes in this Array.
1201
- n_times = i.size
1202
-
1203
- min.upto(max) {|length|
1204
- # ===================================================================== #
1205
- # First, iterate by starting over the min value.
1206
- # ===================================================================== #
1207
- n_times.times {|counter|
1208
- possible_palindrome_sequence = i[counter, length]
1209
- counter += 1 # Adding +1 because nucleotides start at 1, not 0.
1210
- if ::Bioroebe.is_palindrome?(possible_palindrome_sequence) and
1211
- (possible_palindrome_sequence.size >= length)
1212
- @array_palindromes << [possible_palindrome_sequence, counter]
1213
- end
1214
- }
1215
- }
1216
- e; e 'Starting nucleotide | Palindrome sequence'; e
1217
- @array_palindromes.each {|array|
1218
- index_position = array.last
1219
- nucleotides = array.first
1220
- erev ' '+index_position.to_s.rjust(3)+' '+
1221
- nucleotides+' ('+swarn(nucleotides.size.to_s)+rev+')'
1222
- }; e
1223
- end
1224
-
1225
- # ========================================================================= #
1226
- # === mutate_position
1227
- #
1228
- # This method can be used to mutate DNA at a specific position.
1229
- #
1230
- # Usage example:
1231
- #
1232
- # random 50; mutate_position 5 C
1233
- # random 15; mutate_position 1
1234
- #
1235
- # ========================================================================= #
1236
- def mutate_position(
1237
- nucleotide_position,
1238
- mutate_to_this_nucleotide = return_random_nucleotide # Return randomly A, T, C or G here.
1239
- )
1240
- if nucleotide_position.is_a?(String) and nucleotide_position.strip.include?(' ')
1241
- nucleotide_position = nucleotide_position.split(' ')
1242
- end
1243
- # ======================================================================= #
1244
- # === Handle Arrays as input next
1245
- # ======================================================================= #
1246
- if nucleotide_position.is_a? Array # Assume that the user wanted to use things differently then.
1247
- mutate_to_this_nucleotide = nucleotide_position[1]
1248
- nucleotide_position = nucleotide_position[0]
1249
- end
1250
- old_sequence = dna_sequence?
1251
- do_mutate_dna_sequence_at_this_nucleotide_position(
1252
- nucleotide_position,
1253
- old_sequence,
1254
- mutate_to_this_nucleotide
1255
- )
1256
- show_dna_sequence
1257
- end
1258
-
1259
- # ========================================================================= #
1260
- # === mutate_aminoacid_position
1261
- #
1262
- # This method will allow us to mutate the aminoacid sequence.
1263
- #
1264
- # Full usage example:
1265
- # random 24; show_aminoacid_sequence; mutate_aminoacid_position 1
1266
- # ========================================================================= #
1267
- def mutate_aminoacid_position(this_position = 1)
1268
- if this_position.is_a? Array
1269
- this_position = this_position.join.strip
1270
- end
1271
- this_position = this_position.to_i
1272
- sequence = aa_sequence?
1273
- new_aminoacid = return_random_aminoacid
1274
- old_aminoacid = sequence[this_position-1, 1]
1275
- erev 'We will mutate the aminoacid sequence at position '+
1276
- simp(this_position.to_s)+rev+'. The old aminoacid '
1277
- erev 'was '+simp(old_aminoacid)+rev+', the new aminoacid will '\
1278
- 'be '+simp(new_aminoacid)+rev+'.'
1279
- sequence[this_position-1, 1] = new_aminoacid
1280
- show_aminoacid_sequence
1281
- end
1282
-
1283
- # ========================================================================= #
1284
- # === n_uracil?
1285
- # ========================================================================= #
1286
- def n_uracil?
1287
- erev sequence_object?.n_uracil?
1288
- end
1289
-
1290
- # ========================================================================= #
1291
- # === set_start_codon
1292
- #
1293
- # If you wish to use another start codon, this is the right method.
1294
- # ========================================================================= #
1295
- def set_start_codon(i = nil)
1296
- i = i.to_s
1297
- i.tr!('U','T')
1298
- if i.empty?
1299
- erev 'Please assign a non-empty start codon.'
1300
- else
1301
- erev 'Setting to use this as start codon next: '+
1302
- simp(i)
1303
- ::Bioroebe.set_start_codon(i)
1304
- end
1305
- end
1306
-
1307
- # ========================================================================= #
1308
- # === first
1309
- # ========================================================================= #
1310
- def first(i)
1311
- if i.to_s =~ /^\d+$/ # If the input is only numbers
1312
- erev 'Obtaining the first '+simp(i).to_s+rev+' nucleotides next:'
1313
- erev simp(seq?[0,i.to_i])
1314
- else # Else change the first nucleotide.
1315
- change_first_nucleotide_to(f)
1316
- end
1317
- end
1318
-
1319
- # ========================================================================= #
1320
- # === attempt_to_discover_dna_A_boxes
1321
- # ========================================================================= #
1322
- def attempt_to_discover_dna_A_boxes
1323
- dna_A_box_sequence = 'TTATCCACA'
1324
- erev 'The dnaA box in E. coli has this consensus sequence:'
1325
- e
1326
- efancy " #{dna_A_box_sequence}#{rev}"
1327
- e
1328
- unless string?.empty?
1329
- results = string?.scan(/#{dna_A_box_sequence}/)
1330
- if results.empty?
1331
- erev 'The given DNA sequence does not contain any dnaA sequence elements.'
1332
- else
1333
- erev 'This sequence can be found '+simp(results.size.to_s)+rev+' times.'
1334
- pp results
1335
- end
1336
- end if dna_sequence?
1337
- end
1338
-
1339
- # ========================================================================= #
1340
- # === run_sql_query
1341
- # ========================================================================= #
1342
- def run_sql_query(
1343
- i,
1344
- be_verbose = true,
1345
- optional_append_this = ''
1346
- )
1347
- ::Bioroebe.run_sql_query(i, be_verbose, optional_append_this)
1348
- end; alias sql_query run_sql_query # === sql_query
1349
- alias run_query run_sql_query # === run_query
1350
- alias run_sql run_sql_query # === run_sql
1351
- alias sqlq sql_query # === sqlq
1352
-
1353
- # ========================================================================= #
1354
- # === return_available_vectors
1355
- # ========================================================================= #
1356
- def return_available_vectors
1357
- Dir[::Bioroebe.log_dir?+'vector_*']
1358
- end
1359
-
1360
- # ========================================================================= #
1361
- # === check_for_local_vectors
1362
- # ========================================================================= #
1363
- def check_for_local_vectors
1364
- _ = return_available_vectors
1365
- unless _.empty? # Silent assignment comes next.
1366
- set_sequence_2(::Bioroebe::Sequence.sequence_from_file(_.first))
1367
- end
1368
- end
1369
-
1370
- # ========================================================================= #
1371
- # === find_restriction_sites
1372
- #
1373
- # Call the parent method in the Bioroebe class.
1374
- # ========================================================================= #
1375
- def find_restriction_sites(i = string?)
1376
- i = string? if i.nil?
1377
- Bioroebe.restriction_sites?(i) # bl mybioruby
1378
- end
1379
-
1380
- # ========================================================================= #
1381
- # === do_mutate_dna_sequence_at_this_nucleotide_position
1382
- #
1383
- # You can use this method to mutate a DNA sequence at a given position.
1384
- #
1385
- # The first argument should be the specific nucleotide position that
1386
- # you wish to modify. Keep in mind that in BioRoebe we will start to
1387
- # count at nucleotide position 1; in ruby Arrays, we would start to
1388
- # count at position 0 but DNA sequences don't have a nucleotide called
1389
- # 0 by definition, hence why we use a more (bio)logical way that
1390
- # makes more sense.
1391
- #
1392
- # Usage example:
1393
- #
1394
- # random 15; mutate 1
1395
- #
1396
- # ========================================================================= #
1397
- def do_mutate_dna_sequence_at_this_nucleotide_position(
1398
- this_nucleotide_position = 1,
1399
- new_nucleotide = nil,
1400
- old_sequence = dna_sequence?
1401
- )
1402
- if this_nucleotide_position.is_a? Array
1403
- new_nucleotide = this_nucleotide_position[1] if this_nucleotide_position.size > 1
1404
- this_nucleotide_position = this_nucleotide_position.first
1405
- end
1406
- # ======================================================================= #
1407
- # === this_nucleotide_position must be a Fixnum past that point
1408
- # ======================================================================= #
1409
- this_nucleotide_position = this_nucleotide_position.to_i
1410
- if this_nucleotide_position < 1
1411
- this_nucleotide_position = 1 # 1 is minimum.
1412
- end
1413
- old_nucleotide = old_sequence[this_nucleotide_position-1, 1]
1414
- unless new_nucleotide # Enter this clause if new_nucleotide is nil.
1415
- new_nucleotide = (DNA_NUCLEOTIDES - [old_nucleotide]).sample # Obtain a random but different nucleotide.
1416
- end
1417
- erev 'At nucleotide position '+sfancy(this_nucleotide_position.to_s)+
1418
- rev+' we will replace '+simp(old_nucleotide)+rev+' with '+
1419
- simp(new_nucleotide)+rev+'.'
1420
- old_sequence[this_nucleotide_position-1, 1] = new_nucleotide
1421
- set_dna_sequence(old_sequence) # We'll also assign this.
1422
- end
1423
-
1424
- # ========================================================================= #
1425
- # === mutate_dna_sequence
1426
- #
1427
- # Use this method to mutate a DNA nucleotide.
1428
- # ========================================================================= #
1429
- def mutate_dna_sequence(
1430
- n_times = 1,
1431
- old_sequence = dna_sequence?
1432
- )
1433
- if n_times.is_a? Array
1434
- n_times = n_times.join(' ').strip.to_i
1435
- end
1436
- n_times = n_times.to_i
1437
- n_times.times {
1438
- this_nucleotide_position = rand(old_sequence.size)+1
1439
- do_mutate_dna_sequence_at_this_nucleotide_position(
1440
- this_nucleotide_position, old_sequence
1441
- )
1442
- show_dna_sequence
1443
- }
1444
- end
1445
-
1446
- # ========================================================================= #
1447
- # === align_ORFS
1448
- #
1449
- # This method is used to align all intrinsic ORFs of agiven sequence.
1450
- #
1451
- # We delegate into class AlignOpenReadingFrames for the output.
1452
- # ========================================================================= #
1453
- def align_ORFS(i = dna_string?)
1454
- i = dna_string? if i.nil?
1455
- ::Bioroebe::AlignOpenReadingFrames.new(i) # bl $BIOROEBE/align_open_reading_frames.rb
1456
- end
1457
-
1458
- # ========================================================================= #
1459
- # === calculate_hamming_distance_of
1460
- #
1461
- # We will delegate into class HammingDistance here.
1462
- #
1463
- # The argument to this method should ideally be an Array.
1464
- #
1465
- # To test this method, do:
1466
- # hamming AGUUCGAUGG AGUCCGGUCG
1467
- # hamming AGUUCGAUGGGGGGGTTT AGUCCGGUCGGGG
1468
- # random 100; setseq2 hamming 1 2
1469
- # ========================================================================= #
1470
- def calculate_hamming_distance_of(i)
1471
- if i.is_a? String
1472
- if i.include? ' ' and i =~ /^\d+/ # The String could be "1 3" here, for instance.
1473
- splitted = i.split(' ').map(&:strip)
1474
- case splitted.size
1475
- when 2 # If we have at least 2 entries.
1476
- splitted[-1] = return_sequence_from_this_number(splitted[-1])
1477
- splitted[0] = return_sequence_from_this_number(splitted[0])
1478
- i = splitted.join(' ')
1479
- end
1480
- end
1481
- end
1482
- ::Bioroebe::HammingDistance[i] # bl $BIOROEBE/hamming*rb
1483
- end
1484
-
1485
- # ========================================================================= #
1486
- # === get_long_name_of_amino_acid
1487
- # ========================================================================= #
1488
- def get_long_name_of_amino_acid(i)
1489
- amino_acids_table = AMINO_ACIDS
1490
- if amino_acids_table.has_key? i
1491
- _ = amino_acids_table[i]
1492
- key = _.keys.select {|inner_key| inner_key.size == 3 }[0]
1493
- i = _[key].to_s
1494
- end
1495
- return i
1496
- end
1497
-
1498
- # ========================================================================= #
1499
- # === verbose_report_numbered_amino_acid_sequence
1500
- #
1501
- # This method can be used to show a verbose and properly-aligned
1502
- # frame shift table for the given aminoacid sequence.
1503
- # ========================================================================= #
1504
- def verbose_report_numbered_amino_acid_sequence(
1505
- i,
1506
- which_frame = '1'
1507
- )
1508
- n_chunks = ::Bioroebe::Configuration.n_chunks?
1509
- erev 'The amino acid sequence, with numbers and split into chunks '\
1510
- 'of '+plum(n_chunks.to_s)+rev+', for '+
1511
- sfancy('Frame '+which_frame.to_s)+rev+' is: '
1512
- e # Newline is good.
1513
- chars = i.chars
1514
- # ======================================================================= #
1515
- # Split into lines of 40, or rather what value was given to n_chunks.
1516
- # ======================================================================= #
1517
- slice = chars.each_slice(n_chunks).to_a
1518
- position = 1
1519
- slice.each {|array|
1520
- print ' '
1521
- array.each {|char|
1522
- char = char.rjust(3)
1523
- char = ::Bioroebe.colourize_aa(char)
1524
- print rev+char+rev+swarn('|')+rev
1525
- }; e # Do a newline for good measure.
1526
- print ' ' # Always have two ' ' before a new line.
1527
- # ===================================================================== #
1528
- # === Show the position of the aminoacid next
1529
- # ===================================================================== #
1530
- array.size.times {
1531
- print forestgreen(position.to_s.rjust(3))+rev+swarn('|')+rev
1532
- position += 1
1533
- }
1534
- e; e
1535
- }
1536
- e
1537
- end
1538
-
1539
- # ========================================================================= #
1540
- # === uncolourize_this_aminoacid
1541
- # ========================================================================= #
1542
- def uncolourize_this_aminoacid(i)
1543
- if i.nil?
1544
- erev 'Please supply an argument, an aminoacid. Either one '\
1545
- 'letter or the full name.'
1546
- return
1547
- end
1548
- unless ::Bioroebe.array_colourize_this_aminoacid.include? i
1549
- erev 'We will no longer colourize the '\
1550
- 'aminoacid `'+swarn(i)+'`.'
1551
- ::Bioroebe.array_colourize_this_aminoacid.delete i # Using .delete() works here.
1552
- end
1553
- end
1554
-
1555
- # ========================================================================= #
1556
- # === colourize_this_aminoacid
1557
- #
1558
- # Use this method to colourize any particular aminoacid.
1559
- #
1560
- # This should make it easier to detect special aminoacids.
1561
- # ========================================================================= #
1562
- def colourize_this_aminoacid(i)
1563
- if i.nil?
1564
- erev 'Please supply an argument, an aminoacid. Either one letter, '\
1565
- 'such as A for Alanine, or the full name.'
1566
- return
1567
- end
1568
- unless ::Bioroebe.array_colourize_this_aminoacid.include? i
1569
- erev 'We will now colourize the aminoacid `'+swarn(i)+'`.'
1570
- ::Bioroebe.array_colourize_this_aminoacid << i
1571
- end
1572
- end
1573
-
1574
- # ========================================================================= #
1575
- # === add_vertical_barrier_to_sequence
1576
- #
1577
- # This will turn a sequence such as "ATGCCC" into "ATG|CCC".
1578
- #
1579
- # Invocation example:
1580
- #
1581
- # barrier ATGCCC
1582
- #
1583
- # ========================================================================= #
1584
- def add_vertical_barrier_to_sequence(
1585
- i = dna_sequence?
1586
- )
1587
- i = i.join if i.is_a? Array
1588
- i = dna_sequence? if i.nil?
1589
- splitted = i.scan(/.../)
1590
- joined = splitted.join('|')
1591
- e joined
1592
- end
1593
-
1594
- # ========================================================================= #
1595
- # === obtain_url_for
1596
- # ========================================================================= #
1597
- def obtain_url_for(i)
1598
- ::Bioroebe.try_to_pass_through_beautiful_url(i)
1599
- end
1600
-
1601
- # ========================================================================= #
1602
- # === set_locus
1603
- # ========================================================================= #
1604
- def set_locus(i)
1605
- i = i.join(' ').strip if i.is_a? Array
1606
- @locus = i
1607
- end
1608
-
1609
- # ========================================================================= #
1610
- # === identify_aminoacid
1611
- #
1612
- # This method will also display the long name of the aminoacid at hand.
1613
- #
1614
- # Note that you can also identify a batch of aminoacids, by using the
1615
- # '-' character.
1616
- #
1617
- # Example for this:
1618
- #
1619
- # identify_aminoacid A-Z
1620
- #
1621
- # We will ignore invalid aminoacids though.
1622
- # ========================================================================= #
1623
- def identify_aminoacid(i)
1624
- if i.is_a? Array
1625
- i.flatten!
1626
- if i.any? {|inner_entry| inner_entry.include? '-'}
1627
- # =================================================================== #
1628
- # In this case, at the least one entry has a '-' Range component.
1629
- # So we must substitute there.
1630
- # =================================================================== #
1631
- i.map! {|most_inner_entry|
1632
- if most_inner_entry.include?('-')
1633
- # =============================================================== #
1634
- # Assume a Range in this case and prepare it accordingly.
1635
- # =============================================================== #
1636
- chars = most_inner_entry.chars
1637
- start_position = chars.first
1638
- end_position = chars.last
1639
- most_inner_entry = (start_position .. end_position).to_a
1640
- most_inner_entry = strict_filter_away_invalid_aminoacids(most_inner_entry)
1641
- most_inner_entry
1642
- end
1643
- most_inner_entry
1644
- }
1645
- end
1646
- # ===================================================================== #
1647
- # Recursively call the method if the input is an Array.
1648
- # ===================================================================== #
1649
- i.flatten!
1650
- e; i.each {|entry|
1651
- identify_aminoacid(entry)
1652
- }; e
1653
- else # else assume a String.
1654
- _ = ::Bioroebe::AMINO_ACIDS_MASS_TABLE
1655
- if i.empty?
1656
- erev 'Please supply at the least one character '\
1657
- '(aminoacid one letter code).'
1658
- elsif _.has_key? i
1659
- long_name_of_the_aminoacid = FILE_AMINO_ACIDS_ENGLISH[i]
1660
- erev i.ljust(3)+' ('+sfancy(long_name_of_the_aminoacid)+
1661
- rev+') corresponds to a molecular weight of '+
1662
- simp(_[i])+rev+' Dalton.'
1663
- else
1664
- erev "Did not find `#{simp(i)}`."
1665
- end
1666
- end
1667
- end
1668
-
1669
- # ========================================================================= #
1670
- # === compare_two_strings_as_alignment
1671
- #
1672
- # This allows us to interactively compare two strings.
1673
- # ========================================================================= #
1674
- def compare_two_strings_as_alignment(
1675
- string1 = nil,
1676
- string2 = nil
1677
- )
1678
- if string1 and string2
1679
- # Simply pass through in this case.
1680
- else
1681
- erev 'You desire to compare two strings.'
1682
- e
1683
- erev 'Please input the '+palegreen('first')+rev+' string/sequence now:'
1684
- print ' '
1685
- if has_readline?
1686
- string1 = Readline.readline
1687
- else
1688
- string1 = $stdin.gets.chomp
1689
- end
1690
- erev 'Please input the '+palegreen('second')+rev+' string now:'
1691
- print ' '
1692
- if has_readline?
1693
- string2 = Readline.readline
1694
- else
1695
- string2 = $stdin.gets.chomp
1696
- end
1697
- end
1698
- # ======================================================================= #
1699
- # Delegate into class SimpleStringComparer next.
1700
- # ======================================================================= #
1701
- _ = ::Bioroebe::SimpleStringComparer.new(:dont_run_yet) { :use_vertical_bar } # bl $BIOROEBE/string_matching/simple_string_comparer.rb
1702
- _.string1 = string1
1703
- _.string2 = string2
1704
- _.compare
1705
- end
1706
-
1707
- # ========================================================================= #
1708
- # === clear
1709
- #
1710
- # Functionality that is associated with clearing something, can be
1711
- # stored here.
1712
- #
1713
- # Usage example:
1714
- #
1715
- # clear highlighting
1716
- #
1717
- # ========================================================================= #
1718
- def clear(i)
1719
- if i.is_a? Array
1720
- i = i.join(' ').strip
1721
- end
1722
- case i
1723
- when /^highlight/
1724
- e 'Clearing all highlighting next.'
1725
- set_highlight_colour nil
1726
- end
1727
- end
1728
-
1729
- # ========================================================================= #
1730
- # === add_timer_snapshot
1731
- # ========================================================================= #
1732
- def add_timer_snapshot
1733
- array_timer_snapshots? << Time.now
1734
- end
1735
-
1736
- # ========================================================================= #
1737
- # === array_timer_snapshots?
1738
- # ========================================================================= #
1739
- def array_timer_snapshots?
1740
- @internal_hash[:array_timer_snapshots]
1741
- end
1742
-
1743
- # ========================================================================= #
1744
- # === calculate_time_difference
1745
- # ========================================================================= #
1746
- def calculate_time_difference
1747
- (@internal_hash[:array_timer_snapshots][-2] - @internal_hash[:array_timer_snapshots][-1])
1748
- end
1749
-
1750
- # ========================================================================= #
1751
- # === extract_sequence_from_this_file
1752
- #
1753
- # Use this method to extract a DNA sequence from the given file.
1754
- #
1755
- # The given input should thus, logically, be an existing (local)
1756
- # file.
1757
- #
1758
- # Currently this works via genbank .gb files but in the future,
1759
- # other formats may well be supported too.
1760
- # ========================================================================= #
1761
- def extract_sequence_from_this_file(i)
1762
- if i.is_a? Array
1763
- i.each {|entry| extract_sequence_from_this_file(entry) }
1764
- else
1765
- if File.exist? i
1766
- extname = File.extname(i).delete('.')
1767
- case extname
1768
- when 'gb'
1769
- # =================================================================== #
1770
- # Handle genbank .gb files here.
1771
- # =================================================================== #
1772
- _ = ::Bioroebe::GenbankParser.new(i) { :do_not_report_anything }
1773
- assign_sequence(_.sequence?)
1774
- end
1775
- else
1776
- no_file_exists_at(i)
1777
- end
1778
- end
1779
- end; alias extract_sequence extract_sequence_from_this_file # === extract_sequence
1780
-
1781
- # ========================================================================= #
1782
- # === coding_area?
1783
- #
1784
- # Query method over the "coding area" that we will focus on. So for
1785
- # example, if we have 100 nucleotides, but the coding area says 3-34,
1786
- # then we will only care for the nucleotides starting at position 3
1787
- # and ending at position 34.
1788
- # ========================================================================= #
1789
- def coding_area?
1790
- @internal_hash[:coding_area]
1791
- end
1792
-
1793
- # ========================================================================= #
1794
- # === add_his_tag
1795
- #
1796
- # This method can be used to add a his tag. By default we will add 6
1797
- # Histidin tags in succession. This pattern is commonly found in expression
1798
- # vectors.
1799
- #
1800
- # These histidin tags will be randomly placed within the DNA sequence,
1801
- # by default. Note that CAT and CAC code for Histidin. In most vectors,
1802
- # there is an alternation between these codons.
1803
- # ========================================================================= #
1804
- def add_his_tag(i = 'add 6 random his tags')
1805
- n_his_tags_to_add = i.scan(/\d+/).first
1806
- position = rand(main_sequence?.size)+1
1807
- e 'Next adding '+sfancy(n_his_tags_to_add)+rev+
1808
- ' Histidin tags to our main sequence at nucleotide '\
1809
- 'position '+sfancy(position.to_s)+rev+'.'
1810
- _ = main_sequence?
1811
- _.insert_at_this_position(
1812
- position+1, 'CAC|CAT|CAC|CAT|CAC|CAT' # Insert the His tag here.
1813
- )
1814
- assign_this_dna_sequence(_.to_str)
1815
- end
1816
-
1817
- # ========================================================================= #
1818
- # === shorten_aminoacid
1819
- #
1820
- # This method will translate an Aminoacid from Lys to K.
1821
- #
1822
- # Usage example:
1823
- #
1824
- # shorten Lys Val His His Leu Met Ala Ala Lys
1825
- #
1826
- # ========================================================================= #
1827
- def shorten_aminoacid(
1828
- these_aminoacids = aminoacid_sequence?
1829
- )
1830
- unless these_aminoacids
1831
- erev 'Please either assign an aminoacid sequence prior to invoking'
1832
- erev 'this method or simply pass in the aminoacids that you wish'
1833
- erev 'to short. Example:'
1834
- erev ' shorten Lys Val His'
1835
- return
1836
- end
1837
- erev N+'Now translating three letter Aminoacid to their one '\
1838
- 'letter representation: '+N+' '+sfancy(these_aminoacids)+rev+N
1839
- if these_aminoacids.include? ' '
1840
- these_aminoacids.delete!(' ') # get rid of ' '
1841
- end
1842
- if these_aminoacids.include? '-'
1843
- these_aminoacids = sanitize_input(these_aminoacids)
1844
- end
1845
- # ========================================================================= #
1846
- # Instantiate a new Bioroebe object next.
1847
- # ========================================================================= #
1848
- @bioroebe = ::Bioroebe.new(these_aminoacids)
1849
- erev ' '+@bioroebe.three_to_one+N
1850
- _ = @bioroebe.three_to_one
1851
- e
1852
- erev 'Next we will show the available codons for these aminoacids:'
1853
- e
1854
- _.scan(/./).each { |f|
1855
- erev ' '+f+' -> '+
1856
- '['+@bioroebe.aminoacid_to_codon(f).join(', ')+']'
1857
- }
1858
- e
1859
- end
1860
-
1861
- # ========================================================================= #
1862
- # === translate_aminoacid
1863
- #
1864
- # Translate aminoacids from one letter to full name.
1865
- #
1866
- # Usage example:
1867
- #
1868
- # translate kkrnn
1869
- #
1870
- # ========================================================================= #
1871
- def translate_aminoacid(
1872
- these_aminoacids = string?,
1873
- be_verbose = true
1874
- )
1875
- these_aminoacids = string? if these_aminoacids.nil?
1876
- if these_aminoacids.include? ','
1877
- these_aminoacids.delete!(',')
1878
- end
1879
- if these_aminoacids == '?'
1880
- erev 'Help requested:' # The user requested help here.
1881
- erev ' '+sfancy('-> ')+rev+'Simply input some AminoAcids here.'
1882
- erev ' '+sfancy('-> ')+rev+'for instance, "translate kkrrr".'
1883
- else
1884
- if these_aminoacids
1885
- these_aminoacids = these_aminoacids.join(' ') if these_aminoacids.is_a? Array
1886
- these_aminoacids.gsub!(/#{N}/,'')
1887
- _ = these_aminoacids.gsub(/ /,'').upcase
1888
- if be_verbose
1889
- erev 'Now translating one letter Aminoacid to '\
1890
- 'their full names: '
1891
- print ' '+these_aminoacids.upcase
1892
- end
1893
- _ = ::Bioroebe.translate(_)
1894
- if use_colours?
1895
- _ = sienna(_) if Object.const_defined? :Colours
1896
- end
1897
- erev ' -> '+_ # Invoke .translate if be_verbose
1898
- return _
1899
- end
1900
- end
1901
- end
1902
-
1903
- # ========================================================================= #
1904
- # === to_dna
1905
- # ========================================================================= #
1906
- def to_dna(i = sequence?)
1907
- if i.nil?
1908
- if seq?
1909
- i = seq?
1910
- elsif aminoacids? # Handle Aminoacids here.
1911
- i = aminoacids?
1912
- return
1913
- end
1914
- end
1915
- erev padding?+dna_with_ends(Bioroebe.to_dna(i))
1916
- end
1917
-
1918
- # ========================================================================= #
1919
- # === interactive_colour_menu
1920
- # ========================================================================= #
1921
- def interactive_colour_menu
1922
- erev 'You can decide here whether you want to use colours or not, and if'
1923
- erev 'you want to use colours, whether these will be simple ansi colours'
1924
- erev 'or the "more advanced" konsole submodule of the colours project.'
1925
- e
1926
- erev ' (1) no colours'
1927
- erev ' (2) ansi colours'
1928
- erev ' (3) konsole colours'
1929
- e
1930
- print 'Input your choice next: '
1931
- user_input = $stdin.gets.chomp
1932
- case user_input
1933
- when '1'
1934
- erev 'We will use no colours.'
1935
- disable_colours
1936
- when '2'
1937
- erev 'We will use ansi colours.'
1938
- enable_colours unless use_colours?
1939
- Shell.set_colour(:AnsiColours)
1940
- when '3'
1941
- erev 'We will use konsole colours.'
1942
- enable_colours unless use_colours?
1943
- Shell.set_colour(:Konsole)
1944
- end
1945
- end
1946
-
1947
- # ========================================================================= #
1948
- # === return_all_genes
1949
- # ========================================================================= #
1950
- def return_all_genes
1951
- _ = dna_sequence?
1952
- result = _.to_enum(:scan, /(ATG|AUG)/i).map { |match|
1953
- $`.size + 1 # +1 because we refer to the nucleotide positions.
1954
- }
1955
- e
1956
- result.each_with_index {|nucleotide_position, index|
1957
- erev simp(index+1).to_s+rev+') DNA sequence:'
1958
- e
1959
- sequence = _[nucleotide_position-1 .. -1]
1960
- erev dna_with_ends(sequence, ::Bioroebe.start_codon?, 1)
1961
- e
1962
- }
1963
- end
1964
-
1965
- # ========================================================================= #
1966
- # === generate_single_sequence_repeats
1967
- #
1968
- # This method can be used to generate SSR sequences.
1969
- # ========================================================================= #
1970
- def generate_single_sequence_repeats
1971
- _ = ''
1972
- length_of_the_SSR_sequence = 2+rand(4) # 2-5
1973
- length_of_the_SSR_sequence.times {
1974
- _ << return_random_nucleotide
1975
- }
1976
- n_repeats = 9+rand(22) # 9-30
1977
- result = _ * n_repeats
1978
- return result
1979
- end
1980
-
1981
- # ========================================================================= #
1982
- # === on_roebe?
1983
- # ========================================================================= #
1984
- def on_roebe?
1985
- ::Bioroebe.is_on_roebe?
1986
- end
1987
-
1988
- # ========================================================================= #
1989
- # === do_toggle_debug_value
1990
- # ========================================================================= #
1991
- def do_toggle_debug_value
1992
- if @debug
1993
- @debug = false
1994
- else
1995
- @debug = true
1996
- end
1997
- end
1998
-
1999
- # ========================================================================= #
2000
- # === protein_stats
2001
- # ========================================================================= #
2002
- def protein_stats
2003
- e
2004
- e 'CURRENTLY NOT IMPLEMENTED'
2005
- e
2006
- end
2007
-
2008
- # ========================================================================= #
2009
- # === generate_pdf_tutorial
2010
- #
2011
- # Easier wrapper to generate the .pdf Tutorial.
2012
- # ========================================================================= #
2013
- def generate_pdf_tutorial
2014
- ::Bioroebe.generate_pdf_tutorial
2015
- end
2016
-
2017
- # ========================================================================= #
2018
- # === open_blast_webpage
2019
- # ========================================================================= #
2020
- def open_blast_webpage
2021
- open_in_browser_tab 'https://blast.ncbi.nlm.nih.gov/'\
2022
- 'Blast.cgi?PROGRAM=blastn&PAGE_TYPE=BlastSearch&LINK_LOC=blasthome'
2023
- end
2024
-
2025
- # ========================================================================= #
2026
- # === nucleotides_or_aminoacids?
2027
- # ========================================================================= #
2028
- def nucleotides_or_aminoacids?
2029
- case mode?
2030
- # ======================================================================= #
2031
- # === :dna
2032
- # ======================================================================= #
2033
- when :dna,
2034
- :rna
2035
- 'nucleotides'
2036
- # ======================================================================= #
2037
- # === :aminoacids
2038
- # ======================================================================= #
2039
- when :aminoacids
2040
- 'aminoacids'
2041
- end
2042
- end
2043
-
2044
- # ========================================================================= #
2045
- # === is_dna?
2046
- # ========================================================================= #
2047
- def is_dna?
2048
- mode? == :dna
2049
- end
2050
-
2051
- # ========================================================================= #
2052
- # === do_open
2053
- #
2054
- # Open an URL - via browser.
2055
- # ========================================================================= #
2056
- def do_open(i)
2057
- case i
2058
- when 'all','ALL'
2059
- open_my_files
2060
- else # Default.
2061
- open_in_browser(i)
2062
- end
2063
- end; alias browse_to open # === browse_to
2064
-
2065
- # ========================================================================= #
2066
- # === find_all_orfs
2067
- #
2068
- # This method will return all ORFs within the target sequence.
2069
- #
2070
- # It will return an Array, and then we will display these ORFs,
2071
- # starting with the LONGEST ORF first.
2072
- # ========================================================================= #
2073
- def find_all_orfs(
2074
- i = dna_sequence?
2075
- )
2076
- all_start_codons = i.to_enum(:scan, /#{::Bioroebe.start_codon?}/i).map { |match|
2077
- [$`.size] # [$`.size, match]
2078
- }
2079
- all_stop_codons = i.to_enum(:scan, /(TGA|TAG|TAA)/i).map { |match|
2080
- [$`.size]
2081
- }
2082
- array_with_the_proper_matches = []
2083
- current_match = nil
2084
- all_start_codons.each {|start_codon_position|
2085
- start_codon_position = start_codon_position.first
2086
- # ===================================================================== #
2087
- # Find the nearest stop codon position.
2088
- # ===================================================================== #
2089
- all_stop_codons.reverse.each {|stop_codon_position|
2090
- stop_codon_position = stop_codon_position.first
2091
- length = stop_codon_position - start_codon_position
2092
- next if length < 1
2093
- current_match = [start_codon_position, length]
2094
- if current_match
2095
- # Must be a smaller match.
2096
- if length < current_match[1] # [1] refers to the length.
2097
- unless length < 3
2098
- current_match = [start_codon_position, length]
2099
- end
2100
- end
2101
- end
2102
- }
2103
- array_with_the_proper_matches << current_match
2104
- }
2105
- cliner token: '-'
2106
- pp array_with_the_proper_matches
2107
- cliner token: '-'
2108
- _ = dna_sequence?
2109
- array_with_the_proper_matches.each {|start, stop|
2110
- subsequence = _[start.to_i .. stop.to_i]
2111
- erev subsequence unless subsequence.empty?
2112
- }
2113
- end
2114
-
2115
- # ========================================================================= #
2116
- # === to_rna
2117
- # ========================================================================= #
2118
- def to_rna(i = seq_object?)
2119
- i = seq_object? if i.nil? # Assign to default in this case.
2120
- if i.respond_to? :to_rna
2121
- i = i.to_rna
2122
- end
2123
- erev i
2124
- end
2125
-
2126
- # ========================================================================= #
2127
- # === replay
2128
- # ========================================================================= #
2129
- def replay(i = nil)
2130
- if i
2131
- # ===================================================================== #
2132
- # The user did input something. Thus continue here.
2133
- # ===================================================================== #
2134
- case i
2135
- # ===================================================================== #
2136
- # === save
2137
- # ===================================================================== #
2138
- when 'save',
2139
- 'store'
2140
- verbose_save_history_to_file
2141
- else
2142
- # =================================================================== #
2143
- # Else load the replay file. For instance, via "replay load".
2144
- # =================================================================== #
2145
- replay_file = log_dir?+'replay_file.yml'
2146
- if File.exist? replay_file
2147
- erev 'Now replaying the history from the file `'+sfile(replay_file)+rev+'`.'
2148
- array = YAML.load_file(replay_file)
2149
- array.each {|command|
2150
- run_this_user_input(command)
2151
- }
2152
- else
2153
- erev 'We are trying to replay the old history, but we could not find'
2154
- erev 'any file called '+sfile(replay_file)+'.'
2155
- e
2156
- erev 'You can generate a new replay file by inputting some commands'
2157
- erev 'and then invoking "replay".'
2158
- end
2159
- end
2160
- else
2161
- verbose_save_history_to_file
2162
- end
2163
- end
2164
-
2165
- # ========================================================================= #
2166
- # === change_first_nucleotide_to
2167
- #
2168
- # This will only work if we had already assigned a DNA sequence prior
2169
- # to running it.
2170
- # ========================================================================= #
2171
- def change_first_nucleotide_to(
2172
- i = dna_sequence?
2173
- )
2174
- i = i.join(' ').strip if i.is_a? Array
2175
- unless i.empty?
2176
- i = i.upcase
2177
- erev "Now changing the first nucleotide to `#{simp(i)}`."
2178
- @sequence.first_nucleotide = i
2179
- show_string
2180
- end
2181
- end
2182
-
2183
- # ========================================================================= #
2184
- # === start_clipboard
2185
- #
2186
- # Make use of the clipboard here.
2187
- # ========================================================================= #
2188
- def start_clipboard(i = '"')
2189
- if @clipboard
2190
- erev 'Starting Clipboard now (exit it with '+i+')'
2191
- @clipboard.set_exit_token(i) # Set closing token. Default to }
2192
- @clipboard.fetch_input
2193
- return @clipboard.buffer?
2194
- end
2195
- end
2196
-
2197
- # ========================================================================= #
2198
- # === assume_what_type_this_is
2199
- #
2200
- # Determine what type the given input is.
2201
- #
2202
- # Note that this currently has limitations in that it does not use a
2203
- # statistical way to determine whether we really have DNA/RNA/Aminoacids
2204
- # here.
2205
- #
2206
- # Eventually we will write a replacement for it but for now,
2207
- # it has to suffice.
2208
- #
2209
- # To test this method interactively, do this in the shell:
2210
- #
2211
- # assume ATCG
2212
- # assume AUCG
2213
- # assume NNNLMMLLAAA
2214
- #
2215
- # ========================================================================= #
2216
- def assume_what_type_this_is(i)
2217
- if i.is_a? Array
2218
- i = i.join
2219
- end
2220
- if i
2221
- chars = i.chars
2222
- if chars.all? {|entry| POSSIBLE_DNA_NUCLEOTIDES.include? entry }
2223
- erev 'This must be a DNA sequence.'
2224
- elsif chars.all? {|entry| POSSIBLE_RNA_NUCLEOTIDES.include? entry }
2225
- erev 'This must be a RNA sequence.'
2226
- elsif chars.all? {|entry| POSSIBLE_AMINO_ACIDS.include? entry }
2227
- erev 'This must be an amino acid sequence.'
2228
- else
2229
- erev 'This can not be a valid sequence ('+
2230
- simp('DNA/RNA/Proteins')+rev+').'
2231
- end
2232
- else
2233
- erev 'Missing an input such as '+sfancy('ATCG')+rev+'.'
2234
- end
2235
- end
2236
-
2237
- # ========================================================================= #
2238
- # === add_to_start
2239
- #
2240
- # Use this method to add to the start of a nucleotide sequence. In other
2241
- # words, to prepend to the main nucleotide sequence.
2242
- # ========================================================================= #
2243
- def add_to_start(i)
2244
- add_to_start_or_end(i, :to_start)
2245
- end; alias add_n_nucleotides add_to_start # === add_n_nucleotides
2246
-
2247
- # ========================================================================= #
2248
- # === do_action
2249
- #
2250
- # Usage example:
2251
- #
2252
- # do not truncate
2253
- #
2254
- # ========================================================================= #
2255
- def do_action(*i)
2256
- if i.is_a? Array
2257
- i.flatten!
2258
- end
2259
- first_argument = i[0]
2260
- second_argument = i[1]
2261
- case second_argument
2262
- when 'truncate'
2263
- do_not_truncate if first_argument == 'not'
2264
- end
2265
- end
2266
-
2267
- # ========================================================================= #
2268
- # === erev (erev tag)
2269
- #
2270
- # Easier wrapper over output that has rev().
2271
- # ========================================================================= #
2272
- def erev(i = '')
2273
- e "#{rev}#{i}"
2274
- end
2275
-
2276
- # ========================================================================= #
2277
- # === dna_to_aminoacid_sequence
2278
- #
2279
- # Convert a DNA sequence into the corresponding aminoacid sequence.
2280
- # ========================================================================= #
2281
- def dna_to_aminoacid_sequence(i = dna_sequence?)
2282
- i = dna_sequence? if i.nil?
2283
- i = dna_sequence? if i.empty?
2284
- ::Bioroebe::DnaToAminoacidSequence.new(i)
2285
- end
2286
-
2287
- # ========================================================================= #
2288
- # === set_jumper_directory
2289
- # ========================================================================= #
2290
- def set_jumper_directory(i)
2291
- if i
2292
- erev 'Adding '+sdir(i)+' to the jumper directories.'
2293
- @array_jumper_directories << i
2294
- end
2295
- end
2296
-
2297
- # ========================================================================= #
2298
- # === dalton
2299
- #
2300
- # This method will calculate the weight of several aminoacids, in
2301
- # Dalton. We assume that each aminoacid will have a weight of 110
2302
- # Dalton.
2303
- # ========================================================================= #
2304
- def dalton(i)
2305
- n_dalton = i.to_f * 110
2306
- e sfancy(i.to_s)+rev+' aminoacids have a molecular weight of '+
2307
- simp(n_dalton.to_s)+rev+' Dalton ('+(n_dalton/1000.0).to_s+' kDa).'
2308
- end
2309
-
2310
- # ========================================================================= #
2311
- # === analyze (analyze tag)
2312
- #
2313
- # The input to this method should be the DNA or aminoacid sequence.
2314
- # ========================================================================= #
2315
- def analyze(
2316
- i = sequence?
2317
- )
2318
- if i.is_a? Array
2319
- i << sequence? if i.empty?
2320
- i = i.join
2321
- end
2322
- # ======================================================================= #
2323
- # We require a String past this point.
2324
- # ======================================================================= #
2325
- i = i.to_s
2326
- if File.exist? i # Assume that we have a .pdb file here for now.
2327
- parse_this_pdb_file(i)
2328
- else
2329
- if block_given?
2330
- yielded = yield
2331
- case yielded
2332
- when :dna # Handle DNA "input" here.
2333
- analyze_dna_string(i)
2334
- else
2335
- do_analyze_sequence(i)
2336
- end
2337
- else # Default case without block.
2338
- do_analyze_sequence(i)
2339
- end
2340
- end
2341
- end
2342
-
2343
- # ========================================================================= #
2344
- # === trailing_five_prime
2345
- # ========================================================================= #
2346
- def trailing_five_prime
2347
- " - 5'"
2348
- end; alias trailing_5_prime trailing_five_prime # === trailing_5_prime
2349
- alias five_prime_trailer trailing_five_prime # === five_prime_trailer
2350
-
2351
- # ========================================================================= #
2352
- # === mirror_repeat
2353
- # ========================================================================= #
2354
- def mirror_repeat(
2355
- i = dna_sequence?
2356
- )
2357
- i = dna_sequence? if i.nil? # Use a proper default in this case.
2358
- i = i.join(' ').strip if i.is_a? Array
2359
- erev default_padding+
2360
- five_prime+
2361
- colourize_dna_sequence(
2362
- ::Bioroebe.mirror_repeat_of(i, :use_separator_token)
2363
- )+
2364
- rev+
2365
- three_trailer
2366
- end
2367
-
2368
- # ========================================================================= #
2369
- # === all_upcase?
2370
- #
2371
- # Return true if the input is all upcased.
2372
- # ========================================================================= #
2373
- def all_upcase?(i)
2374
- return true if i.upcase == i
2375
- false
2376
- end; alias is_all_upcase? all_upcase? # === is_all_upcase?
2377
-
2378
- # ========================================================================= #
2379
- # === set_codon_table
2380
- #
2381
- # Set which codon table to use.
2382
- # ========================================================================= #
2383
- def set_codon_table(i)
2384
- ::Bioroebe.set_codon_table(i, :be_verbose) # defined in codon_table.rb
2385
- end
2386
-
2387
- # ========================================================================= #
2388
- # === return_sequence_from_this_number
2389
- # ========================================================================= #
2390
- def return_sequence_from_this_number(i = 1)
2391
- case i.to_i
2392
- when 1
2393
- seq1?
2394
- when 2
2395
- seq2?
2396
- when 3
2397
- seq3?
2398
- when 4
2399
- seq4?
2400
- when 5
2401
- seq5?
2402
- when 6
2403
- seq6?
2404
- end
2405
- end
2406
-
2407
- # ========================================================================= #
2408
- # === enter_base_directory
2409
- #
2410
- # Use this method to enter the base directory.
2411
- # ========================================================================= #
2412
- def enter_base_directory
2413
- cd ::Bioroebe.log_dir?
2414
- end
2415
-
2416
- # ========================================================================= #
2417
- # === translate
2418
- #
2419
- # General translate method.
2420
- # ========================================================================= #
2421
- def translate(i, be_verbose = true) # Translate tag.
2422
- translate_aminoacid(i, be_verbose) # for now, we default to this.
2423
- end
2424
-
2425
- # ========================================================================= #
2426
- # === ee (ee tag)
2427
- #
2428
- # As e, but without newline. So basically it behaves like print.
2429
- # ========================================================================= #
2430
- def ee(i)
2431
- e(i, false)
2432
- end
2433
-
2434
- # ========================================================================= #
2435
- # === convert_five_prime_dna_into_five_prime_mrna (DNA to mRNA)
2436
- #
2437
- # This method will translate the 5'-DNA into 5'-mRNA.
2438
- # ========================================================================= #
2439
- def convert_five_prime_dna_into_five_prime_mrna(
2440
- this_string = sequence?
2441
- )
2442
- erev padding?+leading_5_prime+sfancy(this_string.upcase.tr('T','U'))+
2443
- rev+trailing_3_prime
2444
- end
2445
-
2446
- # ========================================================================= #
2447
- # === trailing_3_prime
2448
- #
2449
- # This will essentually return a " -3'" string.
2450
- # ========================================================================= #
2451
- def trailing_3_prime(
2452
- get_rid_of_spaces = false
2453
- )
2454
- if show_the_trailer?
2455
- get_rid_of_spaces = true if get_rid_of_spaces == :no_spaces
2456
- _ = " - 3'".dup
2457
- _.delete!(' ') if get_rid_of_spaces
2458
- return _
2459
- end
2460
- return '' # Else return an empty String.
2461
- end; alias three_trailer trailing_3_prime # === three_trailer
2462
- alias trailer trailing_3_prime # === trailer
2463
- alias three_prime trailing_3_prime # === three_prime
2464
- alias trailing_three_prime trailing_3_prime # === trailing_three_prime
2465
- alias trail_three_prime trailing_3_prime # === trail_three_prime
2466
- alias trail_three trailing_3_prime # === trail_three
2467
- alias trailing_three trailing_3_prime # === trailing_three
2468
-
2469
- # ========================================================================= #
2470
- # === format_this_nucleotide_sequence
2471
- #
2472
- # This method will properly format the passed-in nucleotide sequence,
2473
- # by making use of class ShowNucleotideSequence.
2474
- #
2475
- # It will return the formatted String.
2476
- # ========================================================================= #
2477
- def format_this_nucleotide_sequence(i, &block)
2478
- ::Bioroebe.format_this_nucleotide_sequence(i) { block }
2479
- end
2480
-
2481
-
2482
- # ========================================================================= #
2483
- # === find_longest_substring
2484
- # ========================================================================= #
2485
- def find_longest_substring(i = dna_string?)
2486
- if i.is_a? String and i.include? ' '
2487
- i = i.split(' ')
2488
- end
2489
- ::Bioroebe::FindLongestSubstring.new(i.first, i.last)
2490
- end
2491
-
2492
- # ========================================================================= #
2493
- # === dna_padding (dna_padding tag)
2494
- #
2495
- # This method will properly pad a DNA string (with leading 5' and
2496
- # trailing 3'). That string will be returned.
2497
- #
2498
- # First argument should be the string (sequence) that you wish to
2499
- # modify.
2500
- # ========================================================================= #
2501
- def dna_padding(
2502
- this_sequence,
2503
- get_rid_of_spaces = false
2504
- )
2505
- return left_pad?+
2506
- five_prime(get_rid_of_spaces)+rev+
2507
- sfancy(this_sequence)+rev+
2508
- trailer(get_rid_of_spaces)
2509
- end; alias properly_spaced_dna dna_padding # === properly_spaced_dna
2510
- alias properly_padded_dna_string dna_padding # === properly_padded_dna_string
2511
-
2512
- # ========================================================================= #
2513
- # === no_newlines
2514
- #
2515
- # This will get rid of the newlines in a fasta file, at the least for
2516
- # displaying purposes.
2517
- # ========================================================================= #
2518
- def no_newlines(this_file)
2519
- if this_file.is_a? Array
2520
- this_file.each {|entry| no_newlines(entry) }
2521
- else
2522
- dataset = File.readlines(this_file)
2523
- dataset.map! {|line|
2524
- line.chomp! unless line.start_with? '>'
2525
- line
2526
- }
2527
- e dataset.join
2528
- end
2529
- end
2530
-
2531
- # ========================================================================= #
2532
- # === annotate_this_file
2533
- # ========================================================================= #
2534
- def annotate_this_file(i)
2535
- ::Bioroebe::CreateAnnotationFormat.new(i)
2536
- end
2537
-
2538
- # ========================================================================= #
2539
- # === display_all_aminoacids
2540
- #
2541
- # This method will display all Aminoacids.
2542
- #
2543
- # Invocation example:
2544
- #
2545
- # daminoacids
2546
- #
2547
- # ========================================================================= #
2548
- def display_all_aminoacids
2549
- e
2550
- erev 'Aminoacids Shortnames:'
2551
- erev # Newline here is ok.
2552
- aa = ::Bioroebe::AMINO_ACIDS # Is a hash.
2553
- aa.keys.sort.each {|key|
2554
- result = aa[key].select {|inner_key, value| inner_key.size == 3 }.values.first
2555
- erev ' '+key+': '+sfancy(result)
2556
- }; e # Trailing newline.
2557
- end
2558
-
2559
- # ========================================================================= #
2560
- # === toggle_truncate
2561
- # ========================================================================= #
2562
- def toggle_truncate
2563
- if do_truncate?
2564
- do_not_truncate
2565
- else
2566
- ::Bioroebe.do_truncate
2567
- erev 'We will truncate too-long output.'
2568
- end
2569
- end
2570
-
2571
- # ========================================================================= #
2572
- # === do_truncate?
2573
- # ========================================================================= #
2574
- def do_truncate?
2575
- ::Bioroebe.do_truncate?
2576
- end
2577
-
2578
- # ========================================================================= #
2579
- # === will_we_truncate?
2580
- # ========================================================================= #
2581
- def will_we_truncate?
2582
- if do_truncate?
2583
- erev 'We will truncate.'
2584
- else
2585
- erev 'We will not truncate.'
2586
- end
2587
- end
2588
-
2589
- # ========================================================================= #
2590
- # === do_not_truncate
2591
- # ========================================================================= #
2592
- def do_not_truncate
2593
- ::Bioroebe.do_not_truncate
2594
- erev 'We will no longer truncate too-long output.'
2595
- end
2596
-
2597
- # ========================================================================= #
2598
- # === designate_this_input_as_coding_entry
2599
- #
2600
- # Invocation example:
2601
- #
2602
- # coding_entry 51..3251
2603
- #
2604
- # ========================================================================= #
2605
- def designate_this_input_as_coding_entry(i)
2606
- if i.is_a? Array
2607
- i = i.first
2608
- end
2609
- if i.include? '..'
2610
- # ===================================================================== #
2611
- # Assume Range-behaviour here.
2612
- # ===================================================================== #
2613
- @internal_hash[:coding_area] = i
2614
- end
2615
- erev "Using the coding-area #{sfancy(i)}#{rev}."
2616
- erev 'You can test this by e. g. invoking '+sfancy('ORF?')+rev+'.'
2617
- end
2618
-
2619
- # ========================================================================= #
2620
- # === report_where_we_store
2621
- # ========================================================================= #
2622
- def report_where_we_store
2623
- erev "We will store output from the Bioroebe-Project "\
2624
- "into #{sfile(save_file?)}."
2625
- end
2626
-
2627
- # ========================================================================= #
2628
- # === calculate_melting_temperature
2629
- #
2630
- # This method just delegates towards class CalculateMeltungTemperature.
2631
- # ========================================================================= #
2632
- def calculate_melting_temperature(i)
2633
- i = string? if i.nil?
2634
- if i == :show_formulas
2635
- CalculateMeltingTemperature.show_formulas # bl $BIOROEBE/calculate_melting_temperature.rb
2636
- else
2637
- @_.calculate_melting_temperature(i)
2638
- end
2639
- end
2640
-
2641
- # ========================================================================= #
2642
- # === salt_adjusted_tm
2643
- # ========================================================================= #
2644
- def salt_adjusted_tm(i)
2645
- if i.is_a? Array
2646
- i = i.join.strip
2647
- end
2648
- return ::Bioroebe.salt_adjusted_tm(i)
2649
- end
2650
-
2651
- # ========================================================================= #
2652
- # === leading_5_prime
2653
- #
2654
- # This method will output the leading 5' part, like a header.
2655
- # ========================================================================= #
2656
- def leading_5_prime(
2657
- get_rid_of_spaces = false
2658
- )
2659
- if show_the_leader?
2660
- get_rid_of_spaces = true if get_rid_of_spaces == :no_spaces
2661
- _ = "5' - ".dup # <- This here is the header-tag.
2662
- _.delete!(' ') if get_rid_of_spaces
2663
- return _
2664
- end
2665
- return ''
2666
- end; alias five_prime leading_5_prime # === five_prime
2667
- alias leading_five_prime leading_5_prime # === leading_five_prime
2668
- alias leader leading_5_prime # === leader
2669
- alias lead_five_prime leading_5_prime # === lead_five_prime
2670
- alias return_five_prime_header leading_5_prime # === return_five_prime
2671
- alias leading_five leading_5_prime # === return_five
2672
-
2673
- # ========================================================================= #
2674
- # === is_a_registered_compound?
2675
- # ========================================================================= #
2676
- def is_a_registered_compound?(i)
2677
- %w( glycine ).include? i.to_s.downcase
2678
- end
2679
-
2680
- # ========================================================================= #
2681
- # === compare_two_files
2682
- #
2683
- # We will here compare whether two files are identical.
2684
- #
2685
- # First argument is the first file, second argument is the second file.
2686
- # ========================================================================= #
2687
- def compare_two_files(file_a, file_b)
2688
- if File.exist? file_a
2689
- file_a = File.read(file_a)
2690
- else
2691
- erev file_a+' does not exist.'
2692
- end
2693
- if File.exist? file_b
2694
- file_b = File.read(file_b)
2695
- else
2696
- erev file_b+' does not exist.'
2697
- end
2698
- erev (file_a == file_b)
2699
- end
2700
-
2701
- # ========================================================================= #
2702
- # === molecular_mass_of_amino_acids_in_the_sequence
2703
- #
2704
- # This method will calculate the mass of all amino acids in the given
2705
- # sequence.
2706
- #
2707
- # The default input sequence will be the aminoacid sequence.
2708
- # ========================================================================= #
2709
- def molecular_mass_of_amino_acids_in_the_sequence(
2710
- i = aminoacid_sequence?
2711
- )
2712
- total_mass = 0
2713
- if i.is_a? Array # We require a String here really.
2714
- if i.empty? # In this case, assign a default.
2715
- i = aminoacid_sequence?
2716
- else
2717
- i = i.join
2718
- end
2719
- elsif i.nil?
2720
- i = aminoacid_sequence?
2721
- end
2722
- # ======================================================================= #
2723
- # The user may have inputted something such as 'lysine'. In this
2724
- # case, we will convert this to the one-letter code.
2725
- # ======================================================================= #
2726
- if (i != ::Bioroebe.return_short_aminoacid_letter_from_long_aminoacid_name(i))
2727
- i = ::Bioroebe.return_short_aminoacid_letter_from_long_aminoacid_name(i)
2728
- end
2729
- _ = i # Use a copy.
2730
- unless _
2731
- erev 'Please assign an aminoacid sequence.'
2732
- return
2733
- end
2734
- dataset_molecular_formula = YAML.load_file(FILE_AMINOACIDS_MOLECULAR_FORMULA)
2735
- chars =_.chars
2736
- chars.each {|this_aminoacid|
2737
- # ===================================================================== #
2738
- # The following constant has the mass of the aminoacid at hand. It
2739
- # is stored in the one-letter abbreviation.
2740
- # ===================================================================== #
2741
- value = AMINO_ACIDS_MASS_TABLE[this_aminoacid]
2742
- total_mass += value.to_f
2743
- molecular_formula = dataset_molecular_formula[one_letter_to_long_name(this_aminoacid).capitalize]
2744
- erev 'The molecular formula for '+sfancy(this_aminoacid)+rev+
2745
- ' is: '+lightgreen(molecular_formula)+rev
2746
- }
2747
- erev "The total mass (#{seagreen('molecular weight')}#{rev}) of "\
2748
- "this sequence (#{_.size.to_s} entries), using "\
2749
- "#{teal('mono-isotopic mass')}#{rev}, is: "
2750
- if has_konsole?
2751
- erev ' '+cadetblue(total_mass.to_s)
2752
- else
2753
- e " #{simp(total_mass.to_s)}"
2754
- end
2755
- # ======================================================================= #
2756
- # Next calculate the average mass.
2757
- # ======================================================================= #
2758
- total_mass = 0
2759
- i.chars.each {|this_aminoacid|
2760
- value = AMINO_ACIDS_AVERAGE_MASS_TABLE[this_aminoacid]
2761
- total_mass += value.to_f
2762
- }
2763
- erev "The total mass (#{seagreen('molecular weight')}#{rev}) of "\
2764
- "this sequence (#{_.size.to_s} entries), using "\
2765
- "#{teal('average molecular mass')}#{rev}, is: "
2766
- erev ' '+cadetblue(total_mass.to_s)
2767
- end; alias molecular_mass_of_amino_acids_in_this_sequence molecular_mass_of_amino_acids_in_the_sequence # === molecular_mass_of_aminco_acids_in_this_sequence
2768
-
2769
- # ========================================================================= #
2770
- # === dump
2771
- #
2772
- # This method can be used to save the main DNA string into a file.
2773
- #
2774
- # You can also store RNA of course; simply pass the argument
2775
- # "rna" or "to_rna" to this method.
2776
- # ========================================================================= #
2777
- def dump(optional_arguments = nil)
2778
- what = dna_string?
2779
- if optional_arguments.is_a? Array
2780
- optional_arguments = optional_arguments.join(' ').strip
2781
- end
2782
- case optional_arguments
2783
- when 'rna',/to_?rna/
2784
- what = ::Bioroebe.to_rna(what)
2785
- end
2786
- into = file_dna_string_saved?
2787
- erev 'Storing into `'+sfile(into)+'`.'
2788
- write_what_into(what, into)
2789
- end
2790
-
2791
- # ========================================================================= #
2792
- # === name_of_gene?
2793
- # ========================================================================= #
2794
- def name_of_gene?
2795
- sequence_object?.name_of_gene?
2796
- end
2797
-
2798
- # ========================================================================= #
2799
- # === set_name_of_gene
2800
- #
2801
- # Use this method to set the name of a gene in question.
2802
- # ========================================================================= #
2803
- def set_name_of_gene(
2804
- i = '',
2805
- be_verbose = :be_verbose
2806
- )
2807
- case be_verbose
2808
- when :be_verbose
2809
- be_verbose = true
2810
- end
2811
- if i.is_a? Array # We don't want Arrays here.
2812
- i = i.join(' ').strip
2813
- end
2814
- if i.nil? or i.to_s.empty?
2815
- erev 'Please assign a non-empty name for the gene.'
2816
- return
2817
- end
2818
- if be_verbose
2819
- erev 'Now assigning the gene name to "'+simp(i)+rev+'", without '\
2820
- 'the quotes.'
2821
- end
2822
- sequence_object?.name_of_gene = i
2823
- end
2824
-
2825
- # ========================================================================= #
2826
- # === do_not_show_the_trailer
2827
- # ========================================================================= #
2828
- def do_not_show_the_trailer(be_verbose = true)
2829
- if be_verbose
2830
- e "The 3'-trailer of nucleotide sequences will not be shown."
2831
- end
2832
- @internal_hash[:show_the_trailer] = false
2833
- end
2834
-
2835
- # ========================================================================= #
2836
- # === do_not_show_the_leader
2837
- # ========================================================================= #
2838
- def do_not_show_the_leader(
2839
- be_verbose = true
2840
- )
2841
- if be_verbose
2842
- e "The 3'-trailer of nucleotide sequences will not be shown."
2843
- end
2844
- @internal_hash[:show_the_leader] = false
2845
- end
2846
-
2847
- # ========================================================================= #
2848
- # === show_the_leader?
2849
- # ========================================================================= #
2850
- def show_the_leader?
2851
- @internal_hash[:show_the_leader]
2852
- end
2853
-
2854
- # ========================================================================= #
2855
- # === show_the_trailer?
2856
- # ========================================================================= #
2857
- def show_the_trailer?
2858
- @internal_hash[:show_the_trailer]
2859
- end
2860
-
2861
- require 'bioroebe/toplevel_methods/download_and_fetch_data.rb'
2862
- # ========================================================================= #
2863
- # === uniprot_fetch
2864
- #
2865
- # This method can be sued to obtain the .fasta sequence of a protein
2866
- # listed at uniprot.
2867
- # ========================================================================= #
2868
- def uniprot_fetch(
2869
- i = 'P12345'
2870
- )
2871
- i = 'P12345' if i.nil?
2872
- ::Bioroebe.fetch_data_from_uniprot(i)
2873
- end
2874
-
2875
- # ========================================================================= #
2876
- # === calculate_exponential_growth
2877
- # ========================================================================= #
2878
- def calculate_exponential_growth(a, b)
2879
- erev ::Bioroebe.calculate_exponential_growth(a,b)
2880
- end
2881
-
2882
- # ========================================================================= #
2883
- # === molecular_mass_of
2884
- #
2885
- # Give out the molecular mass of an amino-acid.
2886
- #
2887
- # We will use only the first input character, and upcase it.
2888
- #
2889
- # You can also input an Array here, though.
2890
- #
2891
- # Usage examples:
2892
- #
2893
- # mmasse tyrosin
2894
- # mmasse KKKRAAA
2895
- # mmasse Glycine
2896
- #
2897
- # ========================================================================= #
2898
- def molecular_mass_of(
2899
- i = aminoacids?,
2900
- optional_round_here = nil
2901
- )
2902
- case i
2903
- # ======================================================================= #
2904
- # === HELP
2905
- # ======================================================================= #
2906
- when /^-?-?help$/i
2907
- erev 'Input an amino acid, such as H.'
2908
- return
2909
- end if i.is_a? String
2910
- i = aminoacids? if i.nil? # Safeguard.
2911
- # ======================================================================= #
2912
- # === Handle Arrays first
2913
- # ======================================================================= #
2914
- if i.is_a? Array
2915
- i.uniq.each {|entry|
2916
- molecular_mass_of(entry, optional_round_here)
2917
- }
2918
- elsif is_a_registered_compound?(i)
2919
- original_name = i.dup
2920
- # ===================================================================== #
2921
- # This menu is a bit ad-hoc. In the long run we will probably have
2922
- # to make this more generic.
2923
- # ===================================================================== #
2924
- case i
2925
- # ===================================================================== #
2926
- # === Glycine
2927
- # ===================================================================== #
2928
- when /^Glycine?$/i
2929
- i = 'C8H9NO3'
2930
- end
2931
- i = ChemistryParadise.molmass_of?(i)
2932
- erev 'The molecular mass of '+sfancy(original_name)+rev+
2933
- ' is: '+simp(i.to_s.rjust(5))
2934
- else # Else we assume a String here.
2935
- # ===================================================================== #
2936
- # Some input may be like "tyrosin". In this case, we will assume
2937
- # that the user may have input
2938
- # ===================================================================== #
2939
- if i.size > 1
2940
- if i.size > 3
2941
- _ = i.to_s.downcase
2942
- if _.size > 3
2943
- reversed = AMINO_ACIDS_ABBREVIATIONS.invert
2944
- if reversed.has_key? _
2945
- _ = reversed[_]
2946
- if AMINO_ACIDS_THREE_TO_ONE.has_key? _
2947
- _ = AMINO_ACIDS_THREE_TO_ONE[_]
2948
- end
2949
- molecular_mass_of(_, optional_round_here)
2950
- return
2951
- end
2952
- end
2953
- end
2954
- # =================================================================== #
2955
- # Here, either we grab the mass of each character, or we
2956
- # try to find a single AA replacement.
2957
- # =================================================================== #
2958
- molecular_mass_of(i.chars, optional_round_here)
2959
- else
2960
- if AMINO_ACIDS_MASS_TABLE.has_key? i
2961
- left = rev+'The molecular mass of '+sfancy(i)+rev+' ('+
2962
- get_long_name_of_amino_acid(i)+rev+')'+rev+' is: '
2963
- ljust_value = 72
2964
- ljust_value = 92 if use_colours?
2965
- left = left.ljust(ljust_value)
2966
- result = AMINO_ACIDS_MASS_TABLE[i]
2967
- if optional_round_here
2968
- result = result.to_f.round(optional_round_here)
2969
- end
2970
- erev left+simp(result.to_s.rjust(5))
2971
- else
2972
- # e 'Please input a specific amino acid, such as "H".'
2973
- end
2974
- end
2975
- end
2976
- end
2977
-
2978
- # ========================================================================= #
2979
- # === colour_scheme_for_nucleotides
2980
- #
2981
- # This method can eventually be used to display the colour codes for
2982
- # the nucleotides.
2983
- # ========================================================================= #
2984
- def colour_scheme_for_nucleotides(i = dna_sequence?)
2985
- begin
2986
- require 'roebe/classes/hex_to_rgb.rb'
2987
- rescue LoadError; end
2988
- if Object.const_defined?(:Roebe) and
2989
- Roebe.const_defined?(:HexToRGB)
2990
- i = dna_sequence? if i.nil?
2991
- i = i.first if i.is_a? Array
2992
- hash = ::Bioroebe::ColourScheme::Nucleotide.colours?
2993
- tokens = i.chars
2994
- # ======================================================================= #
2995
- # Get it in chunks of 80.
2996
- # ======================================================================= #
2997
- chunks = tokens.each_slice(80).to_a
2998
- e; chunks.each {|array|
2999
- array.each {|char|
3000
- if hash.has_key? char
3001
- value = hash[char]
3002
- array = Roebe::HexToRGB[value] # Obtain the R,G,B Array from here.
3003
- ::Colours.rgb_print(array, char)
3004
- end
3005
- }
3006
- e
3007
- }; e
3008
- else
3009
- erev 'Please install the gem hex_to_rgb, in order '\
3010
- 'to use this method.'
3011
- end
3012
- end
3013
-
3014
- # ========================================================================= #
3015
- # === www_finder_run
3016
- # ========================================================================= #
3017
- def www_finder_run
3018
- Bioroebe::GUI::Gtk::WwwFinder.run
3019
- end
3020
-
3021
- # ========================================================================= #
3022
- # === primer?
3023
- # ========================================================================= #
3024
- def primer(i)
3025
- i = i.to_s
3026
- if i.empty?
3027
- erev 'Please provide a number, which is the length of the Primer.'
3028
- else
3029
- erev 'We will design two primers, with a '\
3030
- 'length of '+i+rev+' each.'
3031
- report_sequence
3032
- _ = sequence?[0, i.to_i]
3033
- reverse_sequence = sequence?.reverse[0, i.to_i]
3034
- forward_primer = leading_three_prime+
3035
- rev+
3036
- sfancy(
3037
- complement(reverse_sequence.reverse)
3038
- )+rev+trailing_five_prime+
3039
- rev
3040
- reverse_primer = leading_five_prime+
3041
- sfancy(
3042
- complement(_.reverse)
3043
- )+rev+trailing_three_prime+
3044
- rev
3045
- erev 'Forward primer: '+forward_primer
3046
- erev 'Reverse primer: '+reverse_primer
3047
- e
3048
- padding = ' ' * (sequence?.size.to_i - _.size)
3049
- erev ' '+padding+forward_primer
3050
- show_sequence # This is the main sequence.
3051
- spacer = '|' * sequence?.size.to_i
3052
- erev " #{swarn(spacer)} #{rev}"
3053
- erev ' '+leading_three_prime+rev+
3054
- sfancy(complement(sequence?))+rev+trailing_five_prime+rev
3055
- erev ' '+leading_five_prime+rev+
3056
- sfancy(_.to_s)+rev+
3057
- trailing_three_prime+rev
3058
- e
3059
- end
3060
- end
3061
-
3062
- # ========================================================================= #
3063
- # === open_this_file_in_editor (editor tag)
3064
- # ========================================================================= #
3065
- def open_this_file_in_editor(file)
3066
- case file
3067
- when :bioshell, :shell
3068
- file = HOME_DIR+'shell.rb'
3069
- end
3070
- _ = MAIN_EDITOR+' '+file
3071
- if File.exist? file
3072
- splitted = _.split(' ')
3073
- splitted[1][0,0] = sfile
3074
- erev splitted.join(' ')+main_colour
3075
- system _
3076
- else
3077
- erev 'The file `'+sfile(file)+rev+'` does not exist.'
3078
- end
3079
- end
3080
-
3081
- # ========================================================================= #
3082
- # === open_this_ncbi_page
3083
- #
3084
- # This method will help us open the proper NCBI pages.
3085
- # ========================================================================= #
3086
- def open_this_ncbi_page(i)
3087
- search_term = i
3088
- search_term = '' if search_term.nil?
3089
- search_term = search_term.join(' ').strip.to_s if search_term.is_a? Array
3090
- if search_term =~ /^\d+$/ # If only numbers.
3091
- _ = '"https://www.ncbi.nlm.nih.gov/gene/'+search_term.to_s+'"'
3092
- else
3093
- _ = '"https://www.ncbi.nlm.nih.gov/gquery/?term='+search_term+'"'
3094
- end
3095
- erev _
3096
- open_in_browser_tab(_)
3097
- end
3098
-
3099
- # ========================================================================= #
3100
- # === feedback_whether_we_are_in_debug_mode
3101
- # ========================================================================= #
3102
- def feedback_whether_we_are_in_debug_mode
3103
- erev 'Are we in debug mode? '+simp(@debug.to_s)+rev
3104
- end
3105
-
3106
- # ========================================================================= #
3107
- # === upcase_main_string
3108
- #
3109
- # Use this method to upcase the main sequence.
3110
- # ========================================================================= #
3111
- def upcase_main_string
3112
- set_sequence(sequence?.upcase)
3113
- end
3114
-
3115
- # ========================================================================= #
3116
- # === notify_the_user_as_to_how_findgene_works
3117
- # ========================================================================= #
3118
- def notify_the_user_as_to_how_findgene_works
3119
- begin
3120
- _ = project_base_dir?+'find_gene.rb'
3121
- ClassDocuShower[_]
3122
- rescue LoadError
3123
- erev 'Please install class_docu_shower for this functionality to work.'
3124
- end
3125
- end
3126
-
3127
- require 'bioroebe/utility_scripts/find_gene.rb'
3128
- # ========================================================================= #
3129
- # === find_gene
3130
- #
3131
- # Wrapper towards class Bioroebe::FindGene.
3132
- # ========================================================================= #
3133
- def find_gene(i = :default)
3134
- case i
3135
- when :default, nil
3136
- i = dna_sequence?
3137
- end
3138
- if i.empty?
3139
- report_that_a_string_must_be_assigned_first
3140
- else
3141
- ::Bioroebe::FindGene.new(i.upcase) # bl $BIOROEBE/find_gene.rb
3142
- end
3143
- end
3144
-
3145
- require 'bioroebe/nucleotides/sanitize_nucleotide_sequence.rb'
3146
- # ========================================================================= #
3147
- # === sanitize_nucleotide_sequence
3148
- #
3149
- # Invocation example:
3150
- # sanitize_nucleotide_sequence " 10 AGTA \n 20 TTGC"
3151
- # ========================================================================= #
3152
- def sanitize_nucleotide_sequence(i)
3153
- if i.is_a? Array
3154
- i = i.join
3155
- end
3156
- @result = ::Bioroebe::SanitizeNucleotideSequence.new(i).result?.delete('"')
3157
- set_dna_sequence(@result)
3158
- end
3159
-
3160
- require 'bioroebe/colours/colour_schemes/colour_scheme_demo.rb'
3161
- # ========================================================================= #
3162
- # === colour_scheme_demo
3163
- # ========================================================================= #
3164
- def colour_scheme_demo(
3165
- use_this_sequence = 'ATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCATGC'
3166
- )
3167
- ColourSchemeDemo.new(use_this_sequence)
3168
- file = ::Bioroebe::ColourSchemeDemo.create_demo_file.to_s
3169
- erev file
3170
- open_in_browser(file) if File.exist? file
3171
- end
3172
-
3173
- # ========================================================================= #
3174
- # === design_polylinker
3175
- #
3176
- # This method will design a polylinker from 3-8 random restriction
3177
- # enzymes sites.
3178
- #
3179
- # You can pass a first argument to this method.
3180
- #
3181
- # Example:
3182
- #
3183
- # design_polylinker 100
3184
- #
3185
- # ========================================================================= #
3186
- def design_polylinker(
3187
- optional_length_of_polylinker = nil,
3188
- be_verbose = true
3189
- )
3190
- if optional_length_of_polylinker.is_a? Array
3191
- optional_length_of_polylinker = optional_length_of_polylinker[0]
3192
- end
3193
- if optional_length_of_polylinker.nil?
3194
- optional_length_of_polylinker = 20
3195
- end
3196
- optional_length_of_polylinker = optional_length_of_polylinker.to_i
3197
- full_sequence = ''
3198
- n_restriction_sites = rand(6)+3
3199
- n_restriction_sites.times {
3200
- full_sequence << return_random_restriction_enzyme(be_verbose)
3201
- }
3202
- if full_sequence.size < optional_length_of_polylinker
3203
- loop {
3204
- full_sequence << return_random_restriction_enzyme(be_verbose)
3205
- break if full_sequence.size > optional_length_of_polylinker
3206
- }
3207
- end
3208
- erev 'Our generated polylinker has '+sfancy(n_restriction_sites.to_s)+
3209
- ' sites for restriction enzymes available (DNA Sequence '+
3210
- 'length is: '+full_sequence.size.to_s+').'
3211
- erev 'We will also assign this sequence as the new DNA sequence.'
3212
- assign_dna_sequence(full_sequence, :be_quiet)
3213
- return full_sequence
3214
- end
3215
-
3216
- # ========================================================================= #
3217
- # === perform_frameshift_action
3218
- #
3219
- # This method attempts to perform a frameshift on our target sequence.
3220
- # We can give, as argument, +1,+2,+3 etc. Note that the + character
3221
- # is optional - if omitted, we assume that it was passed.
3222
- # ========================================================================= #
3223
- def perform_frameshift_action(i)
3224
- i = i.to_s
3225
- if sequence?.empty?
3226
- erev 'Please first "assign" a sequence before trying to'
3227
- erev 'perform a frameshift on it.'
3228
- else
3229
- if i == 'all'
3230
- erev 'We will perform all frameshift actions next.'
3231
- perform_frameshift_action '+1'
3232
- perform_frameshift_action '+2'
3233
- perform_frameshift_action '+3'
3234
- elsif i.to_i == 0
3235
- report_syntax_help_for_frameshift_action
3236
- else
3237
- erev 'Performing a frameshift on our target sequence next.'
3238
- erev 'The frameshift to perform will be '+simp(('+'+i).squeeze('+'))+'.'
3239
- erev 'We will modify the main sequence directly.'
3240
- @sequence[0, i.to_i] = ''
3241
- show_main_string
3242
- end
3243
- end
3244
- end
3245
-
3246
- # ========================================================================= #
3247
- # === verbose_handle_this_sys_command
3248
- # ========================================================================= #
3249
- def verbose_handle_this_sys_command(
3250
- i, arguments = a?
3251
- )
3252
- if a and a.is_a?(Array)
3253
- arguments = a.join(' ').strip
3254
- end
3255
- esystem i+' '+arguments.to_s+' &'
3256
- end
3257
-
3258
- # ========================================================================= #
3259
- # === leading_3_prime
3260
- #
3261
- # This is when 3' is at the start of an output.
3262
- # ========================================================================= #
3263
- def leading_3_prime
3264
- "3' - "
3265
- end; alias leading_three_prime leading_3_prime # === leading_three_prime
3266
- alias leading_3 leading_3_prime # === leading_3
3267
-
3268
- require 'bioroebe/toplevel_methods/verbose.rb'
3269
- # ========================================================================= #
3270
- # === verbose_truth
3271
- #
3272
- # Delegate towards the module Bioroebe::VerboseTruth here.
3273
- # ========================================================================= #
3274
- def verbose_truth(i)
3275
- ::Bioroebe::VerboseTruth[i]
3276
- end
3277
-
3278
- # ========================================================================= #
3279
- # === will_we_use_colours?
3280
- # ========================================================================= #
3281
- def will_we_use_colours?
3282
- erev "Will we use colours? #{verbose_truth(@use_colours)}#{rev}"
3283
- end
3284
-
3285
- # ========================================================================= #
3286
- # === create_balanced_composition
3287
- #
3288
- # This method will create a balanced nucleotide-composition.
3289
- #
3290
- # In other words, we can do a DNA string with 25% A, G, C, T each.
3291
- # ========================================================================= #
3292
- def create_balanced_composition(i = nil)
3293
- string = ''.dup # The return string.
3294
- if i.nil?
3295
- n_nucleotides_to_be_generated = 1000 # Default.
3296
- # In this case, go interactive.
3297
- erev 'Please enter the percentage of each nucleotide next.'
3298
- ee 'A: '
3299
- a = $stdin.gets.chomp.to_i
3300
- ee 'T: '
3301
- t = $stdin.gets.chomp.to_i
3302
- ee 'C: '
3303
- c = $stdin.gets.chomp.to_i
3304
- erev 'G is automatically calculated.'
3305
- g = 100 - (a + t + c)
3306
- ee 'G: '
3307
- # The following is not yet finished.
3308
- string << ('A' * a)+('T' * t)+('C' * c)+('G' * g)
3309
- else
3310
- i = 1000 if i.nil? or (i.is_a?(Array) and i.empty?) # The default.
3311
- n_nucleotides_to_be_generated = i
3312
- # ===================================================================== #
3313
- # Otherwise, we assume it to be 25% for each nucleotide. The following
3314
- # code will ensure that.
3315
- # ===================================================================== #
3316
- n_times = n_nucleotides_to_be_generated.to_i / 4
3317
- n_times.times {
3318
- _ = return_dna_nucleotides # Get all four entries first.
3319
- _.shuffle.each {|nucleotide|
3320
- string << nucleotide
3321
- }
3322
- }
3323
- end
3324
- erev "Note: we will assume the target size will "\
3325
- "be #{n_nucleotides_to_be_generated.to_s} nucleotides."
3326
- return string # The nucleotide-string to be returned.
3327
- end
3328
-
3329
- # ========================================================================= #
3330
- # === interactive_use_of_levensthein
3331
- # ========================================================================= #
3332
- def interactive_use_of_levensthein(
3333
- i = all_arguments?
3334
- )
3335
- require 'bioroebe/string_matching/levensthein.rb'
3336
- erev 'You want to use class '+steelblue('Bioroebe::Levensthein')+
3337
- rev+'. This class needs two'
3338
- erev 'input sequences (defaulting to nucleotides).'
3339
- e
3340
- if i.nil? or i.empty?
3341
- erev 'Input the nucleotide sequence to the '+
3342
- slateblue('first')+rev+' sequence:'
3343
- print ' '; sequence1 = $stdin.gets.chomp
3344
- e
3345
- erev 'Input the nucleotide sequence to the '+
3346
- slateblue('second')+rev+' sequence:'
3347
- print ' ';
3348
- sequence2 = $stdin.gets.chomp
3349
- ::Bioroebe::Levensthein.new(sequence1, sequence2)
3350
- else
3351
- ::Bioroebe::Levensthein.new(i)
3352
- end
3353
- end
3354
-
3355
- # ========================================================================= #
3356
- # === considering_changing_the_title_of_the_kde_konsole_tab
3357
- # ========================================================================= #
3358
- def considering_changing_the_title_of_the_kde_konsole_tab(
3359
- to_this_title = 'BioRoebe'
3360
- )
3361
- if ::Bioroebe.try_to_rename_kde_konsole? and
3362
- Object.const_defined? :Roebe # For project roebe.
3363
- require 'roebe/classes/kde/kde_konsole/kde_konsole.rb'
3364
- Roebe.change_konsole_tab_title(to_this_title, :be_silent)
3365
- end
3366
- end
3367
-
3368
- # ========================================================================= #
3369
- # === show_xorg_buffer
3370
- # ========================================================================= #
3371
- def show_xorg_buffer
3372
- if @internal_hash[:use_xsel]
3373
- esystem 'xsel -o'
3374
- end
3375
- end
3376
-
3377
- # ========================================================================= #
3378
- # === open_1igt_in_the_browser
3379
- # ========================================================================= #
3380
- def open_1igt_in_the_browser
3381
- _ = 'https://www.rcsb.org/structure/1igt'
3382
- e; e _; e
3383
- open_in_browser _
3384
- end
3385
-
3386
-
3387
- # ========================================================================= #
3388
- # === show_the_aminoacids_frequencies
3389
- # ========================================================================= #
3390
- def show_the_aminoacids_frequencies
3391
- pp YAML.load_file(FILE_AMINO_ACIDS_FREQUENCY)
3392
- end
3393
-
3394
- # ========================================================================= #
3395
- # === is_this_a_cd_alias?
3396
- #
3397
- # The reason why this does a check for :Rcfiles is because not every
3398
- # user may have the rcfiles-project available.
3399
- # ========================================================================= #
3400
- def is_this_a_cd_alias?(i)
3401
- Object.const_defined?(:Rcfiles) and
3402
- ::Rcfiles::DirectoryAliases.is_this_input_a_cd_alias?(i)
3403
- end
3404
-
3405
- # ========================================================================= #
3406
- # === print_rev
3407
- # ========================================================================= #
3408
- def print_rev
3409
- print rev
3410
- end
3411
-
3412
- # ========================================================================= #
3413
- # === try_to_run_rnalfold_on_this_file
3414
- # ========================================================================= #
3415
- def try_to_run_rnalfold_on_this_file(i)
3416
- if File.exist? i
3417
- esystem("RNALfold --infile=#{i}")
3418
- else
3419
- erev 'No file called `'+sfile(i)+rev+'` exists.'
3420
- end
3421
- end
3422
-
3423
- require 'bioroebe/utility_scripts/compacter.rb'
3424
- # ========================================================================= #
3425
- # === compact_file
3426
- #
3427
- # Delegate into class Bioroebe::Compacter.
3428
- # ========================================================================= #
3429
- def compact_file(this_file = nil)
3430
- ::Bioroebe::Compacter.new(this_file)
3431
- end
3432
-
3433
- # ========================================================================= #
3434
- # === return_dna_nucleotides
3435
- #
3436
- # This method will return the Array holding A, T, C and G (the four
3437
- # DNA nucleotides).
3438
- # ========================================================================= #
3439
- def return_dna_nucleotides
3440
- %w( A T C G )
3441
- end
3442
-
3443
- # ========================================================================= #
3444
- # === feedback_version
3445
- # ========================================================================= #
3446
- def feedback_version
3447
- erev version?
3448
- end
3449
-
3450
-
3451
- require 'bioroebe/string_matching/find_longest_substring_via_LCS_algorithm.rb'
3452
- # ========================================================================= #
3453
- # === find_longest_substring_via_LCS
3454
- #
3455
- # To invoke this, try:
3456
- #
3457
- # longest_substring? ATTATTGTT | ATTATTCTT
3458
- #
3459
- # ========================================================================= #
3460
- def find_longest_substring_via_LCS(i)
3461
- i = i.join(' | ') if i.is_a? Array
3462
- ::Bioroebe::FindLongestSubstringViaLCSalgorithm.new(i) { :do_also_show_the_two_sequences }
3463
- end
3464
-
3465
- require 'bioroebe/aminoacids/deduce_aminoacid_sequence.rb'
3466
- # ========================================================================= #
3467
- # === deduce_this_aminoacid_sequence
3468
- #
3469
- # Thi method will show the possible codons for an aminoacid sequence.
3470
- #
3471
- # It will display the result in an ASCII table, on the commandline.
3472
- #
3473
- # Trigger this like so:
3474
- #
3475
- # sof
3476
- # sof Lys-Ser-Pro-Ser-Leu-Asn-Ala-Ala-Lys
3477
- # sof Thr Thr Glu Ala Val Glu Ser Thr Val Ala Thr Leu Glu Asp Ser
3478
- # sof T-T-G-A-V-G-S-T-V
3479
- #
3480
- # ========================================================================= #
3481
- def deduce_this_aminoacid_sequence(
3482
- i = 'Lys-Ser-Pro-Ser-Leu-Asn-Ala-Ala-Lys',
3483
- show_the_rna_sequence = true
3484
- )
3485
- if i.nil? # This is the default.
3486
- if aminoacid_sequence?
3487
- i = aminoacid_sequence?
3488
- else
3489
- i = 'Lys-Ser-Pro-Ser-Leu-Asn-Ala-Ala-Lys'
3490
- end
3491
- end
3492
- DeduceAminoacidSequence.new(i, show_rna: show_the_rna_sequence) # bl DeduceAminoacidSequence
3493
- end
3494
-
3495
- # ========================================================================= #
3496
- # === open_in_uniprot
3497
- #
3498
- # This method will open the remote, associated URL with the protein
3499
- # at hand.
3500
- # ========================================================================= #
3501
- def open_in_uniprot(
3502
- i = 'A1XPA3'
3503
- )
3504
- i = 'A1XPA3' if i.nil? # <- Ensure a default.
3505
- _ = 'https://www.uniprot.org/uniprot/?query='+i+'&sort=score'
3506
- erev _
3507
- set_xclip(_) if configuration?.additionally_set_xorg_buffer
3508
- open_in_browser(_)
3509
- end
3510
-
3511
- # ========================================================================= #
3512
- # === lpad?
3513
- # ========================================================================= #
3514
- def lpad?
3515
- ' '
3516
- end
3517
-
3518
- # ========================================================================= #
3519
- # === purge
3520
- #
3521
- # This method can be used to purge nucleotides. E. g. if you want to
3522
- # get rid of all Thymines.
3523
- #
3524
- # To invoke this method, do:
3525
- #
3526
- # purge thymines
3527
- #
3528
- # ========================================================================= #
3529
- def purge(i)
3530
- if i.nil?
3531
- erev 'Please provide some input such as "thymine" or "t".'
3532
- return
3533
- end
3534
- if i.is_a? Array
3535
- else
3536
- erev "Now purging all #{simp(i)}#{rev}:"
3537
- case i
3538
- when 'thymine','thymines'
3539
- i = 'T'
3540
- when 'cytosine','cytosines'
3541
- i = 'C'
3542
- when 'guanine','guanines'
3543
- i = 'G'
3544
- end
3545
- new_string = sequence?.tr(i.upcase, '')
3546
- set_sequence(new_string)
3547
- show_string
3548
- end
3549
- end
3550
-
3551
- # ========================================================================= #
3552
- # === interactively_pick_colour
3553
- #
3554
- # This method can be used to interactively assign a new colour for
3555
- # the rev() part.
3556
- # ========================================================================= #
3557
- def interactively_pick_colour
3558
- erev 'You can pick a Konsole colour here, for rev(), which is '\
3559
- 'the default colour.'
3560
- erev 'In order to make it a bit easier for you, we will show 5 '\
3561
- 'random examples for this:'
3562
- string = ''
3563
- 5.times {
3564
- string << ::Colours.colours.sample << ', '
3565
- }
3566
- erev ' '+string
3567
- erev 'Input your Colours colour next:'
3568
- user_input = $stdin.gets.chomp
3569
- colour_to_use = ::Colours.send(user_input.to_sym)
3570
- erev colour_to_use+'Testing: '+rev
3571
- # ======================================================================= #
3572
- # Next, set a new default colour to use.
3573
- # ======================================================================= #
3574
- ::Bioroebe.set_default_colour(colour_to_use)
3575
- end
3576
-
3577
- # ========================================================================= #
3578
- # === sanitize_input
3579
- #
3580
- # Right now this method only gets rid of '-' but check if the string
3581
- # contains '-' first before calling this method.
3582
- # ========================================================================= #
3583
- def sanitize_input(i)
3584
- i.tr('-','')
3585
- end
3586
-
3587
- # ========================================================================= #
3588
- # === main_colour
3589
- # ========================================================================= #
3590
- def main_colour
3591
- ::Bioroebe.main_colour
3592
- end; alias main_col main_colour # === main_col
3593
-
3594
- begin
3595
- require 'easycompile'
3596
- rescue LoadError; end
3597
-
3598
- # ========================================================================= #
3599
- # === copy_bioroebe_shell_before_quitting
3600
- #
3601
- # Use this method to copy the Bioroebe shell before quitting.
3602
- #
3603
- # We will make use of class InstallRubyProject for this.
3604
- #
3605
- # This was disabled as of Jan 2016. The reason is that it confuses me
3606
- # too much, seriously. Perhaps I will re-enable it again at a later time.
3607
- # ========================================================================= #
3608
- def copy_bioroebe_shell_before_quitting
3609
- _ = RUBY_SRC+'bioroebe/'
3610
- begin
3611
- require 'roebe/classes/install_ruby_project.rb'
3612
- rescue LoadError; end
3613
- if Object.const_defined? :Roebe
3614
- irp = Roebe::InstallRubyProject.new(_, false)
3615
- irp.run
3616
- elsif on_roebe?
3617
- erev 'The project custom_methods/install_ruby_project is not available.'
3618
- erev 'We will install it now.'
3619
- cd '$RSRC/roebe/'
3620
- Easycompile.rinstall2 if Object.const_defined? :Easycompile
3621
- end if false # Disabled it here. Not sure if I will re-enable it.
3622
- end
3623
-
3624
- # ========================================================================= #
3625
- # === install (install tag)
3626
- # ========================================================================= #
3627
- def install(i)
3628
- case i.to_s
3629
- when 'bioruby','bioroebe','bio','1', # install bioroebe.
3630
- :default
3631
- erev 'We now install Bioruby.'
3632
- file_location = '/home/x/src/bioruby/bioruby-2.0.0.tar.xz'
3633
- begin
3634
- Easycompile::Easycompile.new(file_location) # Make use of Easycompile to install it.
3635
- rescue Exception => error
3636
- pp error
3637
- end
3638
- else
3639
- ewarn 'Do not know how to install `'+simp(i)+'`.'
3640
- end
3641
- end
3642
-
3643
- # ========================================================================= #
3644
- # === translate_dna_into_aminoacid
3645
- #
3646
- # The first argument should be the DNA sequence.
3647
- # ========================================================================= #
3648
- def translate_dna_into_aminoacid(
3649
- i = dna_sequence?,
3650
- frame = 1
3651
- )
3652
- i = dna_sequence? if i.nil?
3653
- if i.is_a? Array
3654
- i.each {|entry| translate_dna_into_aminoacid(entry) }
3655
- else
3656
- i.upcase!
3657
- case frame
3658
- when 1 # normal frame, default.
3659
- when 2 # one shifted
3660
- i[0,1] = ''
3661
- when 3 # two shifted
3662
- i[0,1] = ''
3663
- i[0,1] = ''
3664
- end
3665
- # ===================================================================== #
3666
- # Next, return the result.
3667
- # ===================================================================== #
3668
- return ::Bioroebe.translate_dna_into_aminoacid(i)
3669
- end
3670
- end; alias translate_dna_into_aminoacid_frame1 translate_dna_into_aminoacid # === translate_dna_into_aminoacid_frame1
3671
-
3672
- # ========================================================================= #
3673
- # === print_aa_table
3674
- #
3675
- # Use this method to print an overview over the aminoacid sequence that
3676
- # was assigned.
3677
- # ========================================================================= #
3678
- def print_aa_table(optional_arguments = all_arguments?)
3679
- require 'bioroebe/aminoacids/display_aminoacid_table.rb'
3680
- if optional_arguments.is_a?(Array) and !optional_arguments.empty?
3681
- _ = optional_arguments
3682
- else
3683
- _ = aminoacids?
3684
- end
3685
- _ = _.first if _.is_a? Array
3686
- Bioroebe::DisplayAminoacidTable.new(_)
3687
- end
3688
-
3689
- # ========================================================================= #
3690
- # === codon_to_aminoacid
3691
- #
3692
- # Translate a codon into an aminoacid through this method.
3693
- # ========================================================================= #
3694
- def codon_to_aminoacid(i)
3695
- Bioroebe.codon_to_aminoacid(i)
3696
- end
3697
-
3698
- require 'bioroebe/enzymes/return_sequence_that_is_cut_via_restriction_enzyme.rb'
3699
- # ========================================================================= #
3700
- # === append (append tag)
3701
- #
3702
- # You can use this to simply append to the main string.
3703
- # ========================================================================= #
3704
- def append(i)
3705
- i = i.join.strip if i.is_a? Array
3706
- i = i.to_s
3707
- case i # case tag
3708
- # ======================================================================= #
3709
- # === start
3710
- # ======================================================================= #
3711
- when 'start'
3712
- i = ::Bioroebe.start_codon?
3713
- erev 'We will append the START codon '+sfancy(i)+rev+' next.'
3714
- # ======================================================================= #
3715
- # === stop
3716
- # ======================================================================= #
3717
- when 'stop'
3718
- i = ::Bioroebe.stop_codons?.sample
3719
- erev 'We will append the STOP codon '+sfancy(i)+rev+' next.'
3720
- when 'shine'
3721
- i = 'AGGAGGT' # Can only add nucleotides to the main sequence.
3722
- erev 'We will append the '+mediumslateblue('Shine Dalgarno')+
3723
- rev+' (SD) sequence '+sfancy("#{i}-3")+rev+' next.'
3724
- end
3725
- if i =~ /^\d+$/ # If input is only numbers.
3726
- erev "Only numbers were given: Adding #{sfancy(i.to_s)}#{rev}"\
3727
- " random nucleotides to the main string next."
3728
- new_string = ''.dup
3729
- i.to_i.times { new_string << return_random_nucleotide }
3730
- i = new_string
3731
- end
3732
- # ======================================================================= #
3733
- # === Check that we add only DNA or RNA nucleotides past this point
3734
- # ======================================================================= #
3735
- if only_nucleotides?(i)
3736
- erev "Now appending #{simp(i)}#{rev}."
3737
- sequence_object? << i # Next, append to the sequence object here.
3738
- else
3739
- # ===================================================================== #
3740
- # The user may also wish to append a restriction site, such
3741
- # as via add EcoRI. We need to enable this here.
3742
- # ===================================================================== #
3743
- _ = ::Bioroebe.return_sequence_that_is_cut_via_restriction_enzyme(i, :no_colours)
3744
- if _
3745
- _.tr!('|','')
3746
- erev 'Now appending '+simp(_)+rev+'.'
3747
- sequence_object? << _ # Next, append to the sequence object here.
3748
- show_dna_sequence
3749
- else
3750
- erev 'Can not add the sequence '+simp(i)+rev+' because there are '\
3751
- 'non-nucleotides in it.'
3752
- end
3753
- end
3754
- end
3755
-
3756
- require 'bioroebe/count/count_amount_of_nucleotides.rb'
3757
- # ========================================================================= #
3758
- # === analyze_dna_string
3759
- #
3760
- # This method presently only counts the amount of nucleotides found
3761
- # in the given DNA string at hand.
3762
- #
3763
- # We use the class Bioroebe::CountAmountOfNucleotides, in
3764
- # bl count_amount_of_nucleotides.rb
3765
- # ========================================================================= #
3766
- def analyze_dna_string(
3767
- i = dna_string?
3768
- )
3769
- # ======================================================================= #
3770
- # Set some default values:
3771
- # ======================================================================= #
3772
- i = dna_string? if i.nil?
3773
- if i.is_a? Array and i.empty?
3774
- i = dna_string?
3775
- end
3776
- ::Bioroebe::CountAmountOfNucleotides.new(
3777
- i, :use_cliner
3778
- ) {{ use_colours: use_colours? }} # bl $BIOROEBE/count_amount_of_nucleotides.rb
3779
- end
3780
-
3781
- # ========================================================================= #
3782
- # === could_this_be_an_amino_acid?
3783
- #
3784
- # If the input is an amino acid, we return true for this method here.
3785
- #
3786
- # Characters such as '?' will be removed.
3787
- #
3788
- # Invocation examples:
3789
- #
3790
- # phenylalanine
3791
- # glycin
3792
- # glycine
3793
- #
3794
- # ========================================================================= #
3795
- def could_this_be_an_amino_acid?(i)
3796
- i = i.to_s.downcase
3797
- i.delete!('?') if i.include? '?' # Get rid of '?' tokens.
3798
- return_value = false
3799
- unless i.empty?
3800
- # ===================================================================== #
3801
- # First, we check here for german names. These names are kept in
3802
- # the file called
3803
- # 'amino_acids_long_name_to_one_letter.yml'
3804
- # ===================================================================== #
3805
- unless AMINO_ACIDS_RESTE.has_key?(i)
3806
- if AMINO_ACIDS_LONG_NAME_TO_ONE_LETTER.has_key?(i)
3807
- i = AMINO_ACIDS_LONG_NAME_TO_ONE_LETTER[i]
3808
- i = AMINO_ACIDS_ENGLISH[i].downcase
3809
- end
3810
- end
3811
- if AMINO_ACIDS_RESTE.has_key?(i)
3812
- return_value = true
3813
- end
3814
- end
3815
- return return_value
3816
- end
3817
-
3818
- require 'bioroebe/genbank/genbank_flat_file_format_generator.rb'
3819
- # ========================================================================= #
3820
- # === chunked_display
3821
- #
3822
- # This method will show a "chunked" display of the nucleotides that
3823
- # is similar to the FASTA display at NCBI.
3824
- #
3825
- # Invoke via:
3826
- #
3827
- # cdisplay
3828
- #
3829
- # ========================================================================= #
3830
- def chunked_display(
3831
- i = dna_sequence?
3832
- )
3833
- i = i.join if i.is_a? Array
3834
- i = dna_sequence? if i.nil?
3835
- i = dna_sequence? if i.empty?
3836
- ::Bioroebe::GenbankFlatFileFormatGenerator.new(i) # bl $BIOROEBE/genbank/genbank_flat_file_format_generator.rb
3837
- end
3838
-
3839
- require 'bioroebe/toplevel_methods/fasta_and_fastq.rb'
3840
- # ========================================================================= #
3841
- # === automatically_rename_this_fasta_file
3842
- # ========================================================================= #
3843
- def automatically_rename_this_fasta_file(i)
3844
- [i].flatten.compact.each {|this_fasta_file|
3845
- Bioroebe.automatically_rename_this_fasta_file(this_fasta_file)
3846
- }
3847
- end
3848
-
3849
- # ========================================================================= #
3850
- # === reverse_complement (reverse complement tag)
3851
- #
3852
- # Reverse-Complement a given sequence at hand. In other words, if given
3853
- # a sequence of DNA or RNA, we will first build the complement to
3854
- # that DNA sequence, and then reverse that complement.
3855
- #
3856
- # In the shell interface, you can test this like so:
3857
- #
3858
- # assign AAATTT; reverse_complement
3859
- #
3860
- # ========================================================================= #
3861
- def reverse_complement(i = sequence?)
3862
- i = sequence? if i.nil?
3863
- if i.nil?
3864
- report_that_a_string_must_be_assigned_first
3865
- erev 'Example:'
3866
- e
3867
- e simp(' assign TTATTA')
3868
- e
3869
- else
3870
- result = padding?+leading_five_prime+
3871
- sfancy(
3872
- return_complement(i.reverse)
3873
- )+rev+
3874
- trailing_three_prime
3875
- result << ' ('+orange(i.size)+rev+' nucleotides)'
3876
- erev result
3877
- end
3878
- end
3879
-
3880
- # ========================================================================= #
3881
- # === translate_dna_into_aminoacid_frame2
3882
- # ========================================================================= #
3883
- def translate_dna_into_aminoacid_frame2(i = nil)
3884
- translate_dna_into_aminoacid(i, 2) # Frame 2.
3885
- end
3886
-
3887
- # ========================================================================= #
3888
- # === translate_dna_into_aminoacid_frame3
3889
- # ========================================================================= #
3890
- def translate_dna_into_aminoacid_frame3(i = nil)
3891
- translate_dna_into_aminoacid(i, 3) # Frame 3.
3892
- end
3893
-
3894
- # ========================================================================= #
3895
- # === set_log_dir
3896
- # ========================================================================= #
3897
- def set_log_dir(
3898
- i = first_argument?
3899
- )
3900
- i = i.dup if i.frozen?
3901
- i << '/' unless i.end_with? '/'
3902
- # ======================================================================= #
3903
- # === Handle blocks next
3904
- # ======================================================================= #
3905
- if block_given?
3906
- yielded = yield
3907
- case yielded
3908
- when :be_verbose
3909
- erev 'Will be using '+sdir(i)+rev+' as the new log-directory.'
3910
- end
3911
- end
3912
- unless File.directory? i
3913
- mkdir(i)
3914
- end
3915
- ::Bioroebe.set_log_dir(i)
3916
- end
3917
-
3918
-
3919
- require 'bioroebe/conversions/convert_aminoacid_to_dna.rb'
3920
- # ========================================================================= #
3921
- # === backtranseq
3922
- #
3923
- # Translate an Aminoacid Sequence back into the most likely DNA sequence
3924
- # that would code for this sequence/protein. Thus, this method translates
3925
- # from Aminoacids to DNA sequence - in other words it does a
3926
- # "reverse-lookup".
3927
- #
3928
- # Currently, we hardcode to the homo sapiens frequency codon table, but
3929
- # at a later time, we will probably change to a more flexible layout,
3930
- # to allow a backtranseq for more organisms.
3931
- # ========================================================================= #
3932
- def backtranseq(
3933
- i = aminoacid_sequence?,
3934
- output_as_dna_or_rna = :dna
3935
- )
3936
- sequence = ConvertAminoacidToDNA[i].to_str.delete('-')
3937
- erev lpad?+
3938
- leading_five_prime+
3939
- sfancy(sequence)+
3940
- rev+
3941
- trailing_three_prime
3942
- erev 'Note that we have also assigned the above to be the new DNA sequence.'
3943
- assign_sequence(sequence, :be_silent)
3944
- end; alias translate_aminoacids_into_dna backtranseq # === translate_aminoacids_into_dna
3945
-
3946
- # ========================================================================= #
3947
- # === do_analyze_sequence
3948
- #
3949
- # Use this method to find unique sequences.
3950
- # ========================================================================= #
3951
- def do_analyze_sequence(
3952
- i = sequence?
3953
- )
3954
- if i.is_a?(Array) and i.empty?
3955
- i = sequence?
3956
- end
3957
- if i.empty? and (!aminoacid_sequence?)
3958
- erev 'Please first assign a sequence.'
3959
- elsif aminoacid_sequence?
3960
- aminoacid_sequence = aminoacid_sequence?
3961
- show_protein_composition(aminoacid_sequence)
3962
- # ===================================================================== #
3963
- # Also show the molecular mass.
3964
- # ===================================================================== #
3965
- molecular_mass_of_amino_acids_in_this_sequence(aminoacid_sequence)
3966
- else
3967
- erev 'Searching for '+steelblue('NLS sequences')+rev+' first:'
3968
- run_nls_search
3969
- end
3970
- end
3971
-
3972
- # ========================================================================= #
3973
- # === find_kdel_sequence
3974
- # ========================================================================= #
3975
- def find_kdel_sequence
3976
- # ======================================================================= #
3977
- # We must operate on the aminoacid-sequence next.
3978
- # ======================================================================= #
3979
- aminoacid_sequence = aminoacid_sequence?.to_s
3980
- scan_result = aminoacid_sequence.scan(/KDEL/)
3981
- has_kdel = scan_result.empty?
3982
- if has_kdel
3983
- erev 'This sequence has at the least '+
3984
- steelblue('one')+' KDEL sequence. '\
3985
- '(Has '+scan_result.size.to_s+')'
3986
- else
3987
- erev 'This sequence does not have any KDEL sequence.'
3988
- end
3989
- end
3990
-
3991
- # ========================================================================= #
3992
- # === calculcate_at_content
3993
- #
3994
- # Calculate the AT content of a DNA or RNA sequence.
3995
- #
3996
- # Usage example:
3997
- #
3998
- # set_dna ATGCGCGCGCGAACGATGCATGACTGCTAGTCGACA; calc_at_content
3999
- #
4000
- # ========================================================================= #
4001
- def calculcate_at_content(
4002
- i = dna_sequence?
4003
- )
4004
- if i.is_a? Array
4005
- i = i.first
4006
- end
4007
- i = dna_sequence? if i.nil?
4008
- i.upcase!
4009
- total = i.size
4010
- n_A = i.count('A')
4011
- n_T = i.count('T')
4012
- result = ( (n_A + n_T) * 100 ) / total
4013
- erev 'The AT content of this sequence is '+
4014
- simp(result.to_s)+rev+' %.'
4015
- end
4016
-
4017
- # ========================================================================= #
4018
- # === run_sizeseq
4019
- #
4020
- # This method essentially does what the Emboss sizeseq is doing.
4021
- # ========================================================================= #
4022
- def run_sizeseq
4023
- last_fasta_entry?.do_sort_by_size
4024
- end
4025
-
4026
- # ========================================================================= #
4027
- # === open_my_files (open tag, files tag)
4028
- #
4029
- # This opens some bioroebe-related files.
4030
- # ========================================================================= #
4031
- def open_my_files
4032
- array_my_files = []
4033
- array_my_files << BIOROEBE_AT_HOME+'shell/bioshell.rb'
4034
- array_my_files << BIOROEBE_AT_HOME+'shell/help.rb'
4035
- array_my_files << BIOROEBE_AT_HOME+'shell/menu.rb'
4036
- array_my_files << BIOROEBE_AT_HOME+'bioroebe.rb'
4037
- array_my_files << BIOROEBE_AT_HOME+'constants/constants.rb'
4038
- array_my_files << RUBY_SRC+'/bioroebe/doc/todo/todo.md'
4039
- # array_my_files << BIOROEBE+'/count_amount_of_nucleotides.rb'
4040
- array_my_files.each {|file| open_this_file_in_editor(file) }
4041
- end
4042
-
4043
- # ========================================================================= #
4044
- # === pubmed
4045
- #
4046
- # Open a pubmed citation stuff.
4047
- # ========================================================================= #
4048
- def pubmed(number = 125512)
4049
- if number.is_a? Array
4050
- number = number.join(' ').strip
4051
- end
4052
- use_this_url = 'https://pubmed.ncbi.nlm.nih.gov/'.dup
4053
- if number and !number.nil?
4054
- use_this_url << '?term='+number.to_s
4055
- end
4056
- ::Bioroebe.open_in_browser(use_this_url)
4057
- end
4058
-
4059
- # ========================================================================= #
4060
- # === perform_a_pubmed_search
4061
- # ========================================================================= #
4062
- def perform_a_pubmed_search(i)
4063
- if i.is_a? Array
4064
- i = i.first
4065
- end
4066
- search_term = i.dup.delete('=')
4067
- url = 'https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&term='+
4068
- search_term
4069
- dataset = open(url).read
4070
- # =================================================================== #
4071
- # Grab the IDs next - this functionality is very unfinished as of
4072
- # right now (December 2018):
4073
- # =================================================================== #
4074
- id_matches = dataset.scan(/<Id>\d+<\/Id>/)
4075
- unless id_matches.empty?
4076
- e
4077
- erev 'The following '+sfancy(id_matches.size.to_s)+
4078
- rev+' IDs were found:'
4079
- e
4080
- id_matches.each {|entry|
4081
- erev ' '+sfancy(entry.delete('Id</>'))+rev
4082
- }
4083
- e
4084
- end
4085
- end
4086
-
4087
- # ========================================================================= #
4088
- # === what_sequence_is_this?
4089
- #
4090
- # This method attempts to find common sequences.
4091
- # ========================================================================= #
4092
- def what_sequence_is_this?(
4093
- i = dna_sequence?
4094
- )
4095
- erev 'The sequence length is '+i.size.to_s+'.'
4096
- # ======================================================================= #
4097
- # Obtain the corresponding aminoacid sequence next.
4098
- # ======================================================================= #
4099
- aa_sequence = ::Bioroebe.dna_to_aa(i)
4100
- if aa_sequence.include? ::Bioroebe.ubiquitin
4101
- erev 'The aminoacid sequence has at least one Ubiquitin-related sequence.'
4102
- end
4103
- end
4104
-
4105
- # ========================================================================= #
4106
- # === feedback_where_files_are_kept_locally
4107
- #
4108
- # We feedback where some files are kept, like the restriction enzymes.
4109
- # ========================================================================= #
4110
- def feedback_where_files_are_kept_locally
4111
- erev 'The restriction enzymes are kept here:'
4112
- e
4113
- e " #{sfile(::Bioroebe.restriction_enzymes_file)}"
4114
- e
4115
- erev 'The files with the mass table of the amino acids is kept here:'
4116
- e
4117
- e " #{sfile(::Bioroebe::FILE_AMINO_ACIDS_MASS_TABLE)}"
4118
- e
4119
- report_where_we_store
4120
- end
4121
-
4122
- # ========================================================================= #
4123
- # === count_amount_of_aminoacids
4124
- # ========================================================================= #
4125
- def count_amount_of_aminoacids(i)
4126
- ::Bioroebe::CountAmountOfAminoacids.new(i)
4127
- end
4128
-
4129
- # ========================================================================= #
4130
- # === freeze_the_main_sequence
4131
- # ========================================================================= #
4132
- def freeze_the_main_sequence
4133
- @internal_hash[:the_main_sequence_is_frozen] = true
4134
- end
4135
-
4136
- # ========================================================================= #
4137
- # === unfreeze_the_main_sequence
4138
- # ========================================================================= #
4139
- def unfreeze_the_main_sequence
4140
- @internal_hash[:the_main_sequence_is_frozen] = false
4141
- end
4142
-
4143
- # ========================================================================= #
4144
- # === is_the_main_sequence_frozen?
4145
- # ========================================================================= #
4146
- def is_the_main_sequence_frozen?
4147
- @internal_hash[:the_main_sequence_is_frozen]
4148
- end
4149
-
4150
- # ========================================================================= #
4151
- # === report_that_the_main_sequence_is_frozen
4152
- # ========================================================================= #
4153
- def report_that_the_main_sequence_is_frozen
4154
- e 'The main sequence is frozen and can not be modified anymore.'
4155
- end
4156
-
4157
- # ========================================================================= #
4158
- # === f?
4159
- # ========================================================================= #
4160
- def f?
4161
- @internal_hash[:first_argument]
4162
- end; alias f f? # === f
4163
- alias first_argument? f? # === first_argument?
4164
-
4165
- # ========================================================================= #
4166
- # === remaining_arguments?
4167
- # ========================================================================= #
4168
- def remaining_arguments?
4169
- @internal_hash[:remaining_arguments]
4170
- end
4171
-
4172
- # ========================================================================= #
4173
- # === add_poly_a_sequence
4174
- #
4175
- # Use this method to tag a PolyA sequence to the 3' end of a mRNA.
4176
- #
4177
- # First, the mRNA will be cleaved by the enzyme CPSF, usually at
4178
- # the sequence AAUAAA (most common one, but variants exist).
4179
- # AAUAAA is found in 90% of all sequenced polyadenylation elements.
4180
- # ========================================================================= #
4181
- def add_poly_a_sequence
4182
- this_sequence = 'A' * 250
4183
- @internal_hash[:rna].append(this_sequence)
4184
- end
4185
-
4186
- # ========================================================================= #
4187
- # === use_expand_cd_aliases?
4188
- # ========================================================================= #
4189
- def use_expand_cd_aliases?
4190
- ::Bioroebe::Configuration.use_expand_cd_aliases?
4191
- end
4192
-
4193
- # ========================================================================= #
4194
- # === set_save_file
4195
- # ========================================================================= #
4196
- def set_save_file(
4197
- i = :default
4198
- )
4199
- case i
4200
- # ======================================================================= #
4201
- # === :default_fasta
4202
- # ======================================================================= #
4203
- when :default_fasta
4204
- i = return_pwd+'standard_fasta.fa'
4205
- # ======================================================================= #
4206
- # === :pwd
4207
- # ======================================================================= #
4208
- when :pwd
4209
- return_pwd+File.basename(save_file?)
4210
- # ======================================================================= #
4211
- # === :default
4212
- # ======================================================================= #
4213
- when :default
4214
- i = Bioroebe.log_dir?+
4215
- File.basename(save_file?)
4216
- end
4217
- @internal_hash[:save_file] = i
4218
- end
4219
-
4220
- # ========================================================================= #
4221
- # === save_file?
4222
- # ========================================================================= #
4223
- def save_file?
4224
- @internal_hash[:save_file]
4225
- end
4226
-
4227
- # ========================================================================= #
4228
- # === save_my_file (save tag)
4229
- #
4230
- # We .strip on the @sequence because I think it is better to not have
4231
- # any padding on it.
4232
- # ========================================================================= #
4233
- def save_my_file(&block)
4234
- _ = dna_sequence_as_string?
4235
- if _.empty?
4236
- erev 'Can not save anything as the main string is empty.'
4237
- else
4238
- erev 'Saving the main string now into the file `'+
4239
- sfile(save_file?)+
4240
- rev+'`.'
4241
- save_file(_.strip, save_file?)
4242
- end # string must be empty.
4243
- end
4244
-
4245
- # ========================================================================= #
4246
- # === remove_sequence
4247
- #
4248
- # Use this method to chop away from the beginning part of a nucleotide
4249
- # sequence.
4250
- # ========================================================================= #
4251
- def remove_sequence(i)
4252
- i = i.first if i.is_a? Array
4253
- i = i.to_i
4254
- if dna_sequence_as_string?.size == 0
4255
- erev 'Can not remove any more characters as we do not have a '\
4256
- 'sequence anymore.'
4257
- else
4258
- erev "Removing #{sfancy(i)}#{rev} characters from the "\
4259
- "start (left side; 5' end)."
4260
- _ = dna_sequence?
4261
- _.remove_n_characters_from_the_left_side(i)
4262
- this_sequence = _
4263
- set_dna_sequence(this_sequence)
4264
- end
4265
- end; alias remove remove_sequence # === remove (remove tag)
4266
-
4267
- # ========================================================================= #
4268
- # === return_complement
4269
- #
4270
- # This method is aliased to complement() as well (def complement).
4271
- #
4272
- # It will return the complement sequence to a given DNA/RNA sequence.
4273
- # ========================================================================= #
4274
- def return_complement(
4275
- i = dna_sequence?
4276
- )
4277
- return ::Bioroebe::NucleotideModule.complementary_strand(i)
4278
- end; alias complement return_complement # === complement (complement tag)
4279
- alias complement_sequence? return_complement # === complement_sequence?
4280
- alias reverse return_complement # === reverse (reverse tag)
4281
-
4282
- # ========================================================================= #
4283
- # === find_complementary_strand
4284
- #
4285
- # Invoke this via:
4286
- #
4287
- # 3'-ATGCCTGCC
4288
- #
4289
- # ========================================================================= #
4290
- def find_complementary_strand(i = dna_sequence?)
4291
- _ = i.strip # The original input.
4292
- if _.include? "3'-" and _.start_with?('3')
4293
- _ = _.gsub(/3'-/,'').
4294
- gsub(/-5'/,'').
4295
- gsub(/3'-/,'')
4296
- erev lpad?+leading_three_prime+
4297
- colourize_nucleotide(_, :do_not_add_anything_else)+
4298
- trailing_five_prime
4299
- end
4300
- result = lpad?+
4301
- colourize_nucleotide(
4302
- return_complement(i.reverse)
4303
- )
4304
- erev result
4305
- return result
4306
- end; alias show_complementary_strand find_complementary_strand # === show_complementary_strand
4307
-
4308
- # ========================================================================= #
4309
- # === Bioroebe::Shell[]
4310
- # ========================================================================= #
4311
- def self.[](i = '')
4312
- new(i)
4313
- end
4314
-
4315
- end
4316
-
4317
- # =========================================================================== #
4318
- # === Bioroebe.generate_pdf_tutorial
4319
- # =========================================================================== #
4320
- def self.generate_pdf_tutorial
4321
- ::Bioroebe::Shell.generate_pdf_tutorial
4322
- end
4323
-
4324
- # =========================================================================== #
4325
- # === Bioroebe.upload_this_pdf_file
4326
- # =========================================================================== #
4327
- def self.upload_this_pdf_file(i)
4328
- ::Bioroebe::Shell.upload_this_pdf_file(i)
4329
- end
4330
-
4331
- # =========================================================================== #
4332
- # === Bioroebe.shell
4333
- #
4334
- # This is the main method to instantiate the Shell component of the
4335
- # Bioroebe component.
4336
- # =========================================================================== #
4337
- def self.shell(i = ARGV)
4338
- ::Bioroebe::Shell.new(i)
4339
- end; self.instance_eval { alias start_shell shell } # === Bioroebe.start_shell
4340
-
4341
- end