Class: Bioroebe::Shell

Inherits:
CommandlineApplication show all
Defined in:
lib/bioroebe/shell/menu.rb,
lib/bioroebe/shell/shell.rb,
lib/bioroebe/shell/readline.rb,
lib/bioroebe/shell/help/class.rb

Overview

Bioroebe::Shell

Defined Under Namespace

Classes: Help

Constant Summary collapse

TRUNCATE_AT_N_ELEMENTS =
#

TRUNCATE_AT_N_ELEMENTS

If we display nucleotide strings, then by default, these may be very long. So the following constant will act as a threshold.

#
2000
SHALL_WE_DEBUG =
#

SHALL_WE_DEBUG

#
false
RUBY_SRC =
"#{HOME_DIRECTORY_OF_USER_X}programming/ruby/src/"
BIOROEBE =
ENV['HOME']
FILE_USE_SILENT_STARTUP =
#

FILE_USE_SILENT_STARTUP

#
"#{::Bioroebe.project_base_directory?}shell/configuration/use_silent_startup.yml"
MAIN_EDITOR =

else assume that we may be on windows.

'notepad++.exe'
MY_EDITOR =

MY_EDITOR

MAIN_EDITOR
BIOSHELL_SAVE_FILE =
'/home/Temp/bioroebe/shell_file.md'
HOME_DIR =

This is valid at home.

home_dir+'.gem/gems/bioroebe-'+
Bioroebe.version?.to_s+'/lib/bioroebe/'
DEFAULT_PADDING =
#

DEFAULT_PADDING

#
'  '
COMPLETION_PROC =
#

COMPLETION_PROC

#
proc { |s|
  (ARRAY_WITH_COMPLETIONS.grep(/^#{Regexp.escape(s.to_s)}/)+
  self.return_entries_in_the_current_directory.map {|entry|
    (entry+'/').squeeze('/')
  }).flatten
}

Constants inherited from CommandlineApplication

CommandlineApplication::OLD_VERBOSE_VALUE

Constants included from ColoursForBase

ColoursForBase::ARRAY_HTML_COLOURS_IN_USE

Constants inherited from Base

Base::NAMESPACE

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from CommandlineApplication

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

Methods included from BaseModule

#absolute_path, #default_file_read, #file_readlines

Methods included from CommandlineArguments

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

Methods included from ColoursForBase

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

Methods inherited from Base

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

Methods included from InternalHashModule

#internal_hash?, #reset_the_internal_hash

Methods included from InferTheNamespaceModule

#infer_the_namespace, #namespace?

Constructor Details

#initialize(commandline_arguments = ARGV, run_already = true) ⇒ Shell

#

initialize

#


186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
# File 'lib/bioroebe/shell/shell.rb', line 186

def initialize(
    commandline_arguments = ARGV,
    run_already           = true
  )
  reset # Must come first, to create @internal_hash.
  set_commandline_arguments(
    commandline_arguments
  )
  # ======================================================================= #
  # === Handle blocks next
  # ======================================================================= #
  if block_given?
    yielded = yield
    case yielded
    # ===================================================================== #
    # === :do_not_run_yet
    # ===================================================================== #
    when :do_not_run_yet
      run_already = false
    end
  end
  # ======================================================================= #
  # Intercept some important commandline arguments next. This must come
  # AFTER we invoked set_commandline_arguments().
  # ======================================================================= #
  case first?
  # ======================================================================= #
  # === no_colours
  #
  # This variant is different from the variant in menu() in that another
  # method will be called to disable the colours.
  #
  # Invocation example:
  #
  #   biosh --disable-colours
  #
  # ======================================================================= #
  when 'nocol',
       'noco',
       /^-?-?no(_|-| )?colou?rs?$/,
       /^-?-?disable(_|-| )?colours$/,
       'dcolours'
    disable_colours_in_an_extended_manner(:be_quiet)
  # ======================================================================= #
  # === bioroebe --help
  #
  # This entry-point will quickly show which options are available for
  # the bioshell.
  # ======================================================================= #
  when /^-?-?help$/
    show_commandline_options
  # ======================================================================= #
  # === bioshell --controller
  # ======================================================================= #
  when /^-?-?controller$/i
    require 'bioroebe/gui/gtk3/controller/controller.rb'
    ::Bioroebe.run_gtk_controller
    exit_program
  # ======================================================================= #
  # === bioshell --do-not-create-directories-on-startup
  # === bioshell --do-not-create-directories
  #
  # Do not create directories on startup.
  #
  # Invocation example:
  #
  #   bioshell --do-not-create-directories-on-startup
  #
  # ======================================================================= #
  when /^-?-?do(-|_| )?not(-|_| )?create(-|_| )?directories(-|_| )?on(-|_| )?startup$/i,
       /^-?-?do(-|_| )?not(-|_| )?create(-|_| )?directories$/i
    @internal_hash[:create_directories_on_startup_of_the_shell] = false
  # ======================================================================= #
  # === bioroebe --protein-to-dna
  #
  # This entry point will try to start the ruby-gtk3 protein-to-DNA
  # converting widget.
  # ======================================================================= #
  when /^-?-?protein(-|_| )?to(-|_| )?dna$/i
    require 'bioroebe/gui/gtk3/protein_to_DNA/protein_to_DNA.rb'
    ::Bioroebe::GUI::Gtk::ProteinToDNA.run_gtk3_widget
    exit
  # ======================================================================= #
  # === bioshell --permanently-disable-startup-intro
  # === bioshell --permanently-disable-startup-notice
  # === bioshell --permanently-no-startup-intro
  # === bioshell --permanently-no-startup-info
  # ======================================================================= #
  when /^-?-?permanently(-|_)?disable(-|_)?startup(-|_)?intro$/,
       /^-?-?permanently(-|_)?disable(-|_)?startup(-|_)?notice$/,
       /^-?-?permanently(-|_)?no(-|_)?startup(-|_)?intro$/,
       /^-?-?permanently(-|_)?no(-|_)?startup(-|_)?info$/
    permanently_disable_startup_intro
  # ======================================================================= #
  # === :no_commandline_arguments
  # ======================================================================= #
  when :no_commandline_arguments
    # ===================================================================== #
    # Simply pass through in this case.
    # ===================================================================== #
  # ======================================================================= #
  # === :exit_gracefully
  # ======================================================================= #
  when :exit_gracefully
    set_exit_gracefully
  # ======================================================================= #
  # === bioroebe --silent-startup
  # ======================================================================= #
  when /^-?-?silent(-|_)?startup$/,
       /^-?-?silent$/
    do_a_silent_startup
  # ======================================================================= #
  # === bioroebe --random-aminoacids=33
  # === bioroebe --n-aminoacids=33
  # ======================================================================= #
  when /^-?-?random(-|_)?aminoacids=(.+)$/i,
       /^-?-?n(-|_)?aminoacids=(.+)$/i
    n_aminoacids = $2.to_s.dup
    ::Bioroebe.create_random_aminoacids(n_aminoacids) { :do_report }
    exit
  # ======================================================================= #
  # === bioroebe --rnafold=cdna.MT.fa
  # ======================================================================= #
  when /^-?-?rnafold=(.+)$/
    try_to_run_rnalfold_on_this_file($1.to_s.dup)
    exit
  # ======================================================================= #
  # === bioroebe --fasta=/Depot/Bioroebe/Arabidopsis_thaliana_chromosome_5_sequence.fasta
  # ======================================================================= #
  when /^-?-?fasta=(.+)$/
    this_fasta_file = $1.to_s.dup
    if File.exist?
      handle_fasta(this_fasta_file)
    else
      e 'No file could be found at `'+sfile(this_fasta_file)+'`.'
    end
  # ======================================================================= #
  # === bioroebe --n-fasta-entries
  #
  # Usage example:
  #
  #   cd /root/Bioroebe/Downloads/; bioroebe --n-fasta-entries
  #
  # ======================================================================= #
  when /^-?-?n(-|_)?fasta(-|_)?entries$/
    require 'bioroebe/fasta/display_how_many_fasta_entries_are_in_this_directory.rb'
    ::Bioroebe::DisplayHowManyFastaEntriesAreInThisDirectory.new
    exit
  # ======================================================================= #
  # === bioroebe --split-this-fasta-file-into-chromosomes=Mus_musculus.GRCm38.ncrna.fa
  # ======================================================================= #
  when /^-?-?split(-|_)?this(-|_)?fasta(-|_)?file(-|_)?into(-|_)?chromosomes=(.+)$/i # $6
    _ = $6.to_s.dup
    require 'bioroebe/fasta/split_this_fasta_file_into_chromosomes/split_this_fasta_file_into_chromosomes.rb'
    ::Bioroebe::SplitThisFastaFileIntoChromosomes.new(_)
    exit
  # ======================================================================= #
  # === bioroebe --stats
  #
  # This entry-point will show some simple fasta-statistics, from
  # the current directory.
  #
  # Usage example:
  #
  #   cd /root/Bioroebe/Downloads/; bioroebe --stats
  #
  # ======================================================================= #
  when /^-?-?stats$/i,
       /^-?-?statistics$/i,
       /^-?-?fasta(-|_)?stats$/i
    require 'bioroebe/fasta/show_fasta_statistics.rb'
    ::Bioroebe.show_fasta_statistics(Dir['*'])
    exit
  # ======================================================================= #
  # === bioroebe --download=ftp://ftp.ensembl.org/pub/release-92/gtf/mus_musculus/
  #
  # This entry point allows us to download a remote program.
  #
  # Invocation example:
  #
  #   bioroebe --download=ftp://ftp.ensembl.org/pub/release-92/gtf/mus_musculus/
  #   bioroebe --download ftp://ftp.ensembl.org/pub/release-92/gtf/mus_musculus/
  #
  # Note that the second variant currently (April 2020) does not work -
  # let's see if we need it again in the future.
  # ======================================================================= #
  when /^-?-?download=(.+)/
    ::Bioroebe.download($1.to_s.dup)
  # ======================================================================= #
  # === bioroebe --sequence=150
  #
  # This entry point allows us to use any sequence, on startup.
  #
  # Invocation example:
  #
  #   bioroebe --sequence=1505
  #
  # ======================================================================= #
  when /^-?-?sequence (.+)/,
       /^-?-?sequence=(.+)/
    set_dna($1.to_s.dup, :be_quiet) # Be quiet here when doing the assignment.
  # ======================================================================= #
  # === bioroebe --show-exon-statistics-for=/tmp/praktikum/Mouse/chromosome_8/parsed/cdna.8.L100.global.gtf
  # ======================================================================= #
  when /^-?-?show(-|_)?exon(-|_)?statistics(-|_)?for=(.+)$/ # === $4
    ::Bioroebe.show_exon_statistics($4.to_s.dup)
    exit
  # ======================================================================= #
  # === bioroebe --sinatra
  # ======================================================================= #
  when /^-?-?sinatra$/i
    do_start_the_sinatra_interface
    return
  end
  run if run_already
end

Class Method Details

.[](i = ARGV) ⇒ Object

#

Bioroebe::Shell[]

#


11902
11903
11904
# File 'lib/bioroebe/shell/shell.rb', line 11902

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

.colour?Boolean

#

Bioroebe::Shell.colour?

Query-method over @default_colour.

#

Returns:

  • (Boolean)


140
141
142
# File 'lib/bioroebe/shell/shell.rb', line 140

def self.colour?
  @default_colour
end

.generate_pdf_tutorial(also_upload_the_tutorial = true) ⇒ Object

#

Bioroebe::Shell.generate_pdf_tutorial

You can use this method to simply generate a new .pdf file, then upload it anyway.

#


11850
11851
11852
11853
11854
11855
11856
11857
11858
11859
11860
11861
11862
11863
11864
11865
11866
11867
11868
11869
# File 'lib/bioroebe/shell/shell.rb', line 11850

def self.generate_pdf_tutorial(
    also_upload_the_tutorial = true
  )
  url = ::Bioroebe.try_to_pass_through_beautiful_url('bioroebe_tutorial?pdf')
  url = url.first if url.is_a? Array
  url.gsub!(/^\/home\/x\/data\//, LOCALHOST) if url.include? HOME_DIRECTORY_OF_USER_X+'data/'
  OpenURI.send(:open, url)
  # ======================================================================= #
  # === Designate where the tutorial can be found locally
  # ======================================================================= #
  path = FILE_BIOROEBE_TUTORIAL
  if also_upload_the_tutorial
    if File.exist? path
      ::Bioroebe.upload_this_pdf_file(path)
    else
      e "Can not upload from #{sfile(path.to_s)} as this "\
        "path does not exist."
    end
  end
end
#

Bioroebe::Shell.menu

To test this, try:

Bioroebe::Shell.menu('ll')
#


11840
11841
11842
# File 'lib/bioroebe/shell/shell.rb', line 11840

def self.menu(i = ARGV)
  new(:no_commandline_arguments).menu(i)
end

.return_entries_in_the_current_directoryObject

#

Bioroebe::Shell.return_entries_in_the_current_directory

#


46
47
48
# File 'lib/bioroebe/shell/readline.rb', line 46

def self.return_entries_in_the_current_directory
  Dir['*']
end

.set_colour(i) ⇒ Object

#

Bioroebe::Shell.set_colour

Set the default colour here.

#


157
158
159
# File 'lib/bioroebe/shell/shell.rb', line 157

def self.set_colour(i)
  @default_colour = i
end

.upload_this_pdf_file(path) ⇒ Object

#

Bioroebe::Shell.upload_this_pdf_file

Use this method to upload the .pdf tutorial or any other .pdf file. This is primarily useful on my home system and may have very little value to other people.

#


1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
# File 'lib/bioroebe/shell/shell.rb', line 1892

def self.upload_this_pdf_file(path)
  # ======================================================================= #
  # ^^^ This will have generated the .pdf.
  # ======================================================================= #
  # Hardcoded for now where the .pdf will reside.
  # ======================================================================= #
  if Object.const_defined? :FtpParadise
    ftp = FtpParadise.new(:shevy, :dont_run_yet)
    ftp.
    ftp.upload_this_binary_file(path)
    e 'Finished uploading!'
  end
end

Instance Method Details

#aa_to_dna(i) ⇒ Object

#

aa_to_dna

#


10774
10775
10776
10777
10778
10779
10780
10781
10782
10783
# File 'lib/bioroebe/shell/shell.rb', line 10774

def aa_to_dna(i)
  if i.is_a? Array
    i = i.join.strip
  end
  i = ::Bioroebe.aa_to_dna(i)
  if i.is_a? Array
    i = i.join.strip
  end
  e i
end

#add_his_tag(i = 'add 6 random his tags') ⇒ Object

#

add_his_tag

This method can be used to add a his tag. By default we will add 6 Histidin tags in succession. This pattern is commonly found in expression vectors.

These histidin tags will be randomly placed within the DNA sequence, by default. Note that CAT and CAC code for Histidin. In most vectors, there is an alternation between these codons.

#


8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
# File 'lib/bioroebe/shell/shell.rb', line 8987

def add_his_tag(
    i = 'add 6 random his tags'
  )
  n_his_tags_to_add = i.scan(/\d+/).first
  position = rand(main_sequence?.size)+1
  e 'Next adding '+sfancy(n_his_tags_to_add)+rev+
    ' Histidin tags to our main sequence at nucleotide '\
    'position '+sfancy(position.to_s)+rev+'.'
  _ = main_sequence?
  _.insert_at_this_position(
    position+1, 'CAC|CAT|CAC|CAT|CAC|CAT' # Insert the His tag here.
  )
  assign_this_dna_sequence(_.to_str)
end

#add_n_nucleotidesObject

#

add_to_start

Use this method to add to the start of a nucleotide sequence. In other words, to prepend to the main nucleotide sequence.

#

add_n_nucleotides



6922
6923
6924
# File 'lib/bioroebe/shell/shell.rb', line 6922

def add_to_start(i)
  add_to_start_or_end(i, :to_start)
end

#add_poly_a_sequenceObject

#

add_poly_a_sequence

Use this method to tag a PolyA sequence to the 3’ end of a mRNA.

First, the mRNA will be cleaved by the enzyme CPSF, usually at the sequence AAUAAA (most common one, but variants exist). AAUAAA is found in 90% of all sequenced polyadenylation elements.

#


5660
5661
5662
5663
# File 'lib/bioroebe/shell/shell.rb', line 5660

def add_poly_a_sequence
  this_sequence = 'A' * 250
  @internal_hash[:rna].append(this_sequence)
end

#add_the_current_user_input_to_the_historyObject

#

add_the_current_user_input_to_the_history

#


4901
4902
4903
4904
4905
4906
4907
4908
# File 'lib/bioroebe/shell/shell.rb', line 4901

def add_the_current_user_input_to_the_history
  # ======================================================================= #
  # And add the user-input to the array that keeps track of it. This
  # has to be done through a specific method, which can do additional
  # checks before adding the user-input onto the history.
  # ======================================================================= #
  add_to_history(user_input?)
end

#add_timer_snapshotObject

#

add_timer_snapshot

#


8915
8916
8917
# File 'lib/bioroebe/shell/shell.rb', line 8915

def add_timer_snapshot
  array_timer_snapshots? << Time.now
end

#add_to_end(i) ⇒ Object Also known as: add

#

add_to_end

This method will invoke append() if something has to be appended.

#


6027
6028
6029
# File 'lib/bioroebe/shell/shell.rb', line 6027

def add_to_end(i)
  add_to_start_or_end(i, :end)
end

#add_to_history(i = user_input? ) ⇒ Object Also known as: append_this_onto_the_history

#

add_to_history

This method should be used consistently whenever content is added onto the history of the bioshell. Content in this context refers primarily to user-submitted input.

#


7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
# File 'lib/bioroebe/shell/shell.rb', line 7322

def add_to_history(
    i = user_input?
  )
  if i.is_a? Array
    i.each {|entry| add_to_history(entry) }
  else
    i = i.to_s.chomp
    unless i.empty?
      if array_history? and array_history?.respond_to?(:last)
        last_history_element = array_history?.last # <- On startup there is no history, hence this check as safeguard.
        if last_history_element
          unless (last_history_element.strip == i.strip) # Only add if it is new input.
            array_history? << i
            if log_user_input?
              what = "#{i}#{N}"
              into = "#{bioshell_log_dir?}input_history.yml"
              append_what_into(what, into)
            end
          end
        else # This clause is valid for new entries.
          array_history? << i
        end
      end
    end
  end
end

#add_to_start(i) ⇒ Object Also known as: left_add

#

add_to_start

#


6920
6921
6922
# File 'lib/bioroebe/shell/shell.rb', line 6920

def add_to_start(i)
  add_to_start_or_end(i, :to_start)
end

#add_to_start_or_end(i = '', append_or_prepend = :append) ⇒ Object

#

add_to_start_or_end

This method can either add to the start or to the end.

The default is to append to the nucleotide sequence.

We can input a number - in this case, we simply add these many nucleotides onto the main string.

#


10311
10312
10313
10314
10315
10316
10317
10318
10319
10320
10321
10322
10323
10324
10325
10326
10327
10328
10329
10330
10331
10332
10333
10334
10335
10336
10337
10338
10339
10340
10341
10342
10343
10344
10345
10346
10347
10348
10349
10350
10351
10352
10353
10354
10355
10356
10357
10358
10359
10360
10361
10362
10363
10364
10365
10366
10367
10368
10369
10370
10371
10372
10373
10374
10375
10376
10377
10378
10379
10380
10381
10382
10383
10384
10385
# File 'lib/bioroebe/shell/shell.rb', line 10311

def add_to_start_or_end(
    i                 = '',
    append_or_prepend = :append
  )
  if the_main_sequence_is_frozen?
    report_that_the_main_sequence_is_frozen
    return
  end
  i = i.join('') if i.is_a? Array
  i = i.dup
  old_length = i.size
  case i.to_s # Easier start/stop entries.
  # ======================================================================= #
  # === Add a start codon.
  # ======================================================================= #
  when 'start',
       'START',
       /ORF/i,
       ':start'
    i = ::Bioroebe.start_codon? # Used to be hardcoded -> 'ATG'
  # ======================================================================= #
  # === Add a stop codon.
  # ======================================================================= #
  when /^stop$/i,
       ':stop'
    i = ::Bioroebe.stop_codons?.sample
  end
  i = i.dup if i.frozen?
  i.upcase!
  case append_or_prepend
  # ======================================================================= #
  # === :prepend
  # ======================================================================= #
  when :prepend,
       :to_start,
       :start
    if i =~ /^\d+$/ # If input is only numbers.
      erev 'Only numbers were given: Prepending '+
            sfancy(i.to_s)+rev+
           ' random nucleotides to the main string now.'
      i.to_i.times { prepend(add_nucleotide) }
    else
      erev "Prepending #{sfancy(i)}#{rev} to the main string."
      prepend(i)
    end
  # ======================================================================= #
  # === :append
  # ======================================================================= #
  when :append,
       :to_end,
       :end
    if i =~ /^\d+$/ # If input is only numbers.
      erev "Only numbers were given: Adding #{sfancy(i.to_s)}#{rev}"\
           " random nucleotides to the main string now."
      i.to_i.times { append(return_random_nucleotide) }
    else
      if only_nucleotides?(i)
        msg = "Adding #{sfancy(i)}#{rev}"
        msg = msg.dup if msg.frozen?
        if ::Bioroebe.is_a_stop_codon? i
          msg << ' (a stop codon)'
        end
        msg << ' to the main string.'
        erev msg
      end
      append(i)
    end
  end
  new_length = string?.size.to_s
  unless new_length.to_i == old_length.to_i
    erev "The new length of the main string is now: "\
         "#{simp(new_length)}#{rev}."
  end
  show_dna_sequence
end

#add_vertical_barrier_to_sequence(i = dna_sequence? ) ⇒ Object

#

add_vertical_barrier_to_sequence

This will turn a sequence such as “ATGCCC” into “ATG|CCC”.

Invocation example:

barrier ATGCCC
#


10957
10958
10959
10960
10961
10962
10963
10964
10965
# File 'lib/bioroebe/shell/shell.rb', line 10957

def add_vertical_barrier_to_sequence(
    i = dna_sequence?
  )
  i = i.join if i.is_a? Array
  i = dna_sequence? if i.nil?
  splitted = i.scan(/.../)
  joined = splitted.join('|')
  e joined
end

#adenin?Boolean

#

adenin?

This will return e. g. “C5H5N5”.

#

Returns:

  • (Boolean)


8318
8319
8320
# File 'lib/bioroebe/shell/shell.rb', line 8318

def adenin?
  YAML.load_file(FILE_NUCLEOTIDES)['Adenin']
end

#align_ORFS(i = dna_string? ) ⇒ Object

#

align_ORFS

This method is used to align all intrinsic ORFs of agiven sequence.

We delegate into class AlignOpenReadingFrames for the output.

#


2136
2137
2138
2139
2140
2141
# File 'lib/bioroebe/shell/shell.rb', line 2136

def align_ORFS(
    i = dna_string?
  )
  i = dna_string? if i.nil?
  ::Bioroebe::AlignOpenReadingFrames.new(i) # bl $BIOROEBE/align_open_reading_frames.rb
end

#all_arguments?Boolean Also known as: a?

#

all_arguments? (a? tag)

#

Returns:

  • (Boolean)


7446
7447
7448
# File 'lib/bioroebe/shell/shell.rb', line 7446

def all_arguments?
  @internal_hash[:all_arguments]
end

#all_upcase?(i) ⇒ Boolean Also known as: is_all_upcase?

#

all_upcase?

Return true if the input is all upcased.

#

Returns:

  • (Boolean)


6751
6752
6753
6754
# File 'lib/bioroebe/shell/shell.rb', line 6751

def all_upcase?(i)
  return true if i.upcase == i
  return false
end

#analyze(i = sequence? ) ⇒ Object

#

analyze (analyze tag)

The input to this method should be the DNA or aminoacid sequence.

#


6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
# File 'lib/bioroebe/shell/shell.rb', line 6693

def analyze(
    i = sequence?
  )
  if i.is_a? Array
    i << sequence? if i.empty?
    i = i.join
  end
  # ======================================================================= #
  # We require a String past this point.
  # ======================================================================= #
  i = i.to_s
  if File.exist? i # Assume that we have a .pdb file here for now.
    parse_this_pdb_file(i)
  else
    if block_given?
      yielded = yield
      case yielded
      when :dna # Handle DNA "input" here.
        analyze_dna_string(i)
      else
        do_analyze_sequence(i)
      end
    else # Default case without block.
      do_analyze_sequence(i)
    end
  end
end

#analyze_dna_string(i = dna_string? ) ⇒ Object

#

analyze_dna_string

This method presently only counts the amount of nucleotides found in the given DNA string at hand.

We use the class Bioroebe::CountAmountOfNucleotides, in bl count_amount_of_nucleotides.rb

#


8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
# File 'lib/bioroebe/shell/shell.rb', line 8138

def analyze_dna_string(
    i = dna_string?
  )
  # ======================================================================= #
  # Set some default values:
  # ======================================================================= #
  i = dna_string? if i.nil?
  if i.is_a? Array and i.empty?
    i = dna_string?
  end
  ::Bioroebe::CountAmountOfNucleotides.new(
    i, :use_cliner
  ) {{ use_colours: use_colours? }} # bl $BIOROEBE/count_amount_of_nucleotides.rb
end

#annotate_this_file(i) ⇒ Object

#

annotate_this_file

#


9293
9294
9295
# File 'lib/bioroebe/shell/shell.rb', line 9293

def annotate_this_file(i)
  ::Bioroebe::CreateAnnotationFormat.new(i)
end

#append(i) ⇒ Object

#

append (append tag)

You can use this to simply append to the main string.

#


3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
# File 'lib/bioroebe/shell/shell.rb', line 3388

def append(i)
  i = i.join.strip if i.is_a? Array
  i = i.to_s
  # ======================================================================= #
  # First check whether the main sequence is frozen:
  # ======================================================================= #
  if is_the_main_sequence_frozen?
    report_that_the_main_sequence_is_frozen
  else
    case i # case tag
    # ===================================================================== #
    # === start
    # ===================================================================== #
    when 'start'
      i = ::Bioroebe.start_codon?
      erev 'We will append the START codon '+sfancy(i)+rev+' next.'
    # ===================================================================== #
    # === stop
    #
    # Add a random stop-codon in this case.
    # ===================================================================== #
    when 'stop'
      i = ::Bioroebe.stop_codons?.sample
      erev 'We will append the STOP codon '+sfancy(i)+rev+' next.'
    when 'shine'
      i = 'AGGAGGT' # Can only add nucleotides to the main sequence.
      erev 'We will append the '+mediumslateblue('Shine Dalgarno')+
           rev+' (SD) sequence '+sfancy("#{i}-3")+rev+' next.'
    end
    if i =~ /^\d+$/ # If input is only numbers.
        erev "Only numbers were given: Adding #{sfancy(i.to_s)}#{rev}"\
             " random nucleotides to the main string next."
      new_string = ''.dup
      i.to_i.times { new_string << return_random_nucleotide }
      i = new_string
    end
    # ===================================================================== #
    # === Check that we add only DNA or RNA nucleotides past this point
    # ===================================================================== #
    if only_nucleotides?(i)
      erev "Now appending #{simp(i)}#{rev}."
      sequence_object? << i # Next, append to the sequence object here.
      show_DNA_sequence
    else
      # ===================================================================== #
      # The user may also wish to append a restriction site, such
      # as via add EcoRI. We need to enable this here.
      # ===================================================================== #
      _ = ::Bioroebe.return_sequence_that_is_cut_via_restriction_enzyme(i, :no_colours)
      if _
        _.tr!('|','')
        erev "Now appending #{simp(_)}#{rev}."
        sequence_object? << _ # Next, append to the sequence object here.
        show_dna_sequence
      else
        erev 'Can not add the sequence '+simp(i)+rev+' because there '\
             'are non-nucleotides in it.'
      end
    end
  end
end

#array_fasta?Boolean

#

array_fasta?

#

Returns:

  • (Boolean)


9953
9954
9955
# File 'lib/bioroebe/shell/shell.rb', line 9953

def array_fasta?
  @internal_hash[:array_fasta]
end

#array_history?Boolean

#

array_history?

Access the input-history of the bioshell.

#

Returns:

  • (Boolean)


5145
5146
5147
# File 'lib/bioroebe/shell/shell.rb', line 5145

def array_history?
  @internal_hash[:array_history]
end

#array_timer_snapshots?Boolean

#

array_timer_snapshots?

#

Returns:

  • (Boolean)


8922
8923
8924
# File 'lib/bioroebe/shell/shell.rb', line 8922

def array_timer_snapshots?
  @internal_hash[:array_timer_snapshots]
end

#assign_sequence2(i) ⇒ Object

#

assign_sequence2

#


7468
7469
7470
7471
# File 'lib/bioroebe/shell/shell.rb', line 7468

def assign_sequence2(i)
  i = i.join(' ') if i.is_a? Array
  @internal_hash[:sequence2] = Bioroebe::Sequence.new(i)
end

#assume_what_type_this_is(i) ⇒ Object

#

assume_what_type_this_is

Determine what type the given input is.

Note that this currently has limitations in that it does not use a statistical way to determine whether we really have DNA/RNA/Aminoacids here.

Eventually we will write a replacement for it but for now, it has to suffice.

To test this method interactively, do this in the shell:

assume ATCG
assume AUCG
assume NNNLMMLLAAA
#


7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
# File 'lib/bioroebe/shell/shell.rb', line 7232

def assume_what_type_this_is(i)
  if i.is_a? Array
    i = i.join
  end
  if i
    chars = i.chars
    if    chars.all? {|entry| POSSIBLE_DNA_NUCLEOTIDES.include? entry }
      erev 'This must be a DNA sequence.'
    elsif chars.all? {|entry| POSSIBLE_RNA_NUCLEOTIDES.include? entry }
      erev 'This must be a RNA sequence.'
    elsif chars.all? {|entry| POSSIBLE_AMINO_ACIDS.include? entry }
      erev 'This must be an amino acid sequence.'
    else
      erev 'This can not be a valid sequence ('+
            simp('DNA/RNA/Proteins')+rev+').'
    end
  else
    erev 'Missing an input such as '+sfancy('ATCG')+rev+'.'
  end
end

#attempt_to_discover_dna_A_boxesObject

#

attempt_to_discover_dna_A_boxes

#


7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
# File 'lib/bioroebe/shell/shell.rb', line 7081

def attempt_to_discover_dna_A_boxes
  dna_A_box_sequence = 'TTATCCACA'
  erev 'The dnaA box in E. coli has this consensus sequence:'
  e
  efancy "  #{dna_A_box_sequence}#{rev}"
  e
  unless string?.empty?
    results = string?.scan(/#{dna_A_box_sequence}/)
    if results.empty?
      erev 'The given DNA sequence does not contain any dnaA sequence elements.'
    else
      erev 'This sequence can be found '+simp(results.size.to_s)+rev+' times.'
      pp results
    end
  end if dna_sequence?
end

#automatically_rename_this_fasta_file(i) ⇒ Object

#

automatically_rename_this_fasta_file

#


6818
6819
6820
6821
6822
# File 'lib/bioroebe/shell/shell.rb', line 6818

def automatically_rename_this_fasta_file(i)
  [i].flatten.compact.each {|this_fasta_file|
    Bioroebe.automatically_rename_this_fasta_file(this_fasta_file)
  }
end

#backtranseq(i = aminoacid_sequence?, , output_as_dna_or_rna = :dna) ⇒ Object Also known as: translate_aminoacids_into_dna

#

backtranseq

Translate an Aminoacid Sequence back into the most likely DNA sequence that would code for this sequence/protein. Thus, this method translates from Aminoacids to DNA sequence - in other words it does a “reverse-lookup”.

Currently, we hardcode to the homo sapiens frequency codon table, but at a later time, we will probably change to a more flexible layout, to allow a backtranseq for more organisms.

#


4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
# File 'lib/bioroebe/shell/shell.rb', line 4965

def backtranseq(
    i                    = aminoacid_sequence?,
    output_as_dna_or_rna = :dna
  )
  sequence = ConvertAminoacidToDNA[i].to_str.delete('-')
  erev lpad?+
       leading_five_prime+
       sfancy(sequence)+
       rev+
       trailing_three_prime
  erev 'Note that we have also assigned the above to be the new DNA sequence.'
  assign_sequence(sequence, :be_silent)
end

#bioshell_log_dir?Boolean

#

bioshell_log_dir?

This method will return where the bioshell/ log dir is kept.

#

Returns:

  • (Boolean)


9720
9721
9722
# File 'lib/bioroebe/shell/shell.rb', line 9720

def bioshell_log_dir?
  "#{log_dir?}bioshell/"
end

#bisulfite(i) ⇒ Object

#

bisulfite

#


5709
5710
5711
# File 'lib/bioroebe/shell/shell.rb', line 5709

def bisulfite(i)
  return ::Bioroebe.bisulfite_treatment(i)
end

#calculate_atp_cost_for(i = aminoacid_sequence?) ) ⇒ Object

#

calculate_atp_cost_for

This method can be used to calculate the ATP cost in order to synthesize a protein.

#


7259
7260
7261
7262
7263
7264
# File 'lib/bioroebe/shell/shell.rb', line 7259

def calculate_atp_cost_for(i = aminoacid_sequence?)
  i = i.join.strip if i.is_a? Array
  if i.nil?
    i = aminoacid_sequence?
  end
end

#calculate_exponential_growth(a, b) ⇒ Object

#

calculate_exponential_growth

#


6445
6446
6447
# File 'lib/bioroebe/shell/shell.rb', line 6445

def calculate_exponential_growth(a, b)
  erev ::Bioroebe.calculate_exponential_growth(a,b)
end

#calculate_hamming_distance_of(i) ⇒ Object

#

calculate_hamming_distance_of

We will delegate into class HammingDistance here.

The argument to this method should ideally be an Array.

To test this method, do:

hamming AGUUCGAUGG AGUCCGGUCG
hamming AGUUCGAUGGGGGGGTTT AGUCCGGUCGGGG
random 100; setseq2 hamming 1 2
#


5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
# File 'lib/bioroebe/shell/shell.rb', line 5847

def calculate_hamming_distance_of(i)
  if i.is_a? String
    if i.include? ' ' and i =~ /^\d+/ # The String could be "1 3" here, for instance.
      splitted = i.split(' ').map(&:strip)
      case splitted.size
      when 2 # If we have at least 2 entries.
        splitted[-1] = return_sequence_from_this_number(splitted[-1])
        splitted[0]  = return_sequence_from_this_number(splitted[0])
        i = splitted.join(' ')
      end
    end
  end
  ::Bioroebe::HammingDistance[i] # bl $BIOROEBE/hamming*rb
end

#calculate_melting_temperature(i) ⇒ Object

#

calculate_melting_temperature

This method just delegates towards class CalculateMeltungTemperature.

#


6000
6001
6002
6003
6004
6005
6006
6007
# File 'lib/bioroebe/shell/shell.rb', line 6000

def calculate_melting_temperature(i)
  i = string? if i.nil?
  if i == :show_formulas
    CalculateMeltingTemperature.show_formulas # bl $BIOROEBE/calculate_melting_temperature.rb
  else
    @_.calculate_melting_temperature(i)
  end
end

#calculate_time_differenceObject

#

calculate_time_difference

#


8929
8930
8931
# File 'lib/bioroebe/shell/shell.rb', line 8929

def calculate_time_difference
  (@internal_hash[:array_timer_snapshots][-2] - @internal_hash[:array_timer_snapshots][-1]) 
end

#calculcate_at_content(i = dna_sequence? ) ⇒ Object

#

calculcate_at_content

Calculate the AT content of a DNA or RNA sequence.

Usage examples:

set_dna ATGCGCGCGCGAACGATGCATGACTGCTAGTCGACA; calc_at_content
calc_at_content AAAGGG
#


738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
# File 'lib/bioroebe/shell/shell.rb', line 738

def calculcate_at_content(
    i = dna_sequence?
  )
  if i.is_a? Array
    i = i.first
  end
  i = dna_sequence? if i.nil?
  i.upcase!
  total = i.size
  n_A = i.count('A')
  n_T = i.count('T')
  result = ( (n_A + n_T) * 100 ) / total
  erev 'The AT content of this sequence is '+
        simp(result.to_s)+rev+' %.'
end

#calculcate_gc_content(i = dna_sequence_as_string? ) ⇒ Object

#

calculcate_gc_content

Use this method to calculate the GC content of a DNA sequence.

If you need the number, you can use this piece of code:

CalculateGCContent.gc_percentage(i) # Will return the percentage number.
#


943
944
945
946
947
948
949
950
# File 'lib/bioroebe/shell/shell.rb', line 943

def calculcate_gc_content(
    i = dna_sequence_as_string?
  )
  if i.nil? or i.empty? # The second check also checks for empty Arrays.
    i = dna_sequence_as_string? # bl $BIOROEBE/calculate/calculate_gc_content.rb
  end
  CalculateGCContent.new(i)
end

#change_first_nucleotide_to(i = dna_sequence? ) ⇒ Object

#

change_first_nucleotide_to

This will only work if we had already assigned a DNA sequence prior to running it.

#


5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
# File 'lib/bioroebe/shell/shell.rb', line 5599

def change_first_nucleotide_to(
    i = dna_sequence?
  )
  i = i.join(' ').strip if i.is_a? Array
  unless i.empty?
    i = i.upcase
    erev "Now changing the first nucleotide to `#{simp(i)}`."
    sequence?.first_nucleotide = i
    show_string
  end
end

#chdir(i = :default) ⇒ Object Also known as: cd

#

chdir (cd tag)

#


9995
9996
9997
9998
9999
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
# File 'lib/bioroebe/shell/shell.rb', line 9995

def chdir(
    i = :default
  )
  if i and i.start_with?('cd ')
    i[0,3] = ''
  end
  case i
  # ======================================================================= #
  # === :home
  # ======================================================================= #
  when :home,
       ':home'
    i = log_dir?
  # ======================================================================= #
  # === :default
  # ======================================================================= #
  when :default,
       nil
    i = File.expand_path('~').to_s
  end
  if File.directory? i
    ::Bioroebe.change_directory(i)
  else
    e "No directory at #{sdir(File.absolute_path(i))}#{rev} "\
      "appears to exist."
  end
end

#check_for_local_vectorsObject

#

check_for_local_vectors

#


3067
3068
3069
3070
3071
3072
# File 'lib/bioroebe/shell/shell.rb', line 3067

def check_for_local_vectors
  _ = return_available_vectors
  unless _.empty? # Silent assignment comes next.
    set_sequence_2(::Bioroebe::Sequence.sequence_from_file(_.first))
  end
end

#check_for_mismatchesObject

#

check_for_mismatches

#


5206
5207
5208
# File 'lib/bioroebe/shell/shell.rb', line 5206

def check_for_mismatches
  CheckForMismatches.new
end

#chop(i = 1, chop_from_left_or_right_hand_side = :default) ⇒ Object Also known as: remove_n_nucleotides

#

chop (chop tag)

We use this method to get rid of some nucleotides, from the 3’ end of a nucleotide sequence (aka the “right hand side” of it) by default.

The first argument to this method tells us how many nucleotides are to be removed.

The second argument determines whether to chop from the right side (the 3’ side) or from the left side (the 5’ side).

#


10400
10401
10402
10403
10404
10405
10406
10407
10408
10409
10410
10411
10412
10413
10414
10415
10416
10417
10418
10419
10420
10421
10422
10423
10424
10425
10426
10427
10428
10429
10430
10431
10432
10433
10434
10435
10436
10437
10438
10439
10440
10441
10442
10443
10444
10445
10446
10447
10448
10449
10450
10451
10452
10453
10454
10455
10456
10457
10458
10459
10460
10461
10462
10463
10464
10465
10466
10467
10468
10469
10470
10471
10472
10473
# File 'lib/bioroebe/shell/shell.rb', line 10400

def chop(
    i = 1,
    chop_from_left_or_right_hand_side = :default # The default is the 3' end.
  ) # Default will be to chop off one nucleotide.
  if is_the_main_sequence_frozen?
    report_that_the_main_sequence_is_frozen
    return
  end
  i = i.first if i.is_a? Array
  if i == '?'
    e 'chop allows us to remove nucleotides from the main sequence.'
    return
  end
  i = 1 if i.nil? # Assign to the default then.
  i = i.to_i # Need a number past this point.
  if i == 0
    erev 'Please add a number, such as 1, or any other value.'
  else
    case chop_from_left_or_right_hand_side
    # ===================================================================== #
    # === :right
    # ===================================================================== #
    when :right,
         :default
      which_end = "3'"
    # ===================================================================== #
    # === :left
    # ===================================================================== #
    when :left
      which_end = "5'"
    end
    if dna_sequence_object?.size > 0
      erev "We will now remove some characters (#{simp(i.to_s)}#{rev}"\
           ") from the #{which_end} end of our main string."
    end
    if dna_sequence_object?.size == 0
      erev 'Can not remove anything as the sequence is empty.'
    elsif i > dna_sequence_object?.size
      erev 'We can not remove that many characters, thus we will'
      erev 'simply remove all characters now.'
      reset_string 
    else
      # =================================================================== #
      # Finally do the manipulation. We need to honour from which
      # side we will be operating on.
      # =================================================================== #
      case chop_from_left_or_right_hand_side
      # =================================================================== #
      # === :default
      # =================================================================== #
      when :default,
           :right
        # ================================================================= #
        # We also store the chopped-away sequence, but we have to be
        # mindful here since the sequence-object counts the nucleotides
        # differently than ruby counts Arrays.
        # ================================================================= #
        @internal_hash[:array_these_sequences_were_chopped_away] << seq_object?[(-i)+1, i-1].dup
        seq_object?[-i, i] = ''
      # =================================================================== #
      # === :left
      # =================================================================== #
      when :left
        @internal_hash[:array_these_sequences_were_chopped_away] << seq_object?[0, i].dup
        seq_object?[0, i+1] = ''
      end
    end
    unless dna_sequence_object?.size == 0
      erev "#{rev}The new length of the main string is now: "\
           "#{simp(dna_sequence_object?.size.to_s)}#{rev}."
    end
    show_dna_sequence
  end
end

#chop_to(i) ⇒ Object

#

chop_to

This method will chop up to the first occurence of the given input sequence.

If the given input sequence can not be found, no change is made.

#


4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
# File 'lib/bioroebe/shell/shell.rb', line 4772

def chop_to(i)
  if i.is_a? Array
    i = i.first
  end
  i = i.to_s if i.is_a? Symbol # For instance: chop_to :ATG
  i.delete!(':') if i.include? ':'
  case i
  when 'start'
    i = 'ATG'
  end
  _ = nucleotide_sequence?
  if i.include? 'U'
    # ===================================================================== #
    # Convert Uracil to Thymine next.
    # ===================================================================== #
    erev "The given input sequence includes at the least one "\
         "#{sfancy('U')}#{rev}, which we will convert to #{sfancy('T')}#{rev}."
    i.tr!('U','T')
  end
  if _.include? i
    # ===================================================================== #
    # Ok, we found the search sequence, so now we can chop off the
    # unnecessary sequences.
    # ===================================================================== #
    position = _.index(i)
    erev "Chopping away #{sfancy(position.to_s)}#{rev} nucleotides from "\
         "the left-hand side (5' end) next."
    @internal_hash[:array_these_sequences_were_chopped_away] << seq_object?[0, position+1]
    seq_object?[0, position+1] = ''
    show_dna_sequence
  else
    erev 'No modification can be made as our target nucleotide sequence'
    erev "does not include the given search string #{sfancy(i)}."
  end
end

#chunked_display(i = dna_sequence? ) ⇒ Object

#

chunked_display

This method will show a “chunked” display of the nucleotides that is similar to the FASTA display at NCBI.

Invoke via:

cdisplay
#


6805
6806
6807
6808
6809
6810
6811
6812
# File 'lib/bioroebe/shell/shell.rb', line 6805

def chunked_display(
    i = dna_sequence?
  )
  i = i.join if i.is_a? Array
  i = dna_sequence? if i.nil?
  i = dna_sequence? if i.empty?
  ::Bioroebe::GenbankFlatFileFormatGenerator.new(i) # bl $BIOROEBE/genbank/genbank_flat_file_format_generator.rb
end

#clear(i) ⇒ Object

#

clear

Functionality that is associated with clearing something, can be stored here.

Usage example:

clear highlighting
#


8829
8830
8831
8832
8833
8834
8835
8836
8837
8838
# File 'lib/bioroebe/shell/shell.rb', line 8829

def clear(i)
  if i.is_a? Array
    i = i.join(' ').strip
  end
  case i
  when /^highlight/
    e 'Clearing all highlighting next.'
    set_highlight_colour nil
  end
end

#coding_area?Boolean

#

coding_area?

Query method over the “coding area” that we will focus on. So for example, if we have 100 nucleotides, but the coding area says 3-34, then we will only care for the nucleotides starting at position 3 and ending at position 34.

#

Returns:

  • (Boolean)


8972
8973
8974
# File 'lib/bioroebe/shell/shell.rb', line 8972

def coding_area?
  @internal_hash[:coding_area]
end

#codon(i = sequence? ) ⇒ Object Also known as: codons, codon?, codons?

#

codon

This method will identify codons.

Usage example from within the Shell:

codon AAAGUCCAU
#


3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
# File 'lib/bioroebe/shell/shell.rb', line 3253

def codon(
    i = sequence?
  )
  if i.is_a? Array # We don't want Arrays here.
    i = i.join.strip
  end
  if i.nil?
    i = sequence?
  else
    if i.is_a? String
      i = sequence? if i.empty?
    end
  end
  _ = nucleotides_to_aminoacid(i)
  erev _
end

#codon_to_aminoacid(i) ⇒ Object

#

codon_to_aminoacid

Translate a codon into an aminoacid through this method.

#


8418
8419
8420
# File 'lib/bioroebe/shell/shell.rb', line 8418

def codon_to_aminoacid(i)
  Bioroebe.codon_to_aminoacid(i)
end

#colour_for_nucleotide(i = '') ⇒ Object Also known as: colour_for_nucleotides

#

colour_for_nucleotide

#


2091
2092
2093
# File 'lib/bioroebe/shell/shell.rb', line 2091

def colour_for_nucleotide(i = '')
  royalblue(i)
end

#colour_for_stop_codon(i) ⇒ Object

#

colour_for_stop_codon

#


2084
2085
2086
# File 'lib/bioroebe/shell/shell.rb', line 2084

def colour_for_stop_codon(i)
  orange(i)
end

#colour_scheme_demo(use_this_sequence = 'ATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCATGC') ⇒ Object

#

colour_scheme_demo

#


6567
6568
6569
6570
6571
6572
6573
6574
# File 'lib/bioroebe/shell/shell.rb', line 6567

def colour_scheme_demo(
    use_this_sequence = 'ATGCATGCATGCATGCATGCATGCATGCATGCATGCATGCATGC'
  )
  ColourSchemeDemo.new(use_this_sequence)
  file = ::Bioroebe::ColourSchemeDemo.create_demo_file.to_s
  erev file
  open_in_browser(file) if File.exist? file
end

#colour_scheme_for_aminoacids(i = aminoacid_sequence? ) ⇒ Object

#

colour_scheme_for_aminoacids

Invocation example:

caa TTTHGHGHGIHIHRGGGGAATTTTHGHGHGIHIHRGGGGAATTHGHGHGIHIHRGGGGAAATTT
#


9541
9542
9543
9544
9545
9546
9547
9548
9549
9550
9551
9552
9553
9554
9555
9556
9557
9558
9559
9560
9561
9562
9563
9564
9565
9566
9567
9568
9569
9570
9571
# File 'lib/bioroebe/shell/shell.rb', line 9541

def colour_scheme_for_aminoacids(
    i = aminoacid_sequence?
  )
  i = aminoacid_sequence? if i.nil?
  hash = ::Bioroebe::ColourScheme::Taylor.colours?
  tokens = i
  if tokens.is_a? String
    tokens = tokens.chars
    tokens = tokens.each_slice(80).to_a
  end
  # ======================================================================= #
  # Get it in chunks of 30.
  # ======================================================================= #
  n_chunks = 30
  chunks = tokens.each_slice(n_chunks).to_a
  e; chunks.each {|array|
    array.each {|entry|
      chars = entry.chars
      chars.each {|aminoacid|
        if hash.has_key? aminoacid
          value = hash[aminoacid]
          array = HexToRGB[value] # Obtain the R,G,B Array from here.
          ::Colours.rgb_print(array, aminoacid)
        else
          erev "The hash does not include the key #{simp(aminoacid)}#{rev}."
        end
      }
    }
    e
  }; e
end

#colour_scheme_for_nucleotides(i = dna_sequence? ) ⇒ Object

#

colour_scheme_for_nucleotides

This method can eventually be used to display the colour codes for the nucleotides.

#


6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
# File 'lib/bioroebe/shell/shell.rb', line 6882

def colour_scheme_for_nucleotides(
    i = dna_sequence?
  )
  begin
    require 'roebe/classes/hex_to_rgb.rb'
  rescue LoadError; end
  if Object.const_defined?(:Roebe) and
     Roebe.const_defined?(:HexToRGB)
    i = dna_sequence? if i.nil?
    i = i.first if i.is_a? Array
    hash = ::Bioroebe::ColourScheme::Nucleotide.colours?
    tokens = i.chars
    # ===================================================================== #
    # Get it in chunks of 80.
    # ===================================================================== #
    chunks = tokens.each_slice(80).to_a
    e; chunks.each {|array|
      array.each {|char|
        if hash.has_key? char
          value = hash[char]
          array = Roebe::HexToRGB[value] # Obtain the R,G,B Array from here.
          ::Colours.rgb_print(array, char)
        end
      }
      e
    }; e
  else
    erev 'Please install the gem hex_to_rgb, in order '\
         'to use this method.'
  end
end

#colourize_fasta_file(i) ⇒ Object

#

colourize_fasta_file

Invocation example:

colourize_fasta_file /Depot/Temp/bioroebe/sequence.fasta
#


3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
# File 'lib/bioroebe/shell/shell.rb', line 3677

def colourize_fasta_file(i)
  if i.is_a? Array
    i.each {|entry| colourize_fasta_file(entry) }
  else
    # ===================================================================== #
    # First, get the raw content of the fasta sequence here.
    # ===================================================================== #
    if File.exist? i
      sequence = ::Bioroebe.parse_fasta_file(i).sequence?
      # =================================================================== #
      # Now that we have the sequence, colourize it.
      # =================================================================== #
      cliner {
        ColourSchemeDemo.new(sequence)
      }
    end
  end
end

#colourize_nucleotide(i, add_leading_five_and_trailing_three_primes = true) ⇒ Object Also known as: colourize_nucleotide_sequence

#

colourize_nucleotide

Assemble 5’-sequence-3’, with colours.

#


10998
10999
11000
11001
11002
11003
11004
11005
11006
11007
11008
11009
11010
11011
11012
11013
11014
11015
11016
11017
11018
11019
# File 'lib/bioroebe/shell/shell.rb', line 10998

def colourize_nucleotide(
    i,
    add_leading_five_and_trailing_three_primes = true
  )
  case add_leading_five_and_trailing_three_primes
  # ======================================================================= #
  # === :do_not_add_anything_else
  # ======================================================================= #
  when :do_not_add_anything_else,
       :make_no_modifications
    add_leading_five_and_trailing_three_primes = false
  end
  if add_leading_five_and_trailing_three_primes
    leading_5_prime+
    sfancy(i)+
    rev+
    trailing_3_prime
  else
    sfancy(i)+
    rev
  end
end

#colourize_this_aminoacid(i) ⇒ Object

#

colourize_this_aminoacid

Use this method to colourize any particular aminoacid.

This should make it easier to detect special aminoacids.

#


10935
10936
10937
10938
10939
10940
10941
10942
10943
10944
10945
# File 'lib/bioroebe/shell/shell.rb', line 10935

def colourize_this_aminoacid(i)
  if i.nil?
    erev 'Please supply an argument, an aminoacid. Either one letter, '\
         'such as A for Alanine, or the full name.'
    return
  end
  unless ::Bioroebe.array_colourize_this_aminoacid.include? i
    erev 'We will now colourize the aminoacid `'+swarn(i)+'`.'
    ::Bioroebe.array_colourize_this_aminoacid << i
  end
end

#command_to_be_passed_to_the_menu?Boolean

#

command_to_be_passed_to_the_menu?

#

Returns:

  • (Boolean)


7461
7462
7463
# File 'lib/bioroebe/shell/shell.rb', line 7461

def command_to_be_passed_to_the_menu?
  @internal_hash[:command_to_be_passed_to_the_menu]
end

#compact_file(this_file = nil) ⇒ Object

#

compact_file

Delegate into class Bioroebe::Compacter.

#


7541
7542
7543
7544
7545
# File 'lib/bioroebe/shell/shell.rb', line 7541

def compact_file(
    this_file = nil
  )
  ::Bioroebe::Compacter.new(this_file)
end

#compare_two_files(file_a, file_b) ⇒ Object

#

compare_two_files

We will here compare whether two files are identical.

First argument is the first file, second argument is the second file.

#


8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
# File 'lib/bioroebe/shell/shell.rb', line 8518

def compare_two_files(file_a, file_b)
  if File.exist? file_a
    file_a = File.read(file_a)
  else
    erev file_a+' does not exist.'
  end
  if File.exist? file_b
    file_b = File.read(file_b)
  else
    erev file_b+' does not exist.'
  end
  erev (file_a == file_b)
end

#compare_two_strings_as_alignment(string1 = nil, string2 = nil) ⇒ Object

#

compare_two_strings_as_alignment

This allows us to interactively compare two strings.

#


8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
# File 'lib/bioroebe/shell/shell.rb', line 8785

def compare_two_strings_as_alignment(
    string1 = nil,
    string2 = nil
  )
  if string1 and string2
    # Simply pass through in this case.
  else
    erev 'You desire to compare two strings.'
    e
    erev 'Please input the '+palegreen('first')+rev+' string/sequence now:'
    print '  '
    if has_readline?
      string1 = Readline.readline
    else
      string1 = $stdin.gets.chomp
    end
    erev 'Please input the '+palegreen('second')+rev+' string now:'
    print '  '
    if has_readline?
      string2 = Readline.readline
    else
      string2 = $stdin.gets.chomp
    end
  end
  # ======================================================================= #
  # Delegate into class SimpleStringComparer next.
  # ======================================================================= #
  _ = ::Bioroebe::SimpleStringComparer.new(:dont_run_yet) { :use_vertical_bar } # bl $BIOROEBE/string_matching/simple_string_comparer.rb
  _.string1 = string1
  _.string2 = string2
  _.compare
end

#compseq(i = dna_sequence? ) ⇒ Object

#

compseq

Analyze a given sequence via compseq.

#


5719
5720
5721
5722
5723
5724
# File 'lib/bioroebe/shell/shell.rb', line 5719

def compseq(
    i = dna_sequence?
  )
  i = dna_sequence? if i.nil?
  ::Bioroebe::Compseq.new(i) # bl $BIOROEBE/compseq.rb
end

#config?Boolean Also known as: configuration?

#

config?

#

Returns:

  • (Boolean)


9687
9688
9689
# File 'lib/bioroebe/shell/shell.rb', line 9687

def config?
  @configuration
end

#consider_analysing_the_local_dataset_on_startupObject

#

consider_analysing_the_local_dataset_on_startup

This method will analyse the local dataset (should it exist), and then display some information to the user about it.

#


5217
5218
5219
5220
5221
5222
5223
# File 'lib/bioroebe/shell/shell.rb', line 5217

def consider_analysing_the_local_dataset_on_startup
  if @internal_hash and
     @internal_hash.has_key?(:analyse_the_local_dataset_on_startup) and
     @internal_hash[:analyse_the_local_dataset_on_startup]
    Bioroebe::AnalyseLocalDataset.new
  end
end

#consider_assigning_the_default_dna_sequence_from_a_yaml_fileObject

#

consider_assigning_the_default_dna_sequence_from_a_yaml_file

#


1239
1240
1241
1242
1243
# File 'lib/bioroebe/shell/shell.rb', line 1239

def consider_assigning_the_default_dna_sequence_from_a_yaml_file
  if defined? DEFAULT_DNA_INPUT_YAML_FILE # Main DNA string.
    set_string(DEFAULT_DNA_INPUT_YAML_FILE)
  end
end

#considering_changing_the_title_of_the_kde_konsole_tab(to_this_title = 'BioRoebe') ⇒ Object

#

considering_changing_the_title_of_the_kde_konsole_tab

#


8101
8102
8103
8104
8105
8106
8107
8108
8109
# File 'lib/bioroebe/shell/shell.rb', line 8101

def considering_changing_the_title_of_the_kde_konsole_tab(
    to_this_title = 'BioRoebe'
  )
  if ::Bioroebe.try_to_rename_kde_konsole? and
     Object.const_defined? :Roebe # For project roebe.
    require 'roebe/classes/kde/kde_konsole/kde_konsole.rb'
    Roebe.change_konsole_tab_title(to_this_title, :be_silent)
  end
end

#convert_five_prime_dna_into_five_prime_mrna(this_string = sequence? ) ⇒ Object

#

convert_five_prime_dna_into_five_prime_mrna (DNA to mRNA)

This method will translate the 5’-DNA into 5’-mRNA.

#


6142
6143
6144
6145
6146
6147
6148
# File 'lib/bioroebe/shell/shell.rb', line 6142

def convert_five_prime_dna_into_five_prime_mrna(
    this_string = sequence?
  )
  erev padding?+leading_5_prime+
       sfancy(this_string.upcase.tr('T','U'))+
       rev+trailing_3_prime
end

#copy_bioroebe_shell_before_quittingObject

#

copy_bioroebe_shell_before_quitting

Use this method to copy the Bioroebe shell before quitting.

We will make use of class InstallRubyProject for this.

This was disabled as of Jan 2016. The reason is that it confuses me too much, seriously. Perhaps I will re-enable it again at a later time.

#


8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
# File 'lib/bioroebe/shell/shell.rb', line 8209

def copy_bioroebe_shell_before_quitting
  _ = RUBY_SRC+'bioroebe/'
  begin
    require 'roebe/classes/install_ruby_project.rb'
  rescue LoadError; end
  if Object.const_defined? :Roebe
    irp = Roebe::InstallRubyProject.new(_, false)
    irp.run
  elsif on_roebe?
    erev 'The project custom_methods/install_ruby_project is not available.'
    erev 'We will install it now.'
    cd '$RSRC/roebe/'
    Easycompile.rinstall2 if Object.const_defined? :Easycompile
  end if false # Disabled it here. Not sure if I will re-enable it.
end

#could_this_be_an_amino_acid?(i) ⇒ Boolean

#

could_this_be_an_amino_acid?

If the input is an amino acid, we return true for this method here.

Characters such as ‘?’ will be removed.

Invocation examples:

phenylalanine
glycin
glycine
#

Returns:

  • (Boolean)


6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
# File 'lib/bioroebe/shell/shell.rb', line 6770

def could_this_be_an_amino_acid?(i)
  i = i.to_s.downcase
  i.delete!('?') if i.include? '?' # Get rid of '?' tokens.
  return_value = false
  unless i.empty?
    # ===================================================================== #
    # First, we check here for german names. These names are kept in
    # the file called
    # 'amino_acids_long_name_to_one_letter.yml'
    # ===================================================================== #
    unless AMINO_ACIDS_RESTE.has_key?(i)
      if AMINO_ACIDS_LONG_NAME_TO_ONE_LETTER.has_key?(i)
        i = AMINO_ACIDS_LONG_NAME_TO_ONE_LETTER[i]
        i = AMINO_ACIDS_ENGLISH[i].downcase
      end
    end
    if AMINO_ACIDS_RESTE.has_key?(i)
      return_value = true
    end
  end
  return return_value
end

#count_amount_of_aminoacids(i) ⇒ Object

#

count_amount_of_aminoacids

#


2979
2980
2981
# File 'lib/bioroebe/shell/shell.rb', line 2979

def count_amount_of_aminoacids(i)
  ::Bioroebe::CountAmountOfAminoacids.new(i)
end

#create_balanced_composition(i = nil) ⇒ Object

#

create_balanced_composition

This method will create a balanced nucleotide-composition.

In other words, we can do a DNA string with 25% A, G, C, T each.

#


4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
# File 'lib/bioroebe/shell/shell.rb', line 4221

def create_balanced_composition(i = nil)
  string = ''.dup # The return string.
  if i.nil?
    n_nucleotides_to_be_generated = 1000 # Default.
    # In this case, go interactive.
    erev 'Please enter the percentage of each nucleotide next.'
    ee 'A: '
    a = $stdin.gets.chomp.to_i
    ee 'T: '
    t = $stdin.gets.chomp.to_i
    ee 'C: '
    c = $stdin.gets.chomp.to_i
    erev 'G is automatically calculated.'
    g = 100 - (a + t + c)
    ee 'G: '
    # The following is not yet finished.
    string << ('A' * a)+('T' * t)+('C' * c)+('G' * g)
  else
    i = 1000 if i.nil? or (i.is_a?(Array) and i.empty?) # The default.
    n_nucleotides_to_be_generated = i
    # ===================================================================== #
    # Otherwise, we assume it to be 25% for each nucleotide. The following
    # code will ensure that.
    # ===================================================================== #
    n_times = n_nucleotides_to_be_generated.to_i / 4
    n_times.times {
      _ = return_dna_nucleotides # Get all four entries first.
      _.shuffle.each {|nucleotide|
        string << nucleotide
      }
    }
  end
  erev "Note: we will assume the target size will "\
       "be #{n_nucleotides_to_be_generated.to_s} nucleotides."
  return string # The nucleotide-string to be returned.
end

#create_fasta_fileObject

#

create_fasta_file

#


6065
6066
6067
6068
6069
6070
6071
# File 'lib/bioroebe/shell/shell.rb', line 6065

def create_fasta_file
  set_save_file :default_fasta
  e 'Now creating a new fasta file. Will store into `'+sfile(@save_file)+'`.'
  _ = '>gi|12345|pir|TVHGG| some unknown protein'+N
  _ << string?
  save_file(_, @internal_hash[:save_file])
end

#create_file(i = a?) ) ⇒ Object

#

create_file

#


3373
3374
3375
3376
3377
3378
3379
3380
# File 'lib/bioroebe/shell/shell.rb', line 3373

def create_file(i = a?)
  [i].flatten.each {|this_file|
    unless File.exist?(this_file)
      erev 'Creating the file '+sfile(this_file)+rev+' next.'
      FileUtils.touch(this_file)
    end
  }
end

#create_n_random_amino_acids(n = 1000) ⇒ Object

#

create_n_random_amino_acids

#


7581
7582
7583
# File 'lib/bioroebe/shell/shell.rb', line 7581

def create_n_random_amino_acids(n = 1000)
  set_aminoacids :random, n, :be_verbose
end

#cut(i) ⇒ Object

#

cut (cut tag)

This method will cut away some part from the DNA string.

#


3455
3456
3457
3458
3459
# File 'lib/bioroebe/shell/shell.rb', line 3455

def cut(i)
  i = i.to_i
  sequence?[-i,i] = ''
  show_dna_sequence
end

#cut_at(this_sequence = 'GAATTC', be_verbose = true) ⇒ Object

#

cut_at

Use this method to chop off or rather cut at a DNA sequence.

#


10487
10488
10489
10490
10491
10492
10493
10494
10495
10496
10497
10498
10499
10500
10501
10502
10503
10504
# File 'lib/bioroebe/shell/shell.rb', line 10487

def cut_at(
    this_sequence = 'GAATTC',
    be_verbose    = true
  )
  main_sequence = dna_sequence_object?
  this_sequence = this_sequence.join.strip if this_sequence.is_a? Array
  if be_verbose
    erev "We will chop away (at) the sequence #{simp(this_sequence)}#{rev}."
    erev 'Note that the sequences all originated from the larger '\
         'parent sequence.'
  end
  results = main_sequence.split(/#{this_sequence}/)
  results.each {|sequence|
    _ = properly_spaced_dna(sequence)
    _ << (' ('+sequence.size.to_s+' nucleotides)').rjust(110 - sequence.size)
    erev _
  }
end

#cut_sequence_in_slices_of(threshold = '9') ⇒ Object

#

cut_sequence_in_slices_of

This method cuts the sequence into slices of n, where n is the argument to this method.

So if you input 10 as argument, then we will put the nucleotides into chunks of 10 nucleotides per row.

Usage examples:

cut_sequence_in_slices_of 5
cut_sequence_in_slices_of 6
cut_sequence_in_slices_of 7
#


7489
7490
7491
7492
7493
7494
7495
7496
7497
# File 'lib/bioroebe/shell/shell.rb', line 7489

def cut_sequence_in_slices_of(
    threshold = '9'
  )
  _ = dna_sequence_object?
  matches = _.scan(/.{#{threshold}}/)
  matches.each {|entry|
    erev "  #{entry}"
  }
end

#cut_with_enzyme(i) ⇒ Object

#

cut_with_enzyme

#


3506
3507
3508
3509
# File 'lib/bioroebe/shell/shell.rb', line 3506

def cut_with_enzyme(i)
  i = i.join(' ').strip if i.is_a? Array
  pp sequence_object?.cut_with_enzyme(i)
end

#cutseq(i = [1,3]) ⇒ Object

#

cutseq

This can be used to modify the sequence object. It will cut some segment out from the nucleotide.

Usage examples:

random 30; cutseq 5 8
random 30; cutseq 5-8
#


3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
# File 'lib/bioroebe/shell/shell.rb', line 3473

def cutseq(i = [1,3])
  if i.is_a? Array
    if i.size == 1 and i.first.is_a? String and i.first.include?('-')
      i = [i.first.split('-')].flatten
    end
    if i.empty? # In this case we will ask the user for input.
      erev 'No argument was provided. Please input the start nucleotide position next:'
      start_position = $stdin.gets.chomp.to_i
      erev 'Next, input the end nucleotide position:'
      end_position   = $stdin.gets.chomp
    elsif i.size > 1
      start_position = i.first
      end_position   = i.last
    end
  end
  # ======================================================================= #
  # === Handle +3 relational position given
  # ======================================================================= #
  if end_position.is_a? String and end_position.include?('+')
    end_position = start_position + end_position.delete('+').to_i
  end
  n_nucleotides_will_be_deleted = (end_position.to_i - start_position.to_i)+1
  # ======================================================================= #
  # Notify the user what we will do next.
  # ======================================================================= #
  erev 'Next cutting away '+simp(n_nucleotides_will_be_deleted.to_s)+
        rev+' nucleotides.'
  sequence_object?[start_position, end_position] = ''
end

#cytosin?Boolean

#

cytosin?

#

Returns:

  • (Boolean)


8339
8340
8341
# File 'lib/bioroebe/shell/shell.rb', line 8339

def cytosin?
  YAML.load_file(FILE_NUCLEOTIDES)['Cytosin']
end

#dalton(i) ⇒ Object

#

dalton

This method will calculate the weight of several aminoacids, in Dalton. We assume that each aminoacid will have a weight of 110 Dalton.

#


9944
9945
9946
9947
9948
# File 'lib/bioroebe/shell/shell.rb', line 9944

def dalton(i)
  n_dalton = i.to_f * 110
  e sfancy(i.to_s)+rev+' aminoacids have a molecular weight of '+
    simp(n_dalton.to_s)+rev+' Dalton ('+(n_dalton/1000.0).to_s+' kDa).'
end

#deduce_this_aminoacid_sequence(i = 'Lys-Ser-Pro-Ser-Leu-Asn-Ala-Ala-Lys', show_the_rna_sequence = true) ⇒ Object

#

deduce_this_aminoacid_sequence

Thi method will show the possible codons for an aminoacid sequence.

It will display the result in an ASCII table, on the commandline.

Trigger this like so:

sof
sof Lys-Ser-Pro-Ser-Leu-Asn-Ala-Ala-Lys
sof Thr Thr Glu Ala Val Glu Ser Thr Val Ala Thr Leu Glu Asp Ser
sof T-T-G-A-V-G-S-T-V
#


4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
# File 'lib/bioroebe/shell/shell.rb', line 4653

def deduce_this_aminoacid_sequence(
    i                     = 'Lys-Ser-Pro-Ser-Leu-Asn-Ala-Ala-Lys',
    show_the_rna_sequence = true
  )
  if i.nil? # This is the default.
    if aminoacid_sequence?
      i = aminoacid_sequence?
    else
      i = 'Lys-Ser-Pro-Ser-Leu-Asn-Ala-Ala-Lys'
    end
  end
  DeduceAminoacidSequence.new(i, show_rna: show_the_rna_sequence) # bl DeduceAminoacidSequence
end

#default_length?Boolean

#

default_length?

#

Returns:

  • (Boolean)


7311
7312
7313
# File 'lib/bioroebe/shell/shell.rb', line 7311

def default_length?
  @internal_hash[:default_length]
end

#design_polylinker(optional_length_of_polylinker = nil, be_verbose = true) ⇒ Object

#

design_polylinker

This method will design a polylinker from 3-8 random restriction enzymes sites.

You can pass a first argument to this method.

Example:

design_polylinker 100
#


8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
# File 'lib/bioroebe/shell/shell.rb', line 8637

def design_polylinker(
    optional_length_of_polylinker = nil,
    be_verbose                    = true
  )
  if optional_length_of_polylinker.is_a? Array
    optional_length_of_polylinker = optional_length_of_polylinker[0]
  end
  if optional_length_of_polylinker.nil?
    optional_length_of_polylinker = 20
  end
  optional_length_of_polylinker = optional_length_of_polylinker.to_i
  full_sequence = ''
  n_restriction_sites = rand(6)+3
  n_restriction_sites.times {
    full_sequence << return_random_restriction_enzyme(be_verbose)
  }
  if full_sequence.size < optional_length_of_polylinker
    loop {
      full_sequence << return_random_restriction_enzyme(be_verbose)
      break if full_sequence.size > optional_length_of_polylinker
    }
  end
  erev 'Our generated polylinker has '+sfancy(n_restriction_sites.to_s)+
       ' sites for restriction enzymes available (DNA Sequence '+
       'length is: '+full_sequence.size.to_s+').'
  erev 'We will also assign this sequence as the new DNA sequence.'
  assign_dna_sequence(full_sequence, :be_quiet)
  return full_sequence
end

#designate_this_input_as_coding_entry(i) ⇒ Object

#

designate_this_input_as_coding_entry

Invocation example:

coding_entry 51..3251
#


5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
# File 'lib/bioroebe/shell/shell.rb', line 5964

def designate_this_input_as_coding_entry(i)
  if i.is_a? Array
    i = i.first
  end
  if i.include? '..'
    # ===================================================================== #
    # Assume Range-behaviour here.
    # ===================================================================== #
    @internal_hash[:coding_area] = i
  end
  erev "Using the coding-area #{sfancy(i)}#{rev}."
  erev 'You can test this by e. g. invoking '+sfancy('ORF?')+rev+'.'
end

#determine_and_report_all_stop_codonsObject

#

determine_and_report_all_stop_codons

#


1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
# File 'lib/bioroebe/shell/shell.rb', line 1541

def determine_and_report_all_stop_codons
  dna_sequence = dna_sequence_object?
  erev 'Because 3 different stop codons exist, we have '\
       'to do '+slateblue('3 runs')+rev+'.'
  stop_codons?.each {|this_stop_codon|
    array_matches = ::Bioroebe.return_all_substring_matches(
      dna_sequence, this_stop_codon
    )
    if array_matches.empty?
      erev 'No match has been found.'
    else
      start_position = array_matches.last.first
      erev 'For the stop codon '+sfancy(this_stop_codon)+rev+' the last codon'
      erev 'occurrs at position '+simp(start_position.to_s)+rev+'.'
    end
  }
end

#disable(i) ⇒ Object

#

disable (disable tag)

#


9727
9728
9729
9730
9731
9732
9733
9734
9735
9736
9737
9738
9739
9740
9741
9742
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754
9755
9756
9757
9758
9759
9760
9761
9762
9763
9764
9765
9766
9767
9768
9769
9770
# File 'lib/bioroebe/shell/shell.rb', line 9727

def disable(
    i
  )
  if i.is_a? Array
    i = i.join(' ').strip
  end
  case i.to_s # case tag
  # ======================================================================= #
  # === disable colours
  # ======================================================================= #
  when 'colours',
       'colors',
       /^col/
    disable_colours
  # ======================================================================= #
  # === disable :cd_aliases
  # ======================================================================= #
  when /^-?-?cd(-|_)?aliases$/i
    erev 'We will no longer use class Rcfiles::DirectoryAliases'
    ::Bioroebe::Configuration.do_not_use_expand_cd_aliases
  # ======================================================================= #
  # === truncate
  # ======================================================================= #
  when /^truncate$/i
    disable_truncate
  # ======================================================================= #
  # === prompt
  # ======================================================================= #
  when 'prompt'
    set_prompt :empty # This means to use an empty prompt.
  # ======================================================================= #
  # === padding
  # ======================================================================= #
  when 'padding'
    set_padding 0, :be_verbose
  # ======================================================================= #
  # === disable xsel
  # ======================================================================= #
  when 'xsel'
    disable_xsel
  else
    erev "No such disable-action could be found (#{sfancy(i)}#{rev})"
  end
end

#disable_colours_in_an_extended_manner(be_verbose = :be_quiet) ⇒ Object Also known as: disable_enable_colours, extended_disable_colours

#

disable_colours_in_an_extended_manner (disable tag)

#


703
704
705
706
707
708
709
710
# File 'lib/bioroebe/shell/shell.rb', line 703

def disable_colours_in_an_extended_manner(
    be_verbose = :be_quiet
  )
  disable_colours(be_verbose)
  ::Bioroebe.disable_colours
  @highlight_colour = '' # Use this colour to highlight important sequences.
  set_prompt
end

#disable_truncateObject

#

disable_truncate

#


8709
8710
8711
# File 'lib/bioroebe/shell/shell.rb', line 8709

def disable_truncate
  do_not_truncate
end

#disable_xselObject

#

disable_xsel

#


9233
9234
9235
9236
9237
9238
9239
9240
# File 'lib/bioroebe/shell/shell.rb', line 9233

def disable_xsel
  if use_xsel?
    e 'Now disabling xsel.'
    @internal_hash[:use_xsel] = false
  else
    e 'xsel is already disabled.'
  end
end

#discover_all_palindromes(i = dna_sequence?, , min = 4, max = 10) ⇒ Object

#

discover_all_palindromes

We need to discover all palindromes. For this, we need a min and a max value.

#


7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
# File 'lib/bioroebe/shell/shell.rb', line 7635

def discover_all_palindromes(
    i   = dna_sequence?,
    min =  4,
    max = 10
  )
  i = dna_sequence? unless i
  case i # case tag
  when 'default',
       ':default'
    i = dna_sequence?
  end
  @internal_hash[:array_palindromes] = [] # We store the Palindromes in this Array.
  n_times = i.size

  min.upto(max) {|length|
    # ===================================================================== #
    # First, iterate by starting over the min value.
    # ===================================================================== #
    n_times.times {|counter|
      possible_palindrome_sequence = i[counter, length]
      counter += 1 # Adding +1 because nucleotides start at 1, not 0.
      if ::Bioroebe.is_palindrome?(possible_palindrome_sequence) and
         (possible_palindrome_sequence.size >= length)
        @internal_hash[:array_palindromes] << [possible_palindrome_sequence, counter]
      end
    }
  }
  e; erev 'Starting nucleotide | Palindrome sequence'; e
  @internal_hash[:array_palindromes].each {|array|
    index_position = array.last
    nucleotides    = array.first
    erev '                 '+index_position.to_s.rjust(3)+' '+
         nucleotides+' ('+swarn(nucleotides.size.to_s)+rev+')'
  }; e
end

#display_all_aminoacidsObject

#

display_all_aminoacids

This method will display all Aminoacids.

Invocation example:

daminoacids
#


9307
9308
9309
9310
9311
9312
9313
9314
9315
9316
# File 'lib/bioroebe/shell/shell.rb', line 9307

def display_all_aminoacids
  e
  erev 'Aminoacids Shortnames:'
  erev # Newline here is ok.
  aa = ::Bioroebe::AMINO_ACIDS # Is a hash.
  aa.keys.sort.each {|key|
    result = aa[key].select {|inner_key, value| inner_key.size == 3 }.values.first
    erev '  '+key+': '+sfancy(result)
  }; e # Trailing newline.
end

#display_glycolysis_pathwayObject

#

display_glycolysis_pathway

This method will show the glycolysis Pathway.

#


10109
10110
10111
10112
10113
10114
10115
10116
# File 'lib/bioroebe/shell/shell.rb', line 10109

def display_glycolysis_pathway
  array = Pathways.glycolysis_pathway # Obtain the glyclosis pathway, as Array.
  if Object.const_defined? :Display
    Display.display(array, ')')
  else
    array.each {|entry| e ' - '+entry }
  end
end

#display_nucleotide_sequence(this_sequence = dna_sequence_object?, , &block) ⇒ Object Also known as: display_this_nucleotide_sequence, display_this_sequence, show_this_sequence

#

display_nucleotide_sequence

Consistently use this method whenever you wish to display a nucleotide sequence.

#


1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
# File 'lib/bioroebe/shell/shell.rb', line 1836

def display_nucleotide_sequence(
    this_sequence = dna_sequence_object?,
    &block
  )
  case this_sequence
  when :default
    this_sequence = dna_sequence_object?
  end
  do_show_piped_output = false
  if block_given?
    yielded = yield
    case yielded
    when :piped,
         :show_piped
      do_show_piped_output = true
    end
  end
  hash = {
    padding_to_use:    padding?,
    show_piped_output: do_show_piped_output
  }
  show_nucleotide_sequence?.report_this_sequence(this_sequence) { hash }
end

#display_open_reading_frames(i = dna_sequence_object?, , &block) ⇒ Object

#

display_open_reading_frames

Invocation example:

display_open_reading_frames ATGAGCAAGGCCGACTACGAGAAG
#


5946
5947
5948
5949
5950
5951
5952
5953
5954
# File 'lib/bioroebe/shell/shell.rb', line 5946

def display_open_reading_frames(
    i = dna_sequence_object?, &block
  )
  i = i.first if i.is_a? Array
  i = dna_sequence_object? if i.nil?
  i = dna_sequence_object? if i.empty?
  require 'bioroebe/utility_scripts/display_open_reading_frames/display_open_reading_frames.rb'
  ::Bioroebe::DisplayOpenReadingFrames.new(i, &block)
end

#dna_padding(this_sequence, get_rid_of_spaces = false) ⇒ Object Also known as: properly_spaced_dna, properly_padded_dna_string

#

dna_padding (dna_padding tag)

This method will properly pad a DNA string (with leading 5’ and trailing 3’). That string will be returned.

First argument should be the string (sequence) that you wish to modify.

#


9260
9261
9262
9263
9264
9265
9266
9267
9268
# File 'lib/bioroebe/shell/shell.rb', line 9260

def dna_padding(
    this_sequence,
    get_rid_of_spaces = false
  )
  return left_pad?+
         five_prime(get_rid_of_spaces)+rev+
         sfancy(this_sequence)+rev+
         trailer(get_rid_of_spaces)
end

#dna_sequences?Boolean Also known as: array_sequences?

#

dna_sequences?

#

Returns:

  • (Boolean)


8362
8363
8364
# File 'lib/bioroebe/shell/shell.rb', line 8362

def dna_sequences?
  @internal_hash[:array_dna_sequences]
end

#dna_to_aminoacid_sequence(i = dna_sequence? ) ⇒ Object

#

dna_to_aminoacid_sequence

Convert a DNA sequence into the corresponding aminoacid sequence.

#


6014
6015
6016
6017
6018
6019
6020
# File 'lib/bioroebe/shell/shell.rb', line 6014

def dna_to_aminoacid_sequence(
    i = dna_sequence?
  )
  i = dna_sequence? if i.nil?
  i = dna_sequence? if i.empty?
  ::Bioroebe::DnaToAminoacidSequence.new(i)
end

#dna_translate(i) ⇒ Object

#

dna_translate

#


10823
10824
10825
10826
10827
10828
10829
10830
10831
10832
10833
10834
10835
10836
10837
10838
10839
10840
10841
10842
10843
10844
# File 'lib/bioroebe/shell/shell.rb', line 10823

def dna_translate(i)
  i = i.join(' ').strip if i.is_a? Array
  if i.nil? or i.empty?
    if dna_sequence_as_string?
      i = dna_sequence_as_string?
      erev 'Using the current DNA sequence (size: '+
           i.size.to_s+' nucleotides)'
      # =================================================================== #
      # assign_dna_sequence(i, :be_verbose) # First assign
      # ^^^ Why would we want to re-assign here? Makes no sense, thus it
      #     was disabled as of December 2021. 
      # =================================================================== #
    end
  end
  # ======================================================================= #
  # Find and display the complement to this DNA sequence:
  # ======================================================================= #
  erev "The #{orange('complementary DNA Strand')}#{rev} is:"
  e
  show_nucleotide_sequence?.display(i) { :complementary_strand }
  e
end

#dna_with_ends(i = dna_sequence_as_string?, , optional_colourize = nil, colourize_everything = true) ⇒ Object

#

dna_with_ends

Display DNA with proper ends.

The first argument should be the string that we will colourize.

If the second argument is given (‘optional_colourize`), then this method will colourize the sequence at certain positions. This can be useful to display, for instance, restriction-sites.

#


9855
9856
9857
9858
9859
9860
9861
9862
9863
9864
9865
9866
9867
9868
9869
9870
9871
9872
9873
9874
9875
9876
9877
9878
9879
9880
9881
9882
9883
9884
9885
9886
9887
9888
9889
9890
9891
9892
9893
9894
9895
9896
9897
9898
9899
9900
9901
9902
9903
9904
9905
9906
9907
9908
9909
9910
9911
9912
9913
9914
9915
9916
9917
9918
9919
9920
9921
9922
9923
# File 'lib/bioroebe/shell/shell.rb', line 9855

def dna_with_ends(
    i                    = dna_sequence_as_string?,
    optional_colourize   = nil,
    colourize_everything = true
  )
  i.upcase! if config?.respond_to?(:upcase_nucleotides) and config?.upcase_nucleotides
  if optional_colourize.is_a? String
    optional_colourize = [optional_colourize]
  end
  if block_given?
    yielded = yield
    case yielded
    # ===================================================================== #
    # === :honour_coding_area_if_it_exists
    # ===================================================================== #
    when :honour_coding_area_if_it_exists
      if optional_colourize and @internal_hash[:coding_area]
        # ================================================================= #
        # We will colourize based on the coding area that was designated.
        # ================================================================= #
        _ = @internal_hash[:coding_area]
        # ================================================================= #
        # We deduct 1 because ruby Arrays start at 0.
        # ================================================================= #
        start_position = _.split('..').first.to_i - 1
        end_position   = _.split('..').last.to_i  - 1
        internal_segment = i[start_position .. end_position]
        use_this_as_return_string = ''
        use_this_as_return_string << i[0..(start_position-1)]
        optional_colourize.each {|inner_entry|
          internal_segment.gsub!(inner_entry, yellow+inner_entry+rev)
        }
        use_this_as_return_string << internal_segment
        use_this_as_return_string << i[(end_position+1) .. -1]
        i = use_this_as_return_string
      elsif optional_colourize
        # ================================================================= #
        # Apply all entries given in the Array.
        # ================================================================= #
        if optional_colourize.is_a? Array
          optional_colourize.flatten.each {|inner_entry|
            i.gsub!(
              inner_entry, colour_for_stop_codon(inner_entry)+rev
            ) # Colourize in yellow.
          }
        else
          # =================================================================== #
          # Make sure that we have a String past this point.
          # =================================================================== #
          optional_colourize = optional_colourize.to_s
          if colourize_everything == true
            i.gsub!(optional_colourize, colour_for_stop_codon(optional_colourize)+rev)
          else
            if colourize_everything == 1
              i.sub!(optional_colourize, colour_for_stop_codon(optional_colourize)+rev)
            end
          end
        end
      end
    end
  else
    i = "#{sfancy(i)}#{rev}"
  end
  # ======================================================================= #
  # We will report the DNA sequence with leading 5' prime and
  # trailing 3' prime.
  # ======================================================================= #
  return "#{leading_five_prime}#{i}#{trailing_three_prime}"
end

#do_a_silent_startupObject Also known as: do_silent_startup

#

do_a_silent_startup

Use this method when you want to perform a silent startup.

#


8077
8078
8079
# File 'lib/bioroebe/shell/shell.rb', line 8077

def do_a_silent_startup
  @internal_hash[:silent_startup] = true
end

#do_action(*i) ⇒ Object

#

do_action

Usage example:

do not truncate
#


7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
# File 'lib/bioroebe/shell/shell.rb', line 7169

def do_action(*i)
  if i.is_a? Array
    i.flatten!
  end
  first_argument  = i[0]
  second_argument = i[1]
  case second_argument
  when 'truncate'
    do_not_truncate if first_argument == 'not'
  end
end

#do_analyze_sequence(i = sequence? ) ⇒ Object

#

do_analyze_sequence

Use this method to find unique sequences.

#


4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
# File 'lib/bioroebe/shell/shell.rb', line 4984

def do_analyze_sequence(
    i = sequence?
  )
  if i.is_a?(Array) and i.empty?
    i = sequence?
  end
  if i.empty? and (!aminoacid_sequence?)
    erev 'Please first assign a sequence.'
  elsif aminoacid_sequence?
    aminoacid_sequence = aminoacid_sequence?
    show_protein_composition(aminoacid_sequence)
    # ===================================================================== #
    # Also show the molecular mass.
    # ===================================================================== #
    molecular_mass_of_amino_acids_in_this_sequence(aminoacid_sequence)
  else
    erev 'Searching for '+steelblue('NLS sequences')+rev+' first:'
    run_nls_search
  end
end

#do_mutate_dna_sequence_at_this_nucleotide_position(this_nucleotide_position = 1, new_nucleotide = nil, old_sequence = dna_sequence? ) ⇒ Object

#

do_mutate_dna_sequence_at_this_nucleotide_position

You can use this method to mutate a DNA sequence at a given position.

The first argument should be the specific nucleotide position that you wish to modify. Keep in mind that in BioRoebe we will start to count at nucleotide position 1; in ruby Arrays, we would start to count at position 0 but DNA sequences don’t have a nucleotide called 0 by definition, hence why we use a more (bio)logical way that makes more sense.

Usage example:

random 15; mutate 1
#


5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
# File 'lib/bioroebe/shell/shell.rb', line 5022

def do_mutate_dna_sequence_at_this_nucleotide_position(
    this_nucleotide_position = 1,
    new_nucleotide           = nil,
    old_sequence             = dna_sequence?
  )
  if this_nucleotide_position.is_a? Array
    new_nucleotide = this_nucleotide_position[1] if this_nucleotide_position.size > 1
    this_nucleotide_position = this_nucleotide_position.first
  end
  # ======================================================================= #
  # === this_nucleotide_position must be a Fixnum past that point
  # ======================================================================= #
  this_nucleotide_position = this_nucleotide_position.to_i
  if this_nucleotide_position < 1
    this_nucleotide_position = 1 # 1 is minimum.
  end
  old_nucleotide = old_sequence[this_nucleotide_position-1, 1]
  unless new_nucleotide # Enter this clause if new_nucleotide is nil.
    new_nucleotide = (DNA_NUCLEOTIDES - [old_nucleotide]).sample # Obtain a random but different nucleotide.
  end
  erev 'At nucleotide position '+sfancy(this_nucleotide_position.to_s)+
       rev+' we will replace '+simp(old_nucleotide)+rev+' with '+
       simp(new_nucleotide)+rev+'.'
  old_sequence[this_nucleotide_position-1, 1] = new_nucleotide
  set_dna_sequence(old_sequence) # We'll also assign this.
end

#do_not_show_the_leader(be_verbose = true) ⇒ Object

#

do_not_show_the_leader

#


5824
5825
5826
5827
5828
5829
5830
5831
# File 'lib/bioroebe/shell/shell.rb', line 5824

def do_not_show_the_leader(
    be_verbose = true
  )
  if be_verbose
    e "The 3'-trailer of nucleotide sequences will not be shown."
  end
  @internal_hash[:show_the_leader] = false
end

#do_not_show_the_trailer(be_verbose = true) ⇒ Object

#

do_not_show_the_trailer

#


5812
5813
5814
5815
5816
5817
5818
5819
# File 'lib/bioroebe/shell/shell.rb', line 5812

def do_not_show_the_trailer(
    be_verbose = true
  )
  if be_verbose
    e "The 3'-trailer of nucleotide sequences will not be shown."
  end
  @internal_hash[:show_the_trailer] = false
end

#do_not_truncateObject

#

do_not_truncate

#


9351
9352
9353
9354
# File 'lib/bioroebe/shell/shell.rb', line 9351

def do_not_truncate
  ::Bioroebe.do_not_truncate
  erev 'We will no longer truncate too-long output.'
end

#do_not_use_working_directory_as_promptObject

#

do_not_use_working_directory_as_prompt

#


5101
5102
5103
# File 'lib/bioroebe/shell/shell.rb', line 5101

def do_not_use_working_directory_as_prompt
  @internal_hash[:use_working_directory_as_prompt] = false
end

#do_open(i) ⇒ Object

#

do_open

Open an URL - via browser.

#


11026
11027
11028
11029
11030
11031
11032
11033
# File 'lib/bioroebe/shell/shell.rb', line 11026

def do_open(i)
  case i
  when 'all','ALL'
    open_my_files
  else # Default.
    open_in_browser(i)
  end
end

#do_quit(determine_what_to_do = exit_the_shell_how? ) ⇒ Object

#

do_quit (exit tag, quit tag)

Consistently use this method when quitting from the shell. No exception!

On quitting, we may copy the bioroebe-files.

We may either return a symbol, or we may simply call exit.

#


11725
11726
11727
11728
11729
11730
11731
11732
11733
11734
11735
11736
11737
11738
11739
11740
11741
11742
11743
11744
11745
# File 'lib/bioroebe/shell/shell.rb', line 11725

def do_quit(
    # ===================================================================== #
    # The variable that comes next is usually a Symbol.
    # ===================================================================== #
    determine_what_to_do = exit_the_shell_how?
  )
  # ======================================================================= #
  # We can also copy the content of the Bioroebe-Project - but I am
  # not sure if this is worth the trade-off, so it was disabled again.
  # ======================================================================= #
  # copy_bioroebe_shell_before_quitting
  # ======================================================================= #
  considering_changing_the_title_of_the_kde_konsole_tab('')
  case determine_what_to_do
  when :instantly,
       nil
    :break
  else # This is valid for :exit_gracefully.
    return determine_what_to_do # Allo a graceful exit.
  end
end

#do_start_the_sinatra_interfaceObject

#

do_start_the_sinatra_interface

Invocation example:

biosh --sinatra
#


3184
3185
3186
3187
# File 'lib/bioroebe/shell/shell.rb', line 3184

def do_start_the_sinatra_interface
  require 'bioroebe/sinatra/sinatra_wrapper.rb'
  ::Bioroebe.start_sinatra_interface
end

#do_toggle_debug_valueObject

#

do_toggle_debug_value

#


6034
6035
6036
6037
6038
6039
6040
# File 'lib/bioroebe/shell/shell.rb', line 6034

def do_toggle_debug_value
  if @internal_hash[:debug]
    @internal_hash[:debug] = false
  else
    @internal_hash[:debug] = true
  end
end

#do_truncate?Boolean

#

do_truncate?

#

Returns:

  • (Boolean)


9333
9334
9335
# File 'lib/bioroebe/shell/shell.rb', line 9333

def do_truncate?
  ::Bioroebe.do_truncate?
end

#do_use_working_directory_as_promptObject Also known as: use_working_directory_as_prompt

#

use_working_directory_as_prompt

Use this method if you wish to use the working-directory as your prompt.

#


8686
8687
8688
# File 'lib/bioroebe/shell/shell.rb', line 8686

def do_use_working_directory_as_prompt
  @internal_hash[:use_working_directory_as_prompt] = true
end

#does_this_remote_file_exist?(i) ⇒ Boolean

#

does_this_remote_file_exist?

This method determines, based on wget, whether a remote file exists or whether it does not.

#

Returns:

  • (Boolean)


10284
10285
10286
10287
10288
10289
10290
10291
10292
10293
10294
10295
10296
10297
10298
10299
# File 'lib/bioroebe/shell/shell.rb', line 10284

def does_this_remote_file_exist?(i)
  remote_file_exists = false
  # ======================================================================= #
  # Use wget --spider to check if the remote file exists.
  # ======================================================================= #
  _ = "wget --spider -v #{i} 2>&1"
  result = `#{_}`
  if result.include?('Remote file exists') or # Yes, the remote file exists.
     result =~ /File '.+' exists./
    remote_file_exists = true
  end
  if result.include? '/404'
    remote_file_exists = false
  end
  return remote_file_exists
end

#downcase_main_stringObject

#

downcase_main_string (downcase tag, dcase tag)

Use this method to downcase the main sequence.

#


6929
6930
6931
6932
6933
6934
# File 'lib/bioroebe/shell/shell.rb', line 6929

def downcase_main_string
  downcased_sequence = seq?.downcase
  set_sequence(
    downcased_sequence
  )
end

#download(i) ⇒ Object

#

download (download tag)

General download handler. Some sequences will be changed, such as lambda (for the phage called lambda), to the corresponding entry at NCBI.

#


3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
# File 'lib/bioroebe/shell/shell.rb', line 3518

def download(i)
  if i.is_a? Array
    i.each {|entry| download(entry) }
  else
    case i.to_s
    # ===================================================================== #
    # === The lambda phage sequence
    #
    # Download the lambda-sequence, via:
    #
    #   download lambda
    #
    # ===================================================================== #
    when 'lambda',
         /^-?-?lambda(_|-)?genome$/i
      i = ::Bioroebe.map_ncbi_entry_to_eutils_id('NC_001416.1.fasta')+
          '.fasta'
    # ===================================================================== #
    # === Download the cytochrome c sequence (of humans)
    #
    # This should be equivalent to:
    #
    #   https://www.ncbi.nlm.nih.gov/protein/XP_011521207.1?report=fasta
    #
    # ===================================================================== #
    when /cytochrome_c_protein_sequence/
      return Bioroebe::Ncbi.efetch_by_url('NP_061820.1')
    # ===================================================================== #
    # === P1
    # ===================================================================== #
    when 'P1'
      i = ::Bioroebe.map_ncbi_entry_to_eutils_id('NC_005856.1.fasta')+
          '.fasta'
    # ===================================================================== #
    # === P2
    #
    # The P2 phage, from E. coli, a temperate phage.
    # ===================================================================== #
    when 'P2'
      i = ::Bioroebe.map_ncbi_entry_to_eutils_id('NC_041848.1.fasta')+
          '.fasta'
    # ===================================================================== #
    # === T12
    #
    # This is the Streptococcus phage T12.
    # ===================================================================== #
    when 'T12'
      i = ::Bioroebe.map_ncbi_entry_to_eutils_id('NC_028700.1.fasta')+
          '.fasta'
    # ===================================================================== #
    # === T2
    #
    # This is the phage T2.
    # ===================================================================== #
    when 'T2'
      i = ::Bioroebe.map_ncbi_entry_to_eutils_id('AP018813.1.fasta')+
          '.fasta'
    # ===================================================================== #
    # === T4
    #
    # This is the phage T4.
    # ===================================================================== #
    when 'T4'
      i = ::Bioroebe.map_ncbi_entry_to_eutils_id('NC_000866.4.fasta')+
          '.fasta'
    # ===================================================================== #
    # === T6
    #
    # This is the phage T6.
    # ===================================================================== #
    when 'T6'
      i = ::Bioroebe.map_ncbi_entry_to_eutils_id('MH550421.1.fasta')+
          '.fasta'
    # ===================================================================== #
    # === rhinovirus
    # ===================================================================== #
    when /^-?-?rhinovirus/i
      i = ::Bioroebe.map_ncbi_entry_to_eutils_id('NC_038311')+
          '.fasta'
    # ===================================================================== #
    # === Handle .pdb files here
    # ===================================================================== #
    when /\.pdb$/
      cd :download_directory
      wget i
      register_this_download(i)
      parse_this_pdb_file(File.basename(i))
    end
    # ===================================================================== #
    # === Handle Fasta files next
    # ===================================================================== #
    if i.end_with? '.fa' or i.end_with? '.fasta'
      i = i.dup if i.frozen?
      unless File.exist? i
        _ = Bioroebe::Ncbi.efetch_by_url(
             i.delete_suffix('.fasta')
           )
        if File.exist? _
          erev "The file is now available at `#{sfile(_)}`."
        end
      else
        # ================================================================= #
        # The above download_fasta() makes use of NCBI. We need to rewrite
        # this eventually. For now, we will do another, simpler approach
        # here.
        # ================================================================= #
        what = URI.open(i).read
        into = log_dir?+File.basename(i)
        erev "Storing into `#{sfile(into)}#{rev}`."
        write_what_into(what, into)
        return into # This will also return the local path.
      end
    else
      # erev 'Unsure what to do with '+sfancy(i)
      esystem "wget #{i}"
    end
  end
end

#download_fasta(i = nil) ⇒ Object

#

download_fasta

Use this to download a fasta sequence.

#


10234
10235
10236
10237
10238
10239
10240
10241
10242
10243
10244
10245
10246
10247
10248
10249
10250
10251
10252
10253
# File 'lib/bioroebe/shell/shell.rb', line 10234

def download_fasta(i = nil)
  if i.is_a? Array
    i.each {|entry|
      download_fasta(entry)
    }
  else
    # ===================================================================== #
    # Delegate to a special class here.
    # ===================================================================== #
    stored_here = ::Bioroebe.download_fasta(i) # bl $BIOROEBE/download_fasta.rb
    if stored_here
      if File.exist? stored_here
        assign_sequence(stored_here)
      end
      return stored_here
    else
      e crimson('No result could be found for ')+sfancy(i)+rev
    end
  end
end

#download_this_pdb_file(i = '3O30') ⇒ Object

#

download_this_pdb_file

Use this method to download a .pdb file.

There seem to be at least two major methods how to use the PDB database:

(1) http://www.rcsb.org/pdb/files/3O30.pdb
(2) http://www.rcsb.org/pdb/explore.do?structureId=1QRI

The files/ URI seems to redirect you directly to the .pdb file in question, so I think it is the preferred way. However had, the explore.do query gives additional information.

Other useful URLs are:

http://www.rcsb.org/pdb/explore.do?structureId=1ZAA
http://dx.doi.org/10.2210/pdb1gi5/pdb

Usage example:

download_this_pdb_file http://www.rcsb.org/pdb/files/3O30.pdb
#


3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
# File 'lib/bioroebe/shell/shell.rb', line 3889

def download_this_pdb_file(
    i = '3O30'
  )
  i = ['3O30'] if i.nil? # If nil, use a default value.
  if i.is_a? Array
    i = ['3O30'] if i.empty?
    i.each {|entry| download_this_pdb_file(entry) }
  else
    i = i.to_s.dup
    unless i.end_with? '.pdb'
      i << '.pdb'
    end
    unless i.start_with? 'http://www.rcsb.org/pdb/files/'
      i[0,0] = 'https://www.rcsb.org/pdb/files/'
    end
    target_dir = download_dir?
    cd target_dir
    # ===================================================================== #
    # http://www.rcsb.org/pdb/files/3O30.pdb
    # ===================================================================== #
    download_this = "#{i.to_s}"
    erev "Checking for the availability of "\
         "#{olivedrab(download_this)}#{rev} next ..."
    if does_this_remote_file_exist?(download_this)
      erev 'Next downloading '+sfancy(download_this)+
           rev+' into '+sfancy(target_dir)+'.'
      esystem "wget #{download_this}" # We will just use wget for now.
      _ = ::Bioroebe.pdb_directory?
      if File.directory? _
        new_target = _+File.basename(download_this)
        erev 'Moving into '+sfancy(new_target)+rev+', where '\
             '.pdb files are kept by default.'
        mv(
          target_dir+File.basename(download_this),
          new_target
        )
      end
      register_this_download(download_this)
    else
      erev "The remote file at #{sfile(download_this)} #{rev}does not exist."
      erev 'Hence, we can not download it.'
    end
  end
end

#dump(optional_arguments = nil) ⇒ Object

#

dump

This method can be used to save the main DNA string into a file.

You can also store RNA of course; simply pass the argument “rna” or “to_rna” to this method.

#


8608
8609
8610
8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622
# File 'lib/bioroebe/shell/shell.rb', line 8608

def dump(
    optional_arguments = nil
  )
  what = dna_string?
  if optional_arguments.is_a? Array
    optional_arguments = optional_arguments.join(' ').strip
  end
  case optional_arguments
  when 'rna',/to_?rna/
    what = ::Bioroebe.to_rna(what)
  end
  into = file_dna_string_saved?
  erev 'Storing into `'+sfile(into)+'`.'
  write_what_into(what, into)
end

#e(i = '') ⇒ Object

#

e (e tag)

#


955
956
957
958
959
960
961
962
# File 'lib/bioroebe/shell/shell.rb', line 955

def e(
    i = ''
  )
  ::Bioroebe.e(i)
  if i and !i.empty?
    set_result(i) # This method will always assign to :result.
  end
end

#ee(i) ⇒ Object

#

ee (ee tag)

As e, but without newline. So basically it behaves like print.

#


969
970
971
# File 'lib/bioroebe/shell/shell.rb', line 969

def ee(i)
  e(i, false)
end

#efetch(i) ⇒ Object

#

efetch

Invocation example:

efetch https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=nuccore&id=189458859&rettype=fasta&retmode=text
#


1652
1653
1654
1655
1656
1657
1658
# File 'lib/bioroebe/shell/shell.rb', line 1652

def efetch(i)
  if i.is_a? Array
    i.each {|entry| efetch(entry) }
  else
    ::Bioroebe::Ncbi.efetch_by_url(i)
  end
end

#enable(i) ⇒ Object Also known as: use

#

enable (enable tag)

Enable-functionality can be passed through this method here.

Invocation example from within the bioshell:

enable colours
#


3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
# File 'lib/bioroebe/shell/shell.rb', line 3104

def enable(i)
  if i.is_a? Array
    i = i.join.strip
  end
  case i.to_s # case tag
  # ======================================================================= #
  # === enable cd_aliases
  #
  # This variant will be verbose.
  # ======================================================================= #
  when /^-?-?cd(-|_)?aliases$/
    erev 'class '+
         steelblue('Rcfiles::DirectoryAliases')+rev+' will be '\
         'enabled next, allowing'
    erev 'you to navigate the local filesystem '\
         'more easily so.'
    ::Bioroebe::Configuration.do_use_expand_cd_aliases
  # ======================================================================= #
  # === use colours
  # ======================================================================= #
  when /^colou?rs$/
    enable_colours
  # ======================================================================= #
  # === use xsel
  # ======================================================================= #
  when 'xsel'
    enable_xsel
  end
end

#enable_colours_in_an_extended_manner(be_verbose = :be_quiet) ⇒ Object Also known as: extended_enable_colours

#

enable_colours_in_an_extended_manner (enable tag)

We bundle all colour stuff here. Right now we use only the colour yellow.

#


10702
10703
10704
10705
10706
10707
10708
# File 'lib/bioroebe/shell/shell.rb', line 10702

def enable_colours_in_an_extended_manner(
    be_verbose = :be_quiet
  )
  enable_colours(be_verbose)
  ::Bioroebe.enable_colours
  set_default_highlight_colour
end

#enable_configurationObject

#

enable_configuration

#


10713
10714
10715
10716
10717
10718
10719
10720
10721
10722
10723
10724
10725
10726
10727
10728
10729
10730
10731
10732
10733
# File 'lib/bioroebe/shell/shell.rb', line 10713

def enable_configuration
  config_dir = ::Bioroebe.project_yaml_directory?+
               '/configuration/'
  unless Object.const_defined?(:Roebe) and
         Roebe.const_defined?(:Configuration)
    begin
      require 'roebe/configuration/class/configuration.rb'
    rescue LoadError; end
  end
  if Object.const_defined?(:Roebe) and
     Roebe.const_defined?(:Configuration)
    # ===================================================================== #
    # === Initialize @configuration
    # ===================================================================== #
    @configuration = ::Roebe::Configuration.new(config_dir, :do_not_run_yet)
    @configuration.be_verbose if @configuration.respond_to? :be_verbose
    @configuration.run
  else
    @configuration = nil
  end
end

#enable_gtkObject

#

enable_gtk

This enables gtk.

#


8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
# File 'lib/bioroebe/shell/shell.rb', line 8477

def enable_gtk
  begin
    if ENV['IS_ROEBE'].to_s
      load_gtk
      # =================================================================== #
      # Pulling in the controller.rb file is enough to also require the
      # other GTK-GUI components of the Bioroebe project.
      # =================================================================== #
      require 'bioroebe/gui/gtk3/controller/controller.rb'
    end
    return ::Bioroebe.controller # This will instantiate a new GTK widget.
  rescue LoadError => error
    e 'Failed to load GTK-related files. Showing the specific error next:'
    pp error
  end
end

#enable_gtk_section_antisensestrandObject

#

enable_gtk_section_antisensestrand

#


8505
8506
8507
8508
8509
# File 'lib/bioroebe/shell/shell.rb', line 8505

def enable_gtk_section_antisensestrand
  require 'bioroebe/gui/gtk3/anti_sense_strand/anti_sense_strand.rb'
  e 'Starting AntiSenseStrand ...'
  Bioroebe::GUI::Gtk::AntiSenseStrand.start_gui_application
end

#enable_xselObject

#

enable_xsel

#


9005
9006
9007
9008
9009
9010
9011
9012
# File 'lib/bioroebe/shell/shell.rb', line 9005

def enable_xsel
  if @internal_hash[:use_xsel]
    e 'xsel is already enabled.'
  else
    e 'Now enabling xsel.'
    @internal_hash[:use_xsel] = true
  end
end

#ensure_that_the_bioshell_log_directory_existsObject

#

ensure_that_the_bioshell_log_directory_exists

#


5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
# File 'lib/bioroebe/shell/shell.rb', line 5228

def ensure_that_the_bioshell_log_directory_exists
  # ======================================================================= #
  # We must check whether we really wish to create directories on startup
  # or not.
  # ======================================================================= #
  if @internal_hash and
     @internal_hash.has_key?(:create_directories_on_startup_of_the_shell) and
     @internal_hash[:create_directories_on_startup_of_the_shell]
    _ = bioshell_log_dir?
    unless File.directory? _
      unless @internal_hash[:silent_startup]
        erev "Next creating the directory #{sdir(_)}#{rev}."
      end
      mkdir(_)
    end
    # ===================================================================== #
    # Determine the path of the .yml file.
    # ===================================================================== #
    yaml_file = ::Bioroebe.project_yaml_directory?+
                'create_these_directories_on_startup/'\
                'create_these_directories_on_startup.yml'
    if File.exist? yaml_file
      YAML.load_file(yaml_file).each {|entry|
        # ================================================================= #
        # Create all specified subdirectories next.
        # ================================================================= #
        _ = "#{log_dir?}#{entry}/"
        unless File.directory? _
          unless @internal_hash[:silent_startup]
            erev "Next creating the directory #{sdir(rds(_))}#{rev}."
          end
          mkdir(_)
        end
      }
    end
  end
end

#enter_base_directoryObject

#

enter_base_directory

Use this method to enter the base directory.

#


6114
6115
6116
# File 'lib/bioroebe/shell/shell.rb', line 6114

def enter_base_directory
  cd ::Bioroebe.log_dir?
end

#enter_the_main_loopObject Also known as: loop_get_user_input, enter_main_loop

#

enter_the_main_loop (loop tag)

This is the main-loop of the shell.

#


11543
11544
11545
11546
11547
11548
11549
11550
11551
11552
11553
11554
11555
11556
11557
11558
11559
11560
11561
11562
11563
11564
11565
11566
11567
11568
11569
11570
11571
11572
11573
11574
11575
11576
11577
11578
11579
11580
11581
11582
11583
11584
11585
11586
11587
11588
11589
11590
11591
11592
11593
11594
11595
11596
11597
11598
11599
11600
11601
11602
11603
11604
11605
11606
11607
11608
11609
11610
11611
11612
11613
11614
11615
11616
11617
11618
11619
11620
11621
11622
11623
11624
11625
11626
11627
11628
11629
11630
11631
11632
11633
11634
11635
11636
11637
11638
11639
11640
11641
11642
11643
11644
11645
11646
11647
11648
11649
11650
11651
11652
11653
11654
11655
11656
11657
11658
11659
11660
11661
11662
11663
11664
11665
11666
11667
11668
11669
11670
11671
11672
11673
11674
11675
11676
11677
11678
11679
11680
11681
11682
11683
11684
11685
11686
11687
11688
11689
11690
11691
11692
11693
11694
11695
11696
11697
11698
11699
11700
11701
11702
11703
11704
11705
11706
11707
11708
11709
11710
11711
11712
# File 'lib/bioroebe/shell/shell.rb', line 11543

def enter_the_main_loop
  exit_from_the_main_loop = false
  loop {
    begin
      obtain_user_input                         # 1) Obtain the user input here.
      add_the_current_user_input_to_the_history # 2) Add the user input to the history.
      if @internal_hash[:user_input]
        unless @internal_hash[:user_input].empty?
          # =============================================================== #
          # Pass the user input into the menu next. We will use an
          # Array for this, as user input such as "ls; random 20" should
          # also be valid.
          # =============================================================== #
          user_input = [ @internal_hash[:user_input] ].flatten
          user_input.each {|use_this_as_user_input|
            # ============================================================= #
            # Keep track of the "original" input next:
            # ============================================================= #
            @internal_hash[:original_input] = use_this_as_user_input.dup.chomp.dup
            # ============================================================= #
            # Remove leading 5'- and trailing -3' as these are currently
            # forbidden as input. This check should come quite early.
            #
            # Example input for that may demonstrate this:
            #
            #   5'-ATGGGCAAA
            #
            # ============================================================= #
            use_this_as_user_input[0, 3] = '' if use_this_as_user_input.start_with?("5'-")
            use_this_as_user_input[-3,3] = '' if use_this_as_user_input.end_with?("-3'")
            use_this_as_user_input[-3,3] = '' if use_this_as_user_input.end_with?("-'3")
            # ======================================================================= #
            # === Handle special arguments next
            #
            # Must not start and end with a number, as we will assume input such
            # as "11 - 33" in this case. However had, input such as "random 333"
            # must remain valid.
            #
            # Note that the following input may also be valid:
            #
            #   3to1 ARG-ALA-SER-LEU-PHE-TRP-LYS-HIS-ASN-SER-VAL-LEU-ILE-VAL-PRO
            #
            # This explains why the Regex is a bit complicated.
            # ======================================================================= #
            if use_this_as_user_input.include?(' ') and
              (use_this_as_user_input !~ /^\d+\s+/) and
              (use_this_as_user_input !~ /^\d+.+\d{1,3}\s+$/)
              # ===================================================================== #
              # We must keep in mind that input may be an assignment too,
              # sometimes. In these cases the input will include a '='
              # character. But it could also be an assignment towards
              # a sequence, such as in the following case:
              #
              #   [33,0] = GAATTC
              #
              # ===================================================================== #
              case use_this_as_user_input
              # ===================================================================== #
              # === Assignment via [START_POSITION, END_POSITION]
              #
              # This is a shortcut that allows us to quickly grab a subsequence.
              #
              # See the following link for the explanation of the regex:
              #
              #   https://rubular.com/r/J13Eikdly0
              #
              # Usage example:
              #
              #   [33,0] = GAATTC
              #
              # ===================================================================== #
              when /^\[?(\d{0,10}),\s{0,1}(\d{0,10})\]?\s*=\s*'?([A-Za-z]*)'?$/
                start_position = $1.to_s.dup
                end_position   = $2.to_s.dup
                new_string     = $3.to_s.dup
                erev simp(new_string.size.to_s)+rev+' nucleotides will be inserted '\
                     'at nucleotide position '+
                     sfancy(start_position.to_s)+rev+'.'
                dna_sequence_object?[start_position, end_position] = new_string
                return # Do not evaluate any further for this entry point.
              # ===================================================================== #
              # === User may try a comparison such as:
              #
              #   ATCGATCGATCG == ATCGATCG
              #   ATG == ATG
              #
              # ===================================================================== #
              when /==/
                erev try_to_compare_these_two_sequences_for_equality(use_this_as_user_input)
                return # And "exit" here.
              end
            end
            # ======================================================================= #
            # === Chop off "?" if it is the last character
            # ======================================================================= #
            if use_this_as_user_input.end_with?('?') and (use_this_as_user_input.size > 1)
              if debug?
                ewarn 'Removing the last character `?` in order to '\
                      'simplify input handling.'
              end
              use_this_as_user_input.chop!
            end if remove_question_mark?
            # ======================================================================= #
            # Next check for three-letter code as input.
            # ======================================================================= #
            if use_this_as_user_input.include?('-') and
               Bioroebe.is_in_the_three_letter_code?(use_this_as_user_input)
              erev 'A three-letter aminoacid sequence was given as input.'
              erev 'This will be changed into the most likely aminoacid'
              erev 'sequence.'
              use_this_as_user_input = Bioroebe.deduce_most_likely_aminoacid_sequence_as_string(
                    Bioroebe.three_to_one(
                      use_this_as_user_input.delete('-')
                    )
                  )
              assign(use_this_as_user_input) { :be_verbose }
            end
            parse_this_user_input(use_this_as_user_input) # 3) Always parse the user input.
            # ============================================================= #
            # Intercept " quotes here.
            # ============================================================= #
            if use_this_as_user_input.include?('"') and use_this_as_user_input.include?(N)
              # a = start_clipboard('"') if i.include? '"'
              start_clipboard('"') if use_this_as_user_input.include? '"'
            end
            result_from_the_menu = menu(
              @internal_hash[:command_to_be_passed_to_the_menu]
            )
            case result_from_the_menu
            # ============================================================= #
            # === :exit_gracefully
            # ============================================================= #
            when :exit_gracefully
              say_goodbye
              exit_from_the_main_loop = true
            # ============================================================= #
            # === :break
            # ============================================================= #
            when :break
              case exit_the_shell_how?
              # =========================================================== #
              # === :exit_gracefully
              # =========================================================== #
              when :exit_gracefully # User wants to exit here.
                say_goodbye
                exit_from_the_main_loop = true
              # =========================================================== #
              # === :instantly
              # =========================================================== #
              when :instantly
                exit_from_the_main_loop = true
              end
              exit_from_the_main_loop = true
            else
            end
          }
          @internal_hash[:user_input] = nil # And clear it here again.
        end
      end
      if exit_from_the_main_loop == true
        break
      end
    # ===================================================================== #
    # Rescue sigints (aka ctrl-c) and SystemExit.
    # ===================================================================== #
    rescue Interrupt, SystemExit
      e
    end
  }
end

#ereturn(i = '') ⇒ Object

#

ereturn

#


6287
6288
6289
6290
# File 'lib/bioroebe/shell/shell.rb', line 6287

def ereturn(i = '')
  e i
  return
end

#erev(i = '') ⇒ Object

#

erev (erev tag)

Easier wrapper over output that has rev().

#


9247
9248
9249
# File 'lib/bioroebe/shell/shell.rb', line 9247

def erev(i = '')
  e "#{rev}#{i}"
end

#exit_the_shell_how?Boolean

#

exit_the_shell_how?

#

Returns:

  • (Boolean)


1059
1060
1061
# File 'lib/bioroebe/shell/shell.rb', line 1059

def exit_the_shell_how?
  @internal_hash[:exit_the_shell_how]
end

#extract_sequence_from_this_file(i) ⇒ Object Also known as: extract_sequence

#

extract_sequence_from_this_file

Use this method to extract a DNA sequence from the given file.

The given input should thus, logically, be an existing (local) file.

Currently this works via genbank .gb files but in the future, other formats may well be supported too.

#


8944
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
# File 'lib/bioroebe/shell/shell.rb', line 8944

def extract_sequence_from_this_file(i)
  if i.is_a? Array
    i.each {|entry| extract_sequence_from_this_file(entry) }
  else
    if File.exist? i
      extname = File.extname(i).delete('.')
      case extname
      when 'gb'
        # =================================================================== #
        # Handle genbank .gb files here.
        # =================================================================== #
        _ = ::Bioroebe::GenbankParser.new(i) { :do_not_report_anything }
        assign_sequence(_.sequence?)
      end
    else
      no_file_exists_at(i)
    end
  end
end

#fasta?Boolean Also known as: last_fasta?, last_fasta_entry?

#

fasta?

We need a query method over the main fasta object, IF it was set.

Since we already have an Array that keeps track of these objects, we can simply grab the last one from that collection.

#

Returns:

  • (Boolean)


3664
3665
3666
# File 'lib/bioroebe/shell/shell.rb', line 3664

def fasta?
  array_fasta?.last
end

#fasta_file?(i = :fasta_file) ⇒ Boolean

#

fasta_file?

#

Returns:

  • (Boolean)


6054
6055
6056
6057
6058
6059
6060
# File 'lib/bioroebe/shell/shell.rb', line 6054

def fasta_file?(i = :fasta_file)
  if @internal_hash[:fasta_file].has_key?(i)
    @internal_hash[:fasta_file].fetch(i)
  else
    erev 'We could not find the key called `'+simp(i.to_s)+rev+'`.'
  end
end

#feedback_versionObject

#

feedback_version

#


7560
7561
7562
# File 'lib/bioroebe/shell/shell.rb', line 7560

def feedback_version
  erev version?
end

#feedback_where_files_are_kept_locallyObject

#

feedback_where_files_are_kept_locally

We feedback where some files are kept, like the restriction enzymes.

#


8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
# File 'lib/bioroebe/shell/shell.rb', line 8116

def feedback_where_files_are_kept_locally
  erev 'The restriction enzymes are kept here:'
  e
  e "  #{sfile(::Bioroebe.restriction_enzymes_file)}"
  e
  erev 'The files with the mass table of the amino acids is kept here:'
  e
  e "  #{sfile(::Bioroebe::FILE_AMINO_ACIDS_MASS_TABLE)}"
  e
  report_where_we_store
end

#feedback_whether_we_are_in_debug_modeObject

#

feedback_whether_we_are_in_debug_mode

#


10766
10767
10768
# File 'lib/bioroebe/shell/shell.rb', line 10766

def feedback_whether_we_are_in_debug_mode
  erev 'Are we in debug mode? '+simp(debug?.to_s)+rev
end

#feedback_whether_we_will_also_set_the_xorg_bufferObject

#

feedback_whether_we_will_also_set_the_xorg_buffer

#


8701
8702
8703
8704
# File 'lib/bioroebe/shell/shell.rb', line 8701

def feedback_whether_we_will_also_set_the_xorg_buffer
  erev "Will we also set the Xorg buffer? "\
       "#{sfancy(vt(configuration?.additionally_set_xorg_buffer.to_s))}"
end

#fetch_from_pdb(i) ⇒ Object

#

fetch_from_pdb

This method can obtain a .pdb file from the pdb website.

It can also return the aminoacid sequence.

A URL for the .pdb may be available like this:

https://files.rcsb.org/view/2BTS.pdb
https://files.rcsb.org/view/355D.pdb

For the FASTA sequence, try:

https://www.rcsb.org/fasta/entry/2BTS/display
#


5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
# File 'lib/bioroebe/shell/shell.rb', line 5760

def fetch_from_pdb(i)
  if i.is_a? Array
    i = i.join(' ').strip
  end
  i.upcase!
  remote_url = "https://www.rcsb.org/structure/#{i}"
  erev 'Looking for the protein called '+steelblue(i)+rev+
       ' at pdb next. (URL: '+royalblue(remote_url)+rev+')'
  e
  open_in_browser(remote_url)
  e
  remote_url_to_the_pdb_file = "https://files.rcsb.org/view/#{i}.pdb"
  esystem "wget #{remote_url_to_the_pdb_file}"
  e
  begin
    erev 'The fasta sequence, obtained from '+remote_url+', is:'
    e
    result = ::Bioroebe.return_fasta_sequence_from_this_pdb_file(remote_url)
    e result
    e
    set_aminoacid_sequence(result) # And assign it as well.
  rescue Exception => error
    pp error
  end
  # ======================================================================= #
  # The file may be without a .pdb entry, so rename it in that case.
  # ======================================================================= #
  target = File.basename(remote_url_to_the_pdb_file)
  if File.exist? target
    unless target.end_with? '.pdb'
      unless File.exist? target+'.pdb'
        new_location = target
        rename_file(i, new_location) unless File.exist?(new_location)
        target = new_location
      end
    end
    move_file_to_its_correct_location(target)
  end
end

#file_dna_string_saved?Boolean

#

file_dna_string_saved?

#

Returns:

  • (Boolean)


10801
10802
10803
# File 'lib/bioroebe/shell/shell.rb', line 10801

def file_dna_string_saved?
  @internal_hash[:file_dna_string_saved]
end

#find_all_orfs(i = dna_sequence? ) ⇒ Object

#

find_all_orfs

This method will return all ORFs within the target sequence.

It will return an Array, and then we will display these ORFs, starting with the LONGEST ORF first.

#


11043
11044
11045
11046
11047
11048
11049
11050
11051
11052
11053
11054
11055
11056
11057
11058
11059
11060
11061
11062
11063
11064
11065
11066
11067
11068
11069
11070
11071
11072
11073
11074
11075
11076
11077
11078
11079
11080
11081
11082
11083
# File 'lib/bioroebe/shell/shell.rb', line 11043

def find_all_orfs(
    i = dna_sequence?
  )
  all_start_codons = i.to_enum(:scan, /#{::Bioroebe.start_codon?}/i).map { |match|
    [$`.size] # [$`.size, match]
  }
  all_stop_codons = i.to_enum(:scan, /(TGA|TAG|TAA)/i).map { |match|
    [$`.size]
  }
  array_with_the_proper_matches = []
  current_match = nil
  all_start_codons.each {|start_codon_position|
    start_codon_position = start_codon_position.first
    # ===================================================================== #
    # Find the nearest stop codon position.
    # ===================================================================== #
    all_stop_codons.reverse.each {|stop_codon_position|
      stop_codon_position = stop_codon_position.first
      length = stop_codon_position - start_codon_position
      next if length < 1
      current_match = [start_codon_position, length]
      if current_match
        # Must be a smaller match.
        if length < current_match[1] # [1] refers to the length.
          unless length < 3
            current_match = [start_codon_position, length]
          end
        end 
      end
    }
    array_with_the_proper_matches << current_match
  }
  cliner token: '-'
  pp array_with_the_proper_matches
  cliner token: '-'
  _ = dna_sequence?
  array_with_the_proper_matches.each {|start, stop|
    subsequence = _[start.to_i .. stop.to_i]
    erev subsequence unless subsequence.empty?
  }
end

#find_complementary_strand(i = dna_sequence? ) ⇒ Object Also known as: show_complementary_strand

#

find_complementary_strand

Invoke this via:

3'-ATGCCTGCC
#


11879
11880
11881
11882
11883
11884
11885
11886
11887
11888
11889
11890
11891
11892
11893
11894
11895
11896
11897
# File 'lib/bioroebe/shell/shell.rb', line 11879

def find_complementary_strand(
    i = dna_sequence?
  )
  _ = i.strip # The original input.
  if _.include? "3'-" and _.start_with?('3')
    _.gsub!(/3'-/,'')
    _.gsub!(/-5'/,'')
    _.gsub!(/3'-/,'')
    erev lpad?+leading_three_prime+
         colourize_nucleotide(_, :do_not_add_anything_else)+
         trailing_five_prime
  end
  result = lpad?+
           colourize_nucleotide(
             return_complement(i.reverse)
           )
  erev result
  return result
end

#find_gene(i = :default) ⇒ Object

#

find_gene

Wrapper towards class Bioroebe::FindGene.

#


11185
11186
11187
11188
11189
11190
11191
11192
11193
11194
11195
# File 'lib/bioroebe/shell/shell.rb', line 11185

def find_gene(i = :default)
  case i
  when :default, nil
    i = dna_sequence?
  end 
  if i.empty?
    report_that_a_string_must_be_assigned_first
  else
    ::Bioroebe::FindGene.new(i.upcase) # bl $BIOROEBE/find_gene.rb
  end
end

#find_kdel_sequenceObject

#

find_kdel_sequence

#


4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
# File 'lib/bioroebe/shell/shell.rb', line 4570

def find_kdel_sequence
  # ======================================================================= #
  # We must operate on the aminoacid-sequence next.
  # ======================================================================= #
  aminoacid_sequence = aminoacid_sequence?.to_s
  scan_result = aminoacid_sequence.scan(/KDEL/)
  has_kdel = scan_result.empty?
  if has_kdel
    erev 'This sequence has at the least '+
         steelblue('one')+' KDEL sequence. '\
         '(Has '+scan_result.size.to_s+')'
  else
    erev 'This sequence does not have any KDEL sequence.'
  end
end

#find_longest_substring(i = dna_string?) ) ⇒ Object

#

find_longest_substring

#


6207
6208
6209
6210
6211
6212
# File 'lib/bioroebe/shell/shell.rb', line 6207

def find_longest_substring(i = dna_string?)
  if i.is_a? String and i.include? ' '
    i = i.split(' ')
  end
  ::Bioroebe::FindLongestSubstring.new(i.first, i.last)
end

#find_longest_substring_via_LCS(i) ⇒ Object

#

find_longest_substring_via_LCS

To invoke this, try:

longest_substring? ATTATTGTT | ATTATTCTT
#


7777
7778
7779
7780
# File 'lib/bioroebe/shell/shell.rb', line 7777

def find_longest_substring_via_LCS(i)
  i = i.join(' | ') if i.is_a? Array
  ::Bioroebe::FindLongestSubstringViaLCSalgorithm.new(i) { :do_also_show_the_two_sequences }
end

#find_restriction_enzymes_that_cut_at(i) ⇒ Object

#

find_restriction_enzymes_that_cut_at

A wrapper over find_restriction_sites().

#


9037
9038
9039
9040
9041
9042
9043
9044
# File 'lib/bioroebe/shell/shell.rb', line 9037

def find_restriction_enzymes_that_cut_at(i)
  erev 'Trying to find restriction enzymes that '\
       'cut at `'+sfancy(i)+rev+'`.'
  result = find_restriction_sites(i)
  unless result
    erev 'Found no result for this sequence.'
  end
end

#find_restriction_sites(i = string?) ) ⇒ Object

#

find_restriction_sites

Call the parent method in the Bioroebe class.

#


8230
8231
8232
8233
# File 'lib/bioroebe/shell/shell.rb', line 8230

def find_restriction_sites(i = string?)
  i = string? if i.nil?
  Bioroebe.restriction_sites?(i) # bl mybioruby
end

#find_shine_dalgarno_sequence(i = dna_sequence_as_string? ) ⇒ Object

#

find_shine_dalgarno_sequence

Use this method to attempt to try and find a SD-sequence.

#


3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
# File 'lib/bioroebe/shell/shell.rb', line 3286

def find_shine_dalgarno_sequence(
    i = dna_sequence_as_string?
  )
  i.upcase! # Need to ensure upcased input.
  pure_sd_sequence = 'AGGAGGU'.dup
  if is_dna?
    pure_sd_sequence.tr!('U','T')
  end
  if i.nil?
    report_that_a_string_must_be_assigned_first
  else
    sd_sequence = steelblue(
      dna_padding(pure_sd_sequence, :no_spaces).lstrip
    )
    if i.include? 'T' # Assume that we have a DNA string rather than RNA.
      pure_sd_sequence = 'AGGAGGT'
      sd_sequence = steelblue(
        dna_padding(pure_sd_sequence, :no_spaces).lstrip
      )
    end
    if i.include? pure_sd_sequence
      erev "Yes, our string contains at least one Shine Dalgarno "\
           "(#{sd_sequence}#{rev}) sequence."
      n_sd_sequences = i.scan(/#{pure_sd_sequence}/).size.to_s
      erev 'We have found '+sfancy(n_sd_sequences)+rev+' instance(s) of '\
           'Shine Dalgarno ('+sd_sequence+rev+') Sites.'
      erev 'We will next show the particular sequence in '\
           'question ('+simp(pure_sd_sequence)+rev+').'
      # =================================================================== #
      # Next, try to find restriction enzymes that cut at the
      # Shine-Dalgarno site.
      # =================================================================== #
      try_to_find_restriction_enzymes_for(:shine_dalgarno)
    else
      erev "We did not find a Shine Dalgarno ("\
           "#{simp(sd_sequence)}#{rev}) sequence."
    end
  end
end

#first(i) ⇒ Object

#

first

#


7069
7070
7071
7072
7073
7074
7075
7076
# File 'lib/bioroebe/shell/shell.rb', line 7069

def first(i)
  if i.to_s =~ /^\d+$/ # If the input is only numbers
    erev 'Obtaining the first '+simp(i).to_s+rev+' nucleotides next:'
    erev simp(seq?[0,i.to_i])
  else # Else change the first nucleotide.
    change_first_nucleotide_to(f)
  end
end

#first_argument?Boolean Also known as: f?, f

#

first_argument?

#

Returns:

  • (Boolean)


7438
7439
7440
# File 'lib/bioroebe/shell/shell.rb', line 7438

def first_argument?
  @internal_hash[:first_argument]
end

#format_this_nucleotide_sequence(i, &block) ⇒ Object

#

format_this_nucleotide_sequence

This method will properly format the passed-in nucleotide sequence, by making use of class ShowNucleotideSequence.

It will return the formatted String.

#


6105
6106
6107
# File 'lib/bioroebe/shell/shell.rb', line 6105

def format_this_nucleotide_sequence(i, &block)
  ::Bioroebe.format_this_nucleotide_sequence(i) { block }
end

#freeze_the_main_sequenceObject

#

freeze_the_main_sequence

#


5359
5360
5361
# File 'lib/bioroebe/shell/shell.rb', line 5359

def freeze_the_main_sequence
  @internal_hash[:the_main_sequence_is_frozen] = true
end

#generate_palindrome(i) ⇒ Object

#

generate_palindrome

This method will generate a Palindrome sequence.

#


3642
3643
3644
3645
# File 'lib/bioroebe/shell/shell.rb', line 3642

def generate_palindrome(i)
  i = i.join.strip if i.is_a? Array
  ::Bioroebe::PalindromeGenerator.new(i).report
end

#generate_pdf_tutorialObject

#

generate_pdf_tutorial

Easier wrapper to generate the .pdf Tutorial.

#


5983
5984
5985
# File 'lib/bioroebe/shell/shell.rb', line 5983

def generate_pdf_tutorial
  ::Bioroebe.generate_pdf_tutorial
end

#generate_random_dna_sequence_with_variable_length_and_variable_compositionObject

#

generate_random_dna_sequence_with_variable_length_and_variable_composition

This method will generate a random DNA sequence of variable length and composition.

#


2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
# File 'lib/bioroebe/shell/shell.rb', line 2836

def generate_random_dna_sequence_with_variable_length_and_variable_composition
  e 'Input the desired length of your DNA string:'
  length = $stdin.gets.chomp.to_i
  e 'Input the per