Class: Bioroebe::Taxonomy::Interactive

Inherits:
CommandlineApplication show all
Includes:
Bioroebe, Bioroebe::Taxonomy, Shared, Roebe::SqlParadise
Defined in:
lib/bioroebe/taxonomy/interactive.rb,
lib/bioroebe/taxonomy/menu.rb

Overview

Bioroebe::Taxonomy::Interactive

Constant Summary collapse

FASTA_SQL =
#

FASTA_SQL

This constant will point towards a location such as “/home/Temp/bioroebe/autogenerated_sql_files/fasta.sql”.

#
AUTOGENERATED_SQL_FILES_DIR+'fasta.sql'
BE_VERBOSE =
#

BE_VERBOSE

Constants for this class here.

#
true
USE_COLOURS =
#

USE_COLOURS

Whether to have colourized output or not.

#
true
NO_HELP =
#

NO_HELP

#
false

Constants included from Bioroebe::Taxonomy

PROJECT_YAML_DIR

Constants included from Constants

Constants::AA_DIR, Constants::ARRAY_PROJECT_FILES, Constants::Archaea_Taxonomy_ID, Constants::BASE, Constants::BASE_URL, Constants::Bacteria_Taxonomy_ID, Constants::CITATIONS, Constants::CURATED_DIR, Constants::DATA_DIR, Constants::DELNODES, Constants::DIVISION, Constants::Eukaryota_Taxonomy_ID, Constants::FILE_USE_THIS_DATABASE, Constants::GEM_DIR, Constants::GENCODE, Constants::INCOMING_DIR, Constants::INFO_DIR, Constants::LAST_INTERACTIVE_COMMAND, Constants::LOCALOME_DIR, Constants::LOCAL_MIRROR, Constants::MERGED, Constants::MODULE_PATH, Constants::NAMES, Constants::NAMES_SQL, Constants::NCBI_BASE, Constants::NODES, Constants::NODES_SQL, Constants::NT_DIR, Constants::POSTGRESQL_QUERY_SIZE, Constants::POSTGRE_LOGIN_COMMAND, Constants::PROJECT_DOC_DIR, Constants::SEQUENCES_DIR, Constants::SHARED_HOME, Constants::TAXONOMY_BROWSER, Constants::TEMP_DIR, Constants::TEST_DIR, Constants::TMP_DIR, Constants::URL1

Constants included from Bioroebe

ALLOWED_RNA_NUCLEOTIDES, AMINOACIDS_DIRECTORY, AMINOACID_FAMILIES, AMINO_ACIDS, AMINO_ACIDS_AVERAGE_MASS_TABLE, AMINO_ACIDS_AVERAGE_MONOISOTOPIC_TABLE, AMINO_ACIDS_ENGLISH, AMINO_ACIDS_LONG_NAME_TO_ONE_LETTER, AMINO_ACIDS_MASS_TABLE, AMINO_ACIDS_MOLECULAR_FORMULA, AMINO_ACIDS_RESTE, AMINO_ACIDS_THREE_TO_ONE, ARRAY_AMINOACIDS_THAT_CAN_BE_PHOSPHORYLATED, ARRAY_AMINO_ACIDS_ALPHABET, ARRAY_NLS_SEQUENCES, ARRAY_REGISTERED_ACTIONS, ARRAY_VALID_DNA_SEQUENCES, AUTOGENERATED_SQL_FILES_DIR, Aminoacids, BIOROEBE_AT_HOME, BIOROEBE_YAML_AMINOACIDS_DIRECTORY, BLOSUM_DIRECTORY, CALCULATE_DIRECTORY, CLEAVE_AND_DIGEST_DIRECTORY, CODONS_DIRECTORY, CODON_TABLES_DIRECTORY, CODON_TABLES_DIRECTORY_FREQUENCY, CONFIGURATION_DIRECTORY, COUNT_DIRECTORY, DEFAULT_DNA_SEQUENCE, DEFAULT_LENGTH_FOR_DNA, DIRECTORY_CODON_TABLES_FREQUENCIES, DNA_NUCLEOTIDES, DOTPLOTS_DIRECTORY, ELECTRON_MICROSCOPY_DIRECTORY, EMAIL, ENGLISH_LONG_NAMES_FOR_THE_AMINO_ACIDS, ENZYMES_DIRECTORY, FASTA_AND_FASTQ_DIRECTORY, FASTA_ENTRIES, FIELD_TERMINATOR, FILE_AMINOACIDS_MOLECULAR_FORMULA, FILE_AMINOACIDS_THREE_TO_ONE, FILE_AMINO_ACIDS, FILE_AMINO_ACIDS_ABBREVIATIONS, FILE_AMINO_ACIDS_AVERAGE_MASS_TABLE, FILE_AMINO_ACIDS_ENGLISH, FILE_AMINO_ACIDS_FREQUENCY, FILE_AMINO_ACIDS_LONG_NAME_TO_ONE_LETTER, FILE_AMINO_ACIDS_MASS_TABLE, FILE_AMINO_ACIDS_MOLECULAR_FORMULA, FILE_AMINO_ACIDS_RESTE_YAML, FILE_AMINO_ACIDS_THREE_TO_ONE, FILE_BIO_LANG, FILE_BLOSUM45, FILE_BLOSUM50, FILE_BLOSUM62, FILE_BLOSUM80, FILE_BLOSUM90, FILE_BLOSUM_MATRIX, FILE_BROWSER, FILE_CHROMOSOME_NUMBERS, FILE_COLOURIZE_FASTA_SEQUENCES, FILE_DEFAULT_COLOURS_FOR_THE_AMINOACIDS, FILE_EXPAND_CD_ALIASES, FILE_GFP_SEQUENCE, FILE_HYDROPATHY_TABLE, FILE_NUCLEAR_LOCALIZATION_SEQUENCES, FILE_NUCLEOTIDES, FILE_NUCLEOTIDES_WEIGHT, FILE_RESTRICTION_ENZYMES, FILE_WEIGHT_OF_COMMON_PROTEINS, FTP_NCBI_TAXONOMY_DATABASE, Fasta, HASH_DNA_NUCLEOTIDES, HOME_DIRECTORY_OF_USER_X, HYDROPATHY_TABLE, LAST_UPDATE, LOCALHOST, LOCAL_DIRECTORY_FOR_UNIPROT, MAIN_DELIMITER, N, NAMES_ENTRIES, NAME_OF_BIO_SHELL, NCBI_GENE, NCBI_NUCCORE, NODES_ENTRIES, NUCLEAR_LOCALIZATION_SEQUENCES, NUCLEOTIDES, NUCLEOTIDES_DIRECTORY, PALINDROMES_DIRECTORY, PARSERS_DIRECTORY, PATHWAYS_DIRECTORY, PATH_TO_THE_RELION_BINARY, PATTERN_DIRECTORY, PDB_DIRECTORY, POSSIBLE_AMINO_ACIDS, POSSIBLE_DNA_NUCLEOTIDES, POSSIBLE_RNA_NUCLEOTIDES, ProteinToDNA, R, REGEX_FOR_N_GLYCOSYLATION_PATTERN, REGEX_PROSITE_FOR_ANY_AMINOACID, RNA_NUCLEOTIDES, ROW_TERMINATOR, RUBY_SRC, SEQUENCE_DIRECTORY, SHALL_WE_LOG_LAST_UPDATE, STOP_CODONS, STRING_MATCHING_DIRECTORY, Seq, Bioroebe::TABULATOR, Bioroebe::TOKEN, Bioroebe::TOPLEVEL_METHODS_DIRECTORY, Bioroebe::TWENTY_CANONICAL_AMINOACIDS, UNICODE_HORIZONTAL_BAR, URL_TO_TAXONOMY_ARCHIVE, URL_TO_THE_DOCUMENTATION, USERS_X, USE_THIS_BROWSER, USE_THIS_COLOUR_FOR_DNA, USE_THIS_ENCODING, UTF_ENCODING, VALID_WAYS_TO_EXIT, VERSION, VERTICAL_UNICODE_BAR

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 included from Bioroebe::Taxonomy

#array_size?, be_verbose?, cd, #citations?, #clean, cleanup, #delnodes?, #division?, download_directory?, e, #edit, #edit_gemspec, #edit_instructions, #edit_password, #edit_shared_code_file, #edit_taxonomy, enable_colours, ensure_that_temp_dir_exists, #find_highest_entries_in_sql, #gencode?, #generate_html_links_for, #get_id_of, #get_parent_id_of, #get_scientific_name_of, interactive, load, #merged?, #names?, #nodes?, #pad, #pad_properly, #pad_sql, project_base_dir?, #project_base_dir?, project_yaml_dir?, #remove_delimiter, report_n_species, #return_current_hours_minutes_seconds, #return_full_lineage_of, save_into_which_file?, save_when_we_last_updated_the_database, #search_id, show_current_time_and_date, #show_current_time_and_date, #show_help, show_remote_urls_to_the_NCBI_taxonomy_webpage, #split, status, status?, taxonomy_download_directory?, #test, #to_utf, update, use_colours?, #verify_proper_sql_structures

Methods included from Shared

be_quiet, be_verbose?, #cd, #edit_login_file, #eliminate_tabulator, #ensure_that_download_dir_exists, #ensure_that_temp_dir_exists, #mkdir, #readlines, #set_pgpassword, #show_password, #show_time_now, #split_at, #split_at_tabulator, #tokenize

Methods included from Constants

#info_dir?, #work_directory?

Methods included from Bioroebe

#Sequence, [], ad_hoc_task, align_this_string_via_multiple_sequence_alignment, all_aminoacids?, #all_aminoacids?, allowed_dna_nucleotides?, amino_acid_average_mass, amino_acid_monoisotopic_mass, aminoacid_families?, aminoacid_frequency, aminoacid_substitution, aminoacids?, append_what_into, array_colourize_this_aminoacid, atomic_composition, automatically_rename_this_fasta_file, available_blosum_matrices?, available_codon_tables?, base_composition, batch_create_windows_executables, be_verbose?, bisulfite_treatment, blast_neighborhood, blosum_directory?, blosum_matrix, calculate_exponential_growth, calculate_levensthein_distance, calculate_melting_temperature_for_more_than_thirteen_nucleotides, calculate_n50_value, calculate_original_amount_of_cells_of_exponential_growth, calculate_the_frequencies_of_this_species, calculate_weight_of_the_aminoacids_in_this_fasta_file, can_base_pair_with?, #cat, cat, change_directory, clear_array_colourize_this_aminoacid, clear_stop_codons, cleave, cleave_with_trypsin, cliner, codon_frequencies_of_this_sequence, codon_frequency_of_this_string, codon_table_dataset?, codon_table_in_use?, codon_tables, codons_for_this_aminoacid?, colourize_aa, colourize_this_aminoacid_sequence_for_the_commandline, colourize_this_fasta_dna_sequence, colours, compacter, complement, complementary_dna_strand, complementary_rna_strand, compseq, contains_an_inverted_repeat?, convert_global_env, convert_one_letter_to_full, convert_one_letter_to_three, convert_this_codon_to_that_aminoacid, count_AT, count_GC, count_amount_of_aminoacids, count_amount_of_nucleotides, count_non_DNA_bases_in_this_sequence, create_file, create_jar_archive, create_new_sequence, create_random_aminoacids, create_the_pdf_tutorial, decode_this_aminoacid_sequence, deduce_aminoacid_sequence, deduce_most_likely_aminoacid_sequence, deduce_most_likely_aminoacid_sequence_as_string, #default_colour?, default_colour?, delimiter?, determine_n_glycosylation_matches, determine_start_codons_from_the_codon_table, determine_stop_codons_from_the_codon_table, digest_this_dna, directory_frequencies?, disable_colours, display_all_open_reading_frames_from_this_sequence, dna_sequence, dna_to_aminoacid_sequence, do_not_truncate, do_truncate, dotplot_array, downcase_chunked_display, download, download_directory?, download_fasta, download_human_genome, download_taxonomy_database, download_this_pdb, e, #ecomment, editor?, embeddable_interface, enable_colours, ensure_that_the_base_directories_exist, erev, esystem, every_reverse_palindrome_in_this_string, ewarn, extract, extractseq, fasta_dir?, fasta_directory?, fetch_data_from_uniprot, fetch_fasta_sequence_from_pdb, file_amino_acids, file_amino_acids_abbreviations, file_amino_acids_frequency, file_amino_acids_long_name_to_one_letter, file_fastq_quality_schemes, file_molecular_weight, #file_restriction_enzymes, file_restriction_enzymes, file_statistics?, file_talens, filter_away_invalid_aminoacids, filter_away_invalid_nucleotides, find_substring, format_this_nucleotide_sequence, frequency_per_thousand, gc_content, genbank_to_fasta, generate_nucleotide_sequence_based_on_these_frequencies, generate_pdf_tutorial, generate_random_dna_sequence, generate_random_rna_sequence, guess_format, hamming_distance, has_this_restriction_enzyme?, hash_codon_tables?, index_this_fasta_file, infer_type_from_this_sequence, initialize_codons, initialize_default_stop_codons, input_as_dna, is_a_protein?, is_a_purine?, is_a_pyrimidine?, is_a_stop_codon?, is_an_aminoacid?, is_in_the_three_letter_code?, #is_on_roebe?, is_on_roebe?, is_palindrome?, is_reverse_complement?, is_start_codon?, is_this_a_valid_codon?, is_this_sequence_a_EGF2_pattern?, last_updated?, leading_five_prime, length_modifier, levenshtein_distance, load_and_return_the_restriction_enzymes, load_psych_or_syck, load_the_codon_table_dataset, log_directory?, longest_common_substring, map_ncbi_entry_to_eutils_id, min3, mirror_repeat_of, mkdir, #mkdir, move_file, move_file_to_its_correct_location, mv, n_stop_codons_in_this_sequence?, n_transitions, n_transversions, no_file_exists_at, nucleotide_permutations, number_of_clones, one_to_three, only_nucleotides?, open_in_browser, open_reading_frames_to_aminoacid_sequence, overwrite_fasta_header, palindrome_generator, parse, parse_fasta, parse_fasta_file, parse_fasta_quietly, parse_pdb_file, parse_this_prosite_pattern, partner_nucleotide, partner_nucleotide_hash, pathways, pdb_directory?, percentage_count_non_DNA_bases_in_this_sequence, permanently_disable_opn, permutations, phred_error_probability, plain_palindrome, possible_codons_for_these_aminoacids, possible_codons_for_this_aminoacid, project_base_dir?, project_yaml_directory?, #pwd, pwd, quaternary_encoding_DNA_to_numbers, quaternary_encoding_letter_to_number, quaternary_encoding_number_to_letter, quaternary_encoding_numbers_to_DNA, quaternary_encoding_translate_from_alphabet_string_into_the_corresponding_DNA_sequence, random_aminoacid?, rds, readline_is_available?, regex_with_startcodons, remove_file, remove_invalid_aminoacids, remove_numbers, remove_subsequence, report_base_composition, require_all_aminoacids_files, require_all_calculate_files, require_all_cleave_and_digest_files, require_all_codon_files, require_all_count_files, require_all_dotplot_files, require_all_electron_microscopy_files, require_all_enzymes_files, require_all_fasta_and_fastq_files, require_all_nucleotides_files, require_all_palindromes_files, require_all_parser_files, require_all_pattern_files, require_all_pdb_files, require_all_sequence_files, require_all_string_matching_files, require_all_taxonomy_files, require_all_utility_scripts_files, require_the_toplevel_methods, restriction_enzyme, restriction_enzymes, restriction_enzymes?, restriction_enzymes_file, restriction_sites?, return_DNA_composition_hash, return_DNA_nucleotides, return_all_open_reading_frames_from_this_sequence, return_all_positions_of_this_nucleotide, return_all_substring_matches, return_aminoacid_sequence_from_this_pdb_file, return_aminoacid_sequence_from_this_string, return_array_from_tryptic_digest, return_array_of_common_aminoacids, return_array_of_sequence_matches, return_chunked_display, return_composition_from_this_aminoacid_sequence, return_consensus_sequence_of, return_current_day_month_year, return_current_hours_minutes_seconds, return_every_substring_from_this_sequence, return_fasta_entry_with_the_highest_gc_content, return_fasta_sequence_from_this_pdb_file, return_fasta_subsection_of_this_file, return_illumina_offset, return_long_aminoacid_name, return_longest_ORF_from_this_sequence, return_longest_substring_via_LCS_algorithm, return_n_ORFs_in_this_sequence, return_n_repeats, return_new_filename_based_on_fasta_identifier, return_nucleotide_sequence_as_ten_nucleotides_chunks, return_random_aminoacid_from_this_prosite_pattern, return_random_codon_sequence_for_this_aminoacid_sequence, return_random_nucleotide, return_restriction_enzyme_sequence_and_cut_position, return_sanger_offset, return_sequence_from_this_file, return_sequence_that_is_cut_via_restriction_enzyme, return_short_aminoacid_letter_from_long_aminoacid_name, return_sizeseq, return_solexa_offset, return_source_code_of_this_method, return_subsequence_based_on_indices, return_the_most_likely_codon_sequence_for_this_aminoacid_sequence, return_ubiquitin_sequence, rev, #rev, reverse_complement, reverse_sequence, rna_sequence, rna_splicing, rnalfold, ruler, ruler_return_as_string, ruler_return_as_string_without_colours, run_gtk_controller, run_sql_query, salt_adjusted_tm, sanitize_nucleotide_sequence, sanitize_this_fasta_file, scan_for_rgg_motifs, scan_this_input_for_startcodons, sdir, sequence?, sequence_based_on_these_restriction_enzymes, set_codon_table_in_use, set_default_colour, set_log_directory, set_pgpassword, set_start_codon, set_start_codons, set_stop_codons, set_use_this_codon_table, set_use_this_yaml_engine=, sfancy, sfile, shell, show_aminoacids_mass_table, show_atomic_composition, show_codon_tables, show_complementary_dna_strand, show_exon_statistics, show_fasta_header, show_fasta_statistics, show_n_glycosylation_motifs, show_restriction_enzymes, show_time_now, showorf, shuffleseq, simp, simplify_fasta_header, sizeseq, sort_aminoacid_based_on_its_hydrophobicity, start_codon?, start_codons?, start_sinatra_interface, stop_codons?, strict_filter_away_invalid_aminoacids, sum_of_odd_integers, swarn, taxonomy_directory?, taxonomy_download_directory?, taxonomy_ncbi_database_last_update_log_file, this_aminoacid_has_n_codons, this_nucleotide_pairs_with?, thousand_percentage, three_delimiter, three_to_one, to_aminoacids, to_camelcase, to_dna, to_rna, to_utf, trailing_three_prime, transitions_to_transversions_ratio, translate_all_three_frames, truncate?, try_to_pass_through_beautiful_url, try_to_rename_kde_konsole?, two_dimensional_plot, unique_two_paired_permutations, upcase_this_aminoacid_sequence_and_remove_numbers, upload_this_pdf_file, use_colours?, #use_colours_in_general?, use_opn?, use_this_codon_table, use_which_yaml_engine?, user_home_directory?, version?, weight_of_these_aminoacids?, weight_of_this_aminoacid?, wget_download, windows_platform?, write_what_into

Methods inherited from CommandlineApplication

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

Methods included from BaseModule

#absolute_path, #default_file_read, #file_readlines

Methods included from CommandlineArguments

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

Methods included from ColoursForBase

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

Methods inherited from Base

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

Methods included from InternalHashModule

#internal_hash?, #reset_the_internal_hash

Methods included from InferTheNamespaceModule

#infer_the_namespace, #namespace?

Constructor Details

#initialize(optional_commandline_arguments = nil, run_already = true) ⇒ Interactive

#

initialize

The first argument are the commandline arguments.

#


87
88
89
90
91
92
93
94
95
96
# File 'lib/bioroebe/taxonomy/interactive.rb', line 87

def initialize(
    optional_commandline_arguments = nil,
    run_already                    = true
  )
  reset
  set_commandline_arguments(
    optional_commandline_arguments
  )
  run if run_already
end

Class Method Details

.run(i = nil) ⇒ Object

#

Interactive.run

#


1436
1437
1438
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1436

def self.run(i = nil)
  Taxonomy::Interactive.new(i)
end

.run_interactive(i = nil) ⇒ Object

#

Taxonomy.run_interactive

#


1443
1444
1445
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1443

def self.run_interactive(i = nil)
  Interactive.run(i) # An alias to the above.
end

Instance Method Details

#add_comment(taxid) ⇒ Object

#

add_comment (comment tag)

Use this method to add a comment to the localome table.

#


1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1931

def add_comment(taxid)
  if has? taxid
    e 'Please input the comment you wish to add to the '+
      'Taxonomy ID '+simp(taxid.to_s)+' now:'
    add_this = $stdin.gets.chomp
    _ = "UPDATE fasta SET comment_field='"+add_this+"' WHERE taxid='"+taxid.to_s+"'"
    run_sql(_)
  else
    erev "We could not find any entry with the Taxonomy "\
         "ID #{taxid.to_s}."
  end
end

#be(i) ⇒ Object

#

be

#


1214
1215
1216
1217
1218
1219
1220
1221
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1214

def be(i)
  case i.to_sym
  when :verbose
    be_verbose
  when :silent
    be_silent
  end
end

#be_silentObject

#

be_silent

#


1150
1151
1152
1153
1154
1155
1156
1157
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1150

def be_silent
  if @be_verbose == false
    e 'We are already silent.'
  else
    @be_verbose = false
    e 'We will now be silent.'
  end
end

#be_verboseObject

#

be_verbose

#


1239
1240
1241
1242
1243
1244
1245
1246
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1239

def be_verbose
  if @be_verbose == true
    e 'We are already verbose.'
  else
    @be_verbose = true
    e 'We will now be verbose.'
  end
end

#be_verbose?Boolean

#

be_verbose?

#

Returns:

  • (Boolean)


1196
1197
1198
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1196

def be_verbose?
  @be_verbose
end

#check_commandline_argumentsObject

#

check_commandline_arguments

We check the commandline.

#


1764
1765
1766
1767
1768
1769
1770
1771
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1764

def check_commandline_arguments
  @commandline_arguments.each {|entry|
    case entry
    when :run_connected
      do_run_connected # This mode is for when we embed it in the BioroebeShell.
    end
  }
end

#create_and_save_table(i, be_verbose = false) ⇒ Object

#

create_and_save_table

#


143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/bioroebe/taxonomy/interactive.rb', line 143

def create_and_save_table(
    i, be_verbose = false
  )
  case i
  # ======================================================================= #
  # === :default_fasta
  # ======================================================================= #
  when :default_fasta
    i = FASTA_SQL
  end
  require 'roebe/sql_paradise/commands.rb'
  Roebe::SqlParadise::Commands.create_and_save_table(i, be_verbose)
end

#create_databaseObject

#

create_database

#


1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1892

def create_database
  case which_database_to_use?
  when 'sqlite'
    one   = 'CREATE TABLE names ( taxid int, name_txt varchar(155), unique_name varchar(100), name_class varchar(25) );'
    two   = 'CREATE TABLE nodes ( taxid int, parent_taxid int, rank varchar(25) );'
    three = 'CREATE TABLE fasta ( name varchar(80), taxid integer, type smallint, lineage_ids varchar(500), lineage_scientific_name varchar(2500), comment_field varchar(8000), filesize integer, modification_time varchar(25), n_accession_numbers integer, path varchar(120) );'
    e one
    e two
    e three
    _ = 'sqlite3 '+working_dir?+'names.db "'+one+'"'
    esystem _
    _ = 'sqlite3 '+working_dir?+'nodes.db "'+two+'"'
    esystem _
    _ = 'sqlite3 '+working_dir?+'fasta.db "'+three+'"'
    esystem _
    File.read(Taxonomy::Constants::NAMES_SQL).each_line {|line|
      line = line.chomp
      if line.include? '"'
        line.gsub!(/"/,'\"')
      end
      _ = 'sqlite3 '+working_dir?+'names.db "'+line+'"'
      Esystem.esystem _
    }
  else # default to postgresql for now.
  end
end

#create_default_directoriesObject

#

create_default_directories

#


702
703
704
705
706
707
708
709
710
711
712
713
714
# File 'lib/bioroebe/taxonomy/interactive.rb', line 702

def create_default_directories
  e 'Creating some directories now.'
  array_create_these_directores = %w(
    /data/ncbi/taxonomy/
    /tmp/robert/autogenerated_sql_files/
    /data/curated/sequences/localome/
    /data/curated/sequences/aa/
    /data/curated/sequences/nt/
    /data/curated/sequences/INFO/
    /data/curated/sequences/localome/incoming/
  ); pp array_create_these_directores
  mkdir(array)
end

#create_dirs(be_verbose = false) ⇒ Object

#

create_dirs

#


726
727
728
729
730
731
732
733
734
735
736
# File 'lib/bioroebe/taxonomy/interactive.rb', line 726

def create_dirs(be_verbose = false)
  case be_verbose
  when :be_verbose
    be_verbose = true
  end
  if be_verbose
    opnn; e 'We will create the temp directory and the download directory next.'
  end
  ensure_that_temp_dir_exists
  ensure_that_download_dir_exists
end

#create_fasta_tableObject

#

create_fasta_table

This method generates the fasta table into either postgresql or whatever else you stored things into.

#


128
129
130
131
132
133
134
135
136
137
138
# File 'lib/bioroebe/taxonomy/interactive.rb', line 128

def create_fasta_table
  remove(FASTA_SQL)
  # e 'Now storing into fasta.sql (Fasta-Format).'
  create_and_save_table(:default_fasta, true) # true for verbose
  cat FASTA_SQL # Also display it, after creation.
  # Next, drop the old Fasta table. But we must set the password before.
  e 'Trying to drop the fasta table next.'
  drop_table :fasta
  # And now, read in the new one.
  read_sql :fasta
end

#create_sql_file_from_local_fasta_entry(i) ⇒ Object

#

create_sql_file_from_local_fasta_entry

This method will create a .sql file, based on the information obtained from the local fasta entries.

The first argument to it should be an .INFO file, not a fasta file!

#


1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1557

def create_sql_file_from_local_fasta_entry(i)
  ensure_that_temp_dir_exists
  info = Info.new(i, :be_verbose => false)
  info.try_to_find_likely_fasta_file # Need to run it once so we can try to find the fasta file.
  if info.taxid
    obtain_full_lineage_for(info.taxid) # This will set @lineage_id
  else
    if be_verbose?
      e 'We did not find a Tax ID for `'+sfile(i)+'`.'
      e 'This is considered a fatal error for now - we will thus exit.'
    end
    exit
  end
  mkdir(AUTOGENERATED_SQL_FILES_DIR) unless Dir.exist?(AUTOGENERATED_SQL_FILES_DIR)
  sql_filename = AUTOGENERATED_SQL_FILES_DIR+
     File.basename(i).gsub(/#{File.extname(i)}/,'')+'.sql'        
  remove(sql_filename) if File.exist? sql_filename # Get rido f the old one first.
  # ======================================================================= #
  # Next, we will build up our SQL string:
  # ======================================================================= #
  string = ''.dup # This is the string that will be stored.
  # ======================================================================= #
  # (1) - the scientific name comes first
  # ======================================================================= #
  scientific_name = get_scientific_name(info.taxid).strip
  if scientific_name.empty? # Exit if we can not find it.
    if be_verbose?
      ewarn 'The scientific name for '+simp(info.taxid.to_s)+' was empty.'
      ewarn 'This we consider to be a runtime error for now, thus '+
            'we will exit.'
    end
    exit
  end
  string << pad_with_single_quotes(
    scientific_name
  )+', '
  fasta = ParseFasta.new(info.corresponding_datafile)
  # ======================================================================= #
  # (2) Next we need the Taxonomic ID, which is an integer.
  # ======================================================================= #
  string << info.taxid.to_s+', '
  # ======================================================================= #
  # (3) We now need to find out whether we have DNA or Protein.
  # ======================================================================= #
  type = fasta.type? # DNA or Protein.
  if type    == 'DNA'
    type = 0
  elsif type == 'Protein'
    type = 1
  end
  string << type.to_s+', '
  # ======================================================================= #
  # (4) Now comes the lineage_ids, of varchar(100)
  # ======================================================================= #
  string << pad_with_single_quotes(@lineage_ids)+', '
  # ======================================================================= #
  # (5) And the lineage_scientific_name
  # ======================================================================= #
  string << pad_with_single_quotes(@lineage_scientific_name)+', '
  # ======================================================================= #
  # Here be the accession_number varchar(200000)
  # Disabled as of Friday, needs more testing first. But is not even needed.
  # string << pad_with_single_quotes(
  #   fasta.all_accession_entries.join("\t|")
  # )+', '
  # string << pad_with_single_quotes(0)+', '
  # Dataset should come here
  # string << pad_with_single_quotes(0)+', '
  # (6) And the comment field will be here.
  # ======================================================================= #
  string << pad_with_single_quotes(0)+', '
  # ======================================================================= #
  # (7) filesize: the size of the file in question
  # ======================================================================= #
  string << fasta.filesize.to_s+', '
  # ======================================================================= #
  # (8) modification_time
  # ======================================================================= #
  string << pad_with_single_quotes(fasta.modification_time.to_s)+', '
  # ======================================================================= #
  # (9) n_accession_numbers
  # ======================================================================= #
  string << fasta.n_entries.to_s+', '
  # ======================================================================= #
  # (10) path - the filepath in question
  # ======================================================================= #
  string << pad_with_single_quotes(info.corresponding_datafile)
  # ======================================================================= #
  # Now we can insert into the postgresql Database.
  # ======================================================================= #
  string = InsertInto[
    'fasta',
    'name, taxid, type, lineage_ids, lineage_scientific_name, comment_field, filesize, modification_time, n_accession_numbers, path', # accession_number, dataset, 
     string
  ]
  e 'Now storing into '+sfile(sql_filename) if be_verbose?
  write_what_into(string, sql_filename)
  if be_verbose?
    e 'Next, we will attempt to read in this file into the '
      'Postgresql localome (fasta) table.'
  end
  cmd = POSTGRE_LOGIN_COMMAND+' -f '+sql_filename
  esystem(cmd)
  if be_verbose?
    e 'Done! All should have been well by now. '+
      'The Taxonomic ID was '+info.taxid
  end
end

#create_table(i) ⇒ Object

#

create_table

A wrapper over class CreateTable.

#


1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1838

def create_table(i)
  i = i.to_s
  case i
  when 'fasta'
    create_fasta_table
  else
    i << '.sql' # Append .sql in this case.
    result = ::SqlParadise::Commands.create_table(i)
    store_here = AUTOGENERATED_SQL_FILES_DIR+'create_table_'+i
    e 'Next creating a table for '+simp(i)+'. Will '+
      'store into '+sfile(store_here)
    save_what_into(result, store_here)
    e result
  end
end

#disable(i) ⇒ Object

#

disable (disable tag)

#


495
496
497
498
499
500
# File 'lib/bioroebe/taxonomy/interactive.rb', line 495

def disable(i)
  case i.to_sym
  when :colours
    disable_colours
  end
end

#disable_coloursObject

#

disable_colours

#


349
350
351
# File 'lib/bioroebe/taxonomy/interactive.rb', line 349

def disable_colours
  @use_colours = false
end

#do_run_connectedObject Also known as: run_connected

#

do_run_connected

#


688
689
690
# File 'lib/bioroebe/taxonomy/interactive.rb', line 688

def do_run_connected
  @run_standalone = false
end

#do_startup_actionsObject

#

do_startup_actions

#


1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1747

def do_startup_actions
  if be_verbose?
    e Colours.rev+'Welcome to interactive Taxonomy.'+N+N
    e 'We will show the help menu now (on startup).'+N+N
    show_help
    e 'Please input your command(s). ("help" for help, '+
      '"quit", "exit" or "q" to exit.)'
    nohelp if at_home? # At home I won't use this here.
  end
  check_commandline_arguments
end

#download(i = f?) ) ⇒ Object

#

download

This method can be used to download the ncbi database.

#


378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
# File 'lib/bioroebe/taxonomy/interactive.rb', line 378

def download(i = f?)
  i = i.to_s
  case i # case tag
  # ======================================================================= #
  # === --help
  # ======================================================================= #
  when 'HELP','?','--help'
    e 'Currently we can download only the NCBI database.'
    e
    e 'To do so, do:'
    e '  download ncbi'
  # ======================================================================= #
  # === download --ncbi
  # ======================================================================= #
  when /^-?-?ncbi/i,
       'database','1','' # '' is also a default here.
    download_ncbi_database
    if be_verbose?
      e
      e 'If all went well then you could now try to update the '+
        'database, by issuing:'
      e
      efancy '  update databases'
      e
    end
  else
    e 'In the method download(), we do not know the given '+
      'input `'+simp(i.to_s)+'`.'
  end
end

#download_ncbi_databaseObject

#

download_ncbi_database

#


1922
1923
1924
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1922

def download_ncbi_database
  Taxonomy.download_ncbi_database # bl $TAXONOMY/class_methods.rb
end

#drop_names_table(be_verbose = true) ⇒ Object

#

drop_names_table

#


427
428
429
# File 'lib/bioroebe/taxonomy/interactive.rb', line 427

def drop_names_table(be_verbose = true)
  run_sql POSTGRE_DROP_NAMES_COMMAND, be_verbose
end

#drop_nodes_and_names_database_tables(be_verbose = true) ⇒ Object

#

drop_nodes_and_names_database_tables

#


535
536
537
538
# File 'lib/bioroebe/taxonomy/interactive.rb', line 535

def drop_nodes_and_names_database_tables(be_verbose = true)
  drop_nodes_table(be_verbose)
  drop_names_table(be_verbose)
end

#drop_nodes_table(be_verbose = true) ⇒ Object

#

drop_nodes_table

#


420
421
422
# File 'lib/bioroebe/taxonomy/interactive.rb', line 420

def drop_nodes_table(be_verbose = true)
  run_sql POSTGRE_DROP_NODES_COMMAND, be_verbose
end

#drop_table(i = Bioroebe::Postgresql::DROP_FASTA_TABLE) ⇒ Object

#

drop_table (drop tag)

Use this method when you wish to drop a table.

#


1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1068

def drop_table(
    i = Bioroebe::Postgresql::DROP_FASTA_TABLE
  )
  case i.to_s
  when 'nodes'
  when 'fasta',
       'localomes',
       'localome'
    i = Bioroebe::Postgresql::DROP_FASTA_TABLE
  end
  ::Bioroebe.run_sql_query(i)
end

#enable(i) ⇒ Object

#

enable

#


1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1857

def enable(i)
  i = i.to_s
  if i.start_with? 'enable'
    i.gsub!(/^enable/,'')
  end
  i.strip!
  case i
  when 'colours'
    enable_colours
  end
end

#enable_coloursObject

#

enable_colours

#


1884
1885
1886
1887
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1884

def enable_colours
  @use_colours = true
  Taxonomy.enable_colours
end

#exit_programObject

#

exit_program

Use this method when exiting.

#


1811
1812
1813
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1811

def exit_program
  exit if run_standalone?
end

#fetch_user_input_via_loopObject

#

fetch_user_input_via_loop

#


1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1776

def fetch_user_input_via_loop
  loop {
    begin
      obtain_user_input # This sets the @user_input variable.
    rescue Interrupt
      if be_verbose?
        e 'Sigint occurred by user interrupt, exiting gracefully now.'
      end
      exit_program
    end
    if run_connected? 
      break if VALID_WAYS_TO_EXIT.include? @user_input
    end
  }
end

#finished(optional_extra_message = '') ⇒ Object

#

finished

Here we simply report to the user that we have finished.

#


1253
1254
1255
1256
1257
1258
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1253

def finished(optional_extra_message = '')
  unless optional_extra_message.empty?
    optional_extra_message << '.' unless optional_extra_message.end_with? '.'
  end
  e 'Done! '+optional_extra_message
end

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

#

first_argument?

#

Returns:

  • (Boolean)


1300
1301
1302
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1300

def first_argument?
  @first_argument
end

#generate(i) ⇒ Object Also known as: create

#

generate (generate tag)

This method can be used to generate nodes or names .sql files. These .sql files will be generated in the TEMP_DIR, which at the time of writing this documentation is at /tmp/robert.

#


287
288
289
290
291
292
293
294
# File 'lib/bioroebe/taxonomy/interactive.rb', line 287

def generate(i)
  i = i.to_s
  case i # case tag
  when 'nodes','names','nodes.sql','names.sql'
    i.gsub!(/\.sql/,'')
    menu(i) # Delegate towards the main menu here.
  end
end

#get(i, use_this_id = nil) ⇒ Object

#

get (get tag)

Get something from the localome table with this method.

#


190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/bioroebe/taxonomy/interactive.rb', line 190

def get(
    i,
    use_this_id = nil
  )
  i = i.to_s
  _ = "SELECT #{i} from fasta".dup
  _ << " where taxid='"+use_this_id.to_s+"';" if use_this_id
  if i.include? 'taxid' # Sort by taxid in this case.
    _ << ' ORDER BY taxid'
  end
  _ << ';'
  result = run_sql(_, :silent, :tuples)
  return result
end

#get_all_info_entries_with_tax_idObject

#

get_all_info_entries_with_tax_id

#


1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1108

def get_all_info_entries_with_tax_id
  result = []
  if be_verbose?
    e 'We will now attempt to find all .INFO files that do have a'
    e 'proper Taxonomy ID entry.'
  end
  Dir[INFO_DIR+'*.INFO'].each {|file|
    _ = Info.new(file, :be_verbose => false)
    if _.has_taxonomy_id?
      e sfile(file)+' has a Taxonomy ID.' if be_verbose?
      result << file
    end
  }
  return result
end

#get_user_inputObject Also known as: obtain_user_input

#

get_user_input

Get user input via this method. We prefer to use Readline if it is available, otherwise we will simply use a $stdin.gets() call.

#


1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1453

def get_user_input
  if Object.const_defined? :Readline
    _ = Readline.readline('', true)
    Readline::HISTORY.pop if _ =~ /^\s*$/
    @user_input = _
  else
    @user_input = $stdin.gets.chomp
  end
  sanitize_user_input
  process_user_input
  return @user_input
end

#has_id?(i) ⇒ Boolean Also known as: has?

#

has_id?

We ask the localome if an ID is registered. run_sql is defined in the file shared.rb

#

Returns:

  • (Boolean)


1266
1267
1268
1269
1270
1271
1272
1273
1274
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1266

def has_id?(i)
  i = i.to_s
  _ = "SELECT taxid from fasta where taxid='"+i+"'"
  if run_sql(_, false, :tuples).strip.empty?
    return false
  else
    return true
  end
end

#insert_into(i = :nodes) ⇒ Object

#

insert_into

#


1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1669

def insert_into(i = :nodes)
  i = i.to_s
  case i
  when 'fasta'
    create_fasta_table
  when 'nodes'
    populate_nodes_table(:be_verbose)
  when 'names'
    populate_names_table(:be_verbose)
  end
end

#load_from_info(i) ⇒ Object

#

load_from_info

This method shall attempt to load from an .NFO file, right into the localome/ directory at /data/curated/sequences/localome/incoming/.

#


1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1361

def load_from_info(i)
  e 'We will now attempt to load an .INFO file.'
  info = Info.new(i)
  info.report_id
  taxid = info.taxid?
  e 'We will try to load a fasta file, if it is nearby.'
  _ = info.fasta?
  e _
  ParseFasta.new(_).report
  if has_id? taxid # If we already have an entry like that, we refuse.
    e 'We already have an entry with the Taxonomic ID taxid '+taxid+'.'
    e 'You would have to remove it first before you can load a new one.'
    e '(Removing is as simple as: remove_id TAXONOMIC_ID_GOES_HERE)'
  else
    e 'No entry was yet found in the localome table, thus we will '+
      'attempt to add this dataset now.'
    create_sql_file_from_local_fasta_entry(i)
    e 'You can update the path in the Postgresql database via:'
    e '  set_path TAXONOMY_ID path_goes_here'
  end
end

#lupdate(i = :ncbi) ⇒ Object

#

lupdate (update tag)

This is the general way to update something. “update everything’ is the most important component - it will update everything, including the localomes entry.

#


453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
# File 'lib/bioroebe/taxonomy/interactive.rb', line 453

def lupdate(i = :ncbi)
  i = i.to_s # Use a String past this point.
  case i
  # ======================================================================= #
  # === localomes
  # ======================================================================= #
  when 'localomes',
       'local','loc','localome','2',
       'fasta',
       'database',
       'databases'
    update_local_localomes # This will overwrite the old dataset completely, be careful.
  # ======================================================================= #
  # === ncbi_database
  # ======================================================================= #
  when /^ncbi(-|_| )?database$/,
       'ncbi',
       '1',
       'update_ncbi'
    update_ncbi_database
  # ======================================================================= #
  # === lupdate all
  # ======================================================================= #
  when 'all',
       'everything',
       'both'
    update_ncbi_database
    update_local_localomes
    update_lineage
  # ======================================================================= #
  # === lineage
  # ======================================================================= #
  when 'lineage','lin','li'
    update_lineage
  else
    e 'Not sure what to update - the input was '+sfancy(i.to_s)
  end
end

#make_taxonomy_gemObject

#

make_taxonomy_gem

This is the code that creates the taxonomy .gem.

#


857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
# File 'lib/bioroebe/taxonomy/interactive.rb', line 857

def make_taxonomy_gem
  unless Dir[TAXONOMY_HOME_DIR+'*.gemspec'].empty? # Do we have a .gemspec file there?
    cd TAXONOMY_HOME_DIR
  end
  e
  e 'We will now attempt to build the taxonomy .gem (from '+
    'directory '+(Dir.pwd+'/').squeeze('/')+')'
  e
  if File.exist? 'taxonomy.gemspec'
    esystem 'gem build taxonomy.gemspec', :use_colours
    e
    e 'Done. There should now be a .gem file here.'
    location = Dir['*.gem']
    if location
      e 'We assume the full file path to be at:'
      e '  '+sfile(location.first)
      cp(location.first, TEMP_DIR)
      e 'All done - the .gem should be ready now.'
    end
  else
    e 'Could not find a file called taxonomy.gemspec, thus aborting now.'
  end
end
#

menu (menu tag)

The first argument to this method is the action we wish to check against the menu.

It constitutes the main menu interface of the Taxonomy project. The taxonomy commandline program calls this method here simply menu().

#


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
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
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
# File 'lib/bioroebe/taxonomy/menu.rb', line 34

def menu(
    instruction        = user_input?,
    optional_this_file = nil
  )
  i = instruction.to_s.chomp
  # ======================================================================= #
  # Next we make sure that the temp-dir and the download-dir will exist.
  # ======================================================================= #
  ensure_that_temp_dir_exists
  ensure_that_download_dir_exists
  record_last_command(i, first_argument?) # Record the last command.
  case i # (case tag)
  # ======================================================================= #
  # === update
  # ======================================================================= #
  when 'update',
       'lupdate',
       'upd'
    lupdate(f)
  # ======================================================================= #
  # === download
  # ======================================================================= #
  when 'download'
    download(f)
  # ======================================================================= #
  # === status?
  # ======================================================================= #
  when 'status?',
       'status',
       'stat',
       'stats',
       'data?',
       'try_to_display_the_status'
    try_to_display_the_status(f)
  # ======================================================================= #
  # === disable_colours
  # ======================================================================= #
  when 'disable_colours',
       'nocolours',
       'nocols',
       'nocolour',
       'nocol',
       'nocolorus'
    disable_colours
  # ======================================================================= #
  # === extract
  # ======================================================================= #
  when 'extract',
       'ext'
    extract(File.basename(URL_TO_TAXONOMY_ARCHIVE))
  # ======================================================================= #
  # === download_database
  # ======================================================================= #
  when /^download(_|-)?database$/i,'ncbi_down'
    download_ncbi_database
  # ======================================================================= #
  # === exit
  # ======================================================================= #
  when *VALID_WAYS_TO_EXIT
    exit_program
  # ======================================================================= #
  # === set_be_verbose
  # ======================================================================= #
  when /^set(-|_| )?be(-|_| )?verbose$/,
       'verbose',
       'be_verbose'
    @be_verbose = true
    e 'We will now be verbose.'
  # ======================================================================= #
  # === last?
  # ======================================================================= #
  when 'last?',
       'show_last_command'
    show_last_command
  # ======================================================================= #
  # === query_localome
  # ======================================================================= #
  when 'query_localome',
       'querylocalome',
       'qlocalome',
       'available?',
       'available',
       'query?',
       'localomes?',
       'loc?'
    query_localome_including_path
  # ======================================================================= #
  # === lineageid
  # ======================================================================= #
  when 'lineageid',
       'lineage_id',
       'lineage_ids',
       'lineageids', # Query the localome database directly.
       'show_lineage_from_localome_table',
       'slocalome'
    show_lineage_from_localome_table(f)
  # ======================================================================= #
  # === query
  # ======================================================================= #
  when 'query','qu'
    query(f)
  # ======================================================================= #
  # === name_path
  # ======================================================================= #
  when 'name_path',
       'namepath'
    e run_sql('select name,path from fasta;',false, :tuples)
  # ======================================================================= #
  # === sql
  # ======================================================================= #
  when 'sql',
      'seql'
    sql(f)
  # ======================================================================= #
  # === basedir?
  # ======================================================================= #
  when 'projectbasedir',
       'basedir?',
       'project_base_dir'
    e PROJECT_BASE_DIR
  # ======================================================================= #
  # === grep
  # ======================================================================= #
  when 'grep'
    esystem 'grep -r '+f.to_s+' '+MODULE_PATH+'*'
  # ======================================================================= #
  # === set_database
  # ======================================================================= #
  when 'set_database','setdatabase','database'
    set_database(f) # Set a new database
  # ======================================================================= #
  # === enable
  # ======================================================================= #
  when /^enable/
    enable(i) # Pass all enable instructions into the method.
  # ======================================================================= #
  # === password?
  # ======================================================================= #
  when 'password?',
       'password',
       'show_password',
       'spassword',
       'spass',
       'showpassword'
    show_password
  # ======================================================================= #
  # === show_sql_commands_only
  # ======================================================================= #
  when 'show_sql_commands_only',
       'showsqlcommandsonly',
       'show2'
    show_sql_commands_only
  # ======================================================================= #
  # === commands?
  # ======================================================================= #
  when 'commands?',
       'commands',
       'show_sql_commands',
       'sql?',
       'sqlinfo',
       'tables?',
       'stored?',
       'databases?',
       'database?',
       'sql_commands?'
    show_sql_commands
  # ======================================================================= #
  # === autogenerated_sql_files_dir
  # ======================================================================= #
  when 'AUTOGENERATED_SQL_FILES_DIR','autogenerated_sql_files_dir'
    e AUTOGENERATED_SQL_FILES_DIR
  # ======================================================================= #
  # === usewhichdatabase?
  # ======================================================================= #
  when 'use_which_database?',
       'which_database?',
       'd??',
       'datenbank?',
       'usewhichdatabase?',
       'usewhichdatabase',
       'whichdatabase?'
    e File.read(FILE_USE_THIS_DATABASE)
  # ======================================================================= #
  # === populatenodestable
  # ======================================================================= #
  when /^populate(_|-)?nodes(_|-)?table$/i,
       'nodestable',
       'nodes.sql'
    nodes_sql
  # ======================================================================= #
  # === populatenamestable
  # ======================================================================= #
  when 'populate_names_table','populatenamestable','namestable',
       'names.sql'
    names_sql
  # ======================================================================= #
  # === create_database
  # ======================================================================= #
  when /^create(_|-)?database/,
       'cdata'
    create_database
  # ======================================================================= #
  # === generatesql
  # ======================================================================= #
  when 'make_sql',
       'makesql',
       'msql',
       'do_sql',
       'dosql',
       'generatesql'
    nodes_sql
    names_sql
  # ======================================================================= #
  # === config?
  # ======================================================================= #
  when 'config?'
    show_configuration
  # ======================================================================= #
  # === dirs?
  # ======================================================================= #
  when 'dirs?','feedback','d?','dir?','home?'
    show_important_directories # Defined in this file here.
  # ======================================================================= #
  # === last_update
  # ======================================================================= #
  when 'last_update',
       'last_update?',
       'lup',
       'lup?',
       'lupd',
       'lupdate?',
       'lastupdate',
       'lupd?',
       'lastupdate?',
       'lastupdated?',
       'last_upd?'
    try_to_show_when_the_last_update_has_happened
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when 'create_fasta_table',
       'ftable',
       'fff',
       'cfasta',
       'createfastatable'
    create_fasta_table
  # ======================================================================= #
  # === names
  # ======================================================================= #
  when 'names',
       'nodes',
       'fasta2',
       'names_db',
       'nodes_db',
       'fasta_db'
    # ===================================================================== #
    # We default to the directory SHARED_HOME, unless the user did
    # input any other arg.
    # ===================================================================== #
    cd SHARED_HOME unless f
    i = i.gsub(/_db/,'') # Get rid of possible _db entries.
    this_file = i+'.sql'
    remove(i+'.sql', true) if File.exist? this_file
    if be_verbose?
      e 'In '+sdir(Dir.pwd+'/')+', we will now generate the '+
        sfile(this_file)+' file anew. This may take'
      e 'a while, please be patient.'
    end
    create_and_save_table(i)
    # ===================================================================== #
    # Next, fill in that .sql file with INSERT INTO statements.
    # ===================================================================== #
    populate(i, false, this_file) # in file commands.rb
    finished 'Generated '+i.to_s+'.' if File.exist? this_file
  # ======================================================================= #
  # === cat
  # ======================================================================= #
  when 'cat'
    cat(f)
  # ======================================================================= #
  # === cd
  # ======================================================================= #
  when 'cd'
    cd(f, :be_verbose)
  # ======================================================================= #
  # === colours?
  # ======================================================================= #
  when 'colours?'
    e 'Will we use colours: '+@use_colours.to_s
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when 'BASE?','base'
    cd working_directory?
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when 'url?'
    e NCBI_URL
  # ======================================================================= #
  # === date
  # ======================================================================= #
  when 'date',
       'time',
       'date?',
       'time?',
       'show_current_time_and_date'
    show_current_time_and_date
  # ======================================================================= #
  # === populate
  # ======================================================================= #
  when 'populate',
       'pop',
       'loadup', # This will loadup dataset from a fasta file into the fasta table.
       'create_sql_file_from_local_fasta_entry'
    create_sql_file_from_local_fasta_entry(f)
  # ======================================================================= #
  # === create?
  # ======================================================================= #
  when 'create?'
    e 'We can create:'
    e '  names'
    e '  nodes'
  # ======================================================================= #
  # === ctable
  # ======================================================================= #
  when 'create_table','ctable','createtable','create'
    create_table(first_argument?)
  # ======================================================================= #
  # === create_dirs
  # ======================================================================= #
  when 'create_dirs','cdirs'
    create_dirs(:be_verbose)
  # ======================================================================= #
  # === verify
  # ======================================================================= #
  when 'verify?','verify','ver','v','debug','debug?'
    verify_proper_sql_structures
  # ======================================================================= #
  # === show_help
  # ======================================================================= #
  when 'help','hlep',
       'subhelp',
       'shelp',
       'helps',
       '?',
       'hlp',
       '--help',
       '-help'
    show_help
  # ======================================================================= #
  # === instructions?
  # ======================================================================= #
  when 'instructions?','instruction','ins','ins?',
       'inst?','instruction?'
    try_to_show_instructions
  # ======================================================================= #
  # === test
  # ======================================================================= #
  when 'test','batch','batch_process','batch_read_info_files',
       'batch?','batchprocess'
    ParseFasta.batch_process # Run them all.
  # ======================================================================= #
  # === parentid
  # ======================================================================= #
  when 'parent_id','pid','parentid','pid?','parentof',
       'get_parent_id_of','parent'
    e 'The parent id of Tax ID '+sfancy(f)+' is: '+simp(
         get_parent_id_of(f)
       )
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when 'get_scientific_name_of','getscientificnameof', # Obtain the scientific name here.
       'science','sciname','sci','sciid','scif',
       'show_scientific_name_of','scientific_name_of',
       'name_of',
       'scientific_name',
       'scientificname'
    show_scientific_name_of(f)
  # ======================================================================= #
  # === insert_into
  # ======================================================================= #
  when 'insert_into','insertinto','iinto'
    insert_into(f)
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when 'postgres_size?','show_postgres_size','showpostgressize',
       'showsize','size?','table_size?','tablesize?'
    show_postgres_size
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when 'fasta_table?','fastatable?'
    result = run_sql(
      'select * from fasta limit 0;',
    false).strip.gsub(/\(0 rows\)/,'')
    e 'The fasta table has these entries: '+N+'   '+result
  # ======================================================================= #
  # === search_by_name
  # ======================================================================= #
  when 'search_by_name','search_in_database_for_name','sname',
       'search','name','searchfor','sfor','search_for'
    result = search_in_database_for_name(f).strip.split(N)
    result.each {|entry|
      entry = entry.split('|'); e entry[0]+' '+entry[1]
    }
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when 'find_highest',
       'latest','current','akt'
    find_highest_entries_in_sql
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when 'fullhelp','fhelp'
    begin
      require 'case_parser'
      CaseParser.parse(__FILE__).each {|entry|
        e "  - #{entry}"
      }
    rescue LoadError
    end
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when 'enable_colours','enablecolours','yescolours',
       'ecolours'
    enable_colours
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when 'be'
    be(f)
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when 'dropper'
    drop_nodes_and_names_database_tables
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when 'read_in_names_and_nodes_sql_files','readinnamesandnodessqlfiles'
    read_in_names_and_nodes_sql_files
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when 'verbose?'
    e be_verbose?.to_s
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when 'open','open_project_files'
    open_project_files
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when 'set_path','setpath','spath','path','update_path'
    set_path(f)
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when 'info?','i?','info','info2','inf','nfo',
       'parse_info','parseinfo','pinfo'
    if f # If given a single .INFO file, continue here.
      cliner {
        _ = Info.new(f)
        _.show_info(false) # false so we don't use cliner.
        _.show_likely_fasta_file_if_it_can_be_found
        if _.location.include? 'incoming/'
          e 'We found the string incoming/ as being part of the location of the .INFO file.'
          e '(The full location is: '+sfile(_.location?)+')'
          e 'We thus assume that you wish to automatically load this dataset into '
          e 'the localome table, and we will do so now.'
          create_sql_file_from_local_fasta_entry(f)
        end
      }
    else
      cliner {
        report_how_many_info_files_exist_and_how_many_lack_taxonomy_id
      }
    end
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when 'obtain_full_lineage_for','obtainfulllineagefor'
    pp obtain_full_lineage_for(f)
    e 'This has also built the two lineage IDs:'+N+N
    efancy '  '+@lineage_ids.to_s
    efancy '  '+@lineage_scientific_name.to_s
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when 'search_in_localomes','searchinlocalomes','sin',
       'searchlocalomes','slocal','slocalomes'
    search_in_localomes(f)
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when 'query_localomes_by_modtime','mod_time','modtime',
       'modtime?'
    query_localomes_by_modtime
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when 'get_all_info_entries_with_tax_id','getallinfoentrieswithtaxid',
       'ginfo','get_all_info_entries_with_taxid'
    get_all_info_entries_with_tax_id
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when 'fasta?','table?'
    e 'We use these values for the fasta table:'
    e '  '+FASTA_ENTRIES
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when 'type','types','type?','types?',
       'show_type_of_all_info_files','showtypeofallinfofiles'
    show_type_of_all_info_files(f)
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when 'name,taxid','names,taxid'
    run_sql 'select name,taxid from fasta ORDER BY taxid;'
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when 'get_id','id','id?','getid','idof?','gid','getidof',
       'get_id_of','showid'
    get_id_of(f)
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when 'edit','edit_login'
    edit(f)
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when 'lineage','get_lineage','getlineage','get_parent_ids',
       'getparentids','gpids','pids','pids_of','pidsof',
       'allids','linage'
    return_full_lineage_of(f)
    report_lineage_of(f)
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when 'login?','login_information?','linfo?','login',
       'show_login_information','showlogininformation'
    
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when 'nodes?','show_nodes_table','shownodestable'
    show_nodes_table
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when 'store_where?','storewhere?'
    e 'We will store at '+sdir(TEMP_DIR)
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when 'generate'
    generate(f)
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when 'remove','remove_taxid_from_localome_table',
       'remove_id'
    remove_taxid_from_localome_table(f)
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when 'drop_table','droptable','drop','dropt'
    drop_table(f)
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when 'disable'
    disable(f)
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when 'where','where?'
    e TAXONOMY_DIR+'names.dmp'
    e TAXONOMY_DIR+'nodes.dmp'
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when 'taxtree','taxtree?','tree','treetax','tax_tree'
    taxtree(f)
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when 'query_whether_we_have_this_id','has_id?','hasid','hasid?'
    query_whether_we_have_this_id(f)
  # ======================================================================= #
  # === update_lineage
  # ======================================================================= #
  when 'update_lineage','updatelineage','ulineage'
    update_lineage # Only update the lineage, nothing else.
  # ======================================================================= #
  # === ll
  # ======================================================================= #
  when 'll','LL','l',
       'lll',
       'show_directory_content',
       'directory_paradise'
    show_directory_content
  # ======================================================================= #
  # === load_from_info
  # ======================================================================= #
  when 'load_from_info','linfo','loadinfo'
    load_from_info(f)
  # ======================================================================= #
  # === lafo
  # ======================================================================= #
  when 'lafo','loadup_localomes','loaduplocalomes','goloc',
       'localomes_go','localomesgo','golocal','goloco',
       'localgo',
       'update_local_localomes',
       'update2',
       'default'
    update_local_localomes
  # ======================================================================= #
  # === show_all_eukarya
  # ======================================================================= #
  when 'show_all_eukarya','eukarya?','eukarya','eucarya?','eucarya',
       'eukaryota','seu','euk'
    show_all_eukarya(f)
  # ======================================================================= #
  # === repeat_last
  # ======================================================================= #
  when 'repeat_last','last_command','lastcommand','last' # We will repeat the last command here.
    repeat_last_command
  # ======================================================================= #
  # === deepfasta
  # ======================================================================= #
  when 'deepfasta' # The difference here is that we will also report the sequence.
    _ = Taxonomy::ParseFasta.new(f)
    e 'The (at least one) sequence is: '+sfancy(_.sequence.first)
    e 'The status for '+sfile(_.location)+' is as follows:'
    _.report_status
    pp _.hash
  # ======================================================================= #
  # === isdna
  # ======================================================================= #
  when 'isdna','is_dna','isdna?'
    Taxonomy::IsDNA.new(f).report
  # ======================================================================= #
  # === nohelp
  # ======================================================================= #
  when 'nohelp','nhelp','nh','silence'
    nohelp
  # ======================================================================= #
  # === silent
  # ======================================================================= #
  when 'silent','be_silent','besilent'
    be_silent
    nohelp
  # ======================================================================= #
  # === taxid
  # ======================================================================= #
  when 'taxid','t','taxid?','tid'
    get_id_of(f)
    e 'http://www.ncbi.nlm.nih.gov/taxonomy/?term='+f.to_s
  # ======================================================================= #
  # === silently_update_ncbi_database
  # ======================================================================= #
  when 'silently_update_ncbi_database'
    silently_update_ncbi_database
  # ======================================================================= #
  # === n_info?
  # ======================================================================= #
  when 'n_info?','ninfo'
    report_how_many_info_files_exist_and_how_many_lack_taxonomy_id
  # ======================================================================= #
  # === taxid,name,path
  # ======================================================================= #
  when 'taxid,name,path'
    run_sql 'SELECT taxid,name,path from fasta ORDER BY taxid;'
  # ======================================================================= #
  # === name,path,taxid
  # ======================================================================= #
  when 'name,path,taxid'
    run_sql 'SELECT name,path,taxid from fasta ORDER BY taxid;'
  # ======================================================================= #
  # === taxid,name,path,filesize
  # ======================================================================= #
  when 'taxid,name,path,filesize'
    run_sql 'SELECT taxid,name,path,filesize from fasta ORDER BY taxid;'
  # ======================================================================= #
  # === dependencies?
  # ======================================================================= #
  when 'dependencies?','deps?','dep?'
    try_to_show_dependencies
  # ======================================================================= #
  # === taxid,path
  # ======================================================================= #
  when 'taxid,path'
    run_sql 'SELECT taxid,path from fasta ORDER BY taxid;'
  # ======================================================================= #
  # === name,path
  # ======================================================================= #
  when 'name,path'
    run_sql 'SELECT name,path from fasta ORDER BY name;'
  # ======================================================================= #
  # === name,taxid,path
  # ======================================================================= #
  when 'name,taxid,path'
    run_sql 'SELECT name,taxid,path from fasta ORDER BY taxid;'
  # ======================================================================= #
  # === taxid,name
  # ======================================================================= #
  when 'taxid,name'
    run_sql 'SELECT taxid,name from fasta ORDER BY taxid;'
  # ======================================================================= #
  # === edit_instructions
  # ======================================================================= #
  when 'edit_instructions'
    edit_instructions
  # ======================================================================= #
  # === make_taxonomy_gem
  # ======================================================================= #
  when 'make_taxonomy_gem','make_gem','gem','makegem',
       'make','gemmer'
    make_taxonomy_gem
  # ======================================================================= #
  # === check_available
  # ======================================================================= #
  when 'check_available','checkavailable','cavail',
       'cavailable','cava'
    Taxonomy::CheckAvailable.new
  # ======================================================================= #
  # === www?
  # ======================================================================= #
  when 'www?','www','cgi?','cgi'
    e 'http://localomics.imp.univie.ac.at:8666/'
  # ======================================================================= #
  # === sdc
  # ======================================================================= #
  when 'sdc'
    begin
      require 'show_directory_content'
      ShowDirectoryContent.new
    rescue; end # Silent error here.
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when 'all_info_files','all_info','allinfo','fa?'
    pp Dir[AA_DIR+'*.fa']
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when 'localome?'
    localome?
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when 'add_comment','comment','addcomment'
    add_comment(f)
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when 'comments?'
    menu 'taxid,comment_field'
  # ======================================================================= #
  # === update_database
  # ======================================================================= #
  when 'update_database','ud','updatedatabases','update_databases',
       'update_ncbi_database',
       'updatencbidatabase','update_ncbi',
       'main' # This is the main action (main tag).
    update_ncbi_database
  # ======================================================================= #
  # === finished
  # ======================================================================= #
  when 'finished'
    finished
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when '',nil
    show_short_help
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when 'ftp','start_ftp'
    begin
      require 'ftp_paradise'
      FtpParadise::InteractiveFtp.new
    rescue LoadError
      e 'ftp is not available, it would depend on the ftp_paradise gem.'
    end
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when 'prokarya?','prokarya','procarya?','procarya',
       'show_all_prokarya','spu'
    show_all_prokarya 
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when 'parse','parse_fasta','parsefasta','par','pa','paste',
       'papa','pp','fasta','fas','-','pfasta'
    _ = ParseFasta.new(f)
    _.report_one_sequence
    e 'The status for '+sfile(_.location)+' is as follows:'
    _.report_status
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when 'port?','port','show_port','showport','sport?','sport',
       '--port','-port','p?'
    show_port
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when 'show_changelog','changes?','showchangelog','changelog?'
    show_changelog
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when 'shared_code?','sharedcode?','show_shared_code_location',
       'showsharedcodelocation','sshared','scode?'
    show_shared_code_location
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when 'pwd','pwd?'
    e sdir(  ( Dir.pwd+'/' ).squeeze('/') )
  # ======================================================================= #
  # === edit_gemspec
  # ======================================================================= #
  when 'edit_gemspec','gemspec','gemspec?','gspec'
    edit_gemspec
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when 'show_table_names','table_names?','tablenames','tnames',
       'table_names','tablenames?','tnames?','1'
    show_table_names
  # ======================================================================= #
  # === 
  # ======================================================================= #
  when 'paths?'
    menu 'taxid,name,path'
  # ======================================================================= #
  # === create_default_directories
  # ======================================================================= #
  when 'create_default_directories','cdd','simulate'
    create_default_directories
  else # else tag
    if i.include? '.INFO'
      menu 'parse_info',i
    elsif i.include? '.fa' # Delegate to parsing a fasta file here.
      menu 'parse_fasta',i
    elsif i.include? AA_DIR
      menu 'parse_fasta',i
    elsif i.include?(',') # General pass through (an assumption however).
      query_from_localome_table(i)
    elsif ::Rcfiles::DirectoryAliases.does_include?(i)
      e sdir(rds(Dir.pwd+'/'))
    else
      e 'In the method menu(), file '+__FILE__.to_s+':'
      e 'We did not find the input: `'+sfancy(i.to_s)+'`'
    end
  end # end tag
end

#names_sqlObject

#

names_sql

#


1698
1699
1700
1701
1702
1703
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1698

def names_sql
  store_here = AUTOGENERATED_SQL_FILES_DIR+'names.sql'
  File.delete(store_here) if File.exist? store_here
  e 'We will populate the names-table next. This will take a while.'
  populate_names_table :be_verbose, store_here
end

#nodes_sqlObject

#

nodes_sql

Use this method to generate the nodes.sql file.

#


1710
1711
1712
1713
1714
1715
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1710

def nodes_sql
  store_here = AUTOGENERATED_SQL_FILES_DIR+'nodes.sql'
  File.delete(store_here) if File.exist? store_here
  e 'We will populate the nodes-table next. This will take a while.'
  populate_nodes_table :be_verbose, store_here
end

#nohelpObject

#

nohelp

#


1000
1001
1002
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1000

def nohelp
  @no_help = true
end

#obtain_full_lineage_for(f) ⇒ Object Also known as: get_lineage_ids_and_lineage_scientific_name

#

obtain_full_lineage_for

The input to this method should be an existing TaxID.

#


1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1040

def obtain_full_lineage_for(f)
  result = return_full_lineage_of(f) # in taxonomy.rb
  if result
    @lineage_ids = ''.dup
    @lineage_scientific_name = ''.dup
    hash = Hash[result]
    hash.each {|taxid, scientific_name|
      @lineage_ids << taxid.to_s+' -> '
      @lineage_scientific_name << scientific_name.chomp+' (Tax id: '+taxid.to_s+'), '
    }
    @lineage_scientific_name = @lineage_scientific_name.strip
    # Next, get rid of trailing , characters.
    @lineage_scientific_name.chop! if @lineage_scientific_name.end_with? ','
    @lineage_ids.strip!
    if @lineage_ids.end_with? '->'
      @lineage_ids[-2,2] = ''.dup
      @lineage_ids.strip!
    end
    @lineage_scientific_name.chomp!
  end
  return result
end

#open_project_filesObject

#

open_project_files (open tag)

This method will open the various project files in the editor.

#


678
679
680
681
682
683
# File 'lib/bioroebe/taxonomy/interactive.rb', line 678

def open_project_files
  ARRAY_PROJECT_FILES.each {|entry|
    _ = (editor?+' '+PROJECT_BASE_DIR+'lib/taxonomy/'+entry.to_s).squeeze '/'
    esystem _
  }
end

#process_user_input(i = @user_input) ⇒ Object

#

process_user_input

#


1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1482

def process_user_input(i = @user_input)
  if i.is_a? Array
    i.each {|entry| process_user_input(entry) }
  else # We assume it is a String here.
    if i.include? ';'
      process_user_input(i.split(';'))
    else
      check_against_menu(@cmd, @first_argument)
    end
  end
end

#query(i) ⇒ Object

#

query

Formulate a query against the database.

#


1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1094

def query(i)
  case i.to_s
  when 'localome','extended','main'
    query_localome_including_path
  when 'modtime'
    query_localomes_by_modtime
  when 'ncbi'
    e 'https://www.ncbi.nlm.nih.gov/taxonomy'
  end
end

#query_from_localome_table(i) ⇒ Object

#

query_from_localome_table

This will display the result as well.

#


342
343
344
# File 'lib/bioroebe/taxonomy/interactive.rb', line 342

def query_from_localome_table(i)
  e get(i)
end

#query_localomeObject

#

query_localome

Query the localome table.

#


545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
# File 'lib/bioroebe/taxonomy/interactive.rb', line 545

def query_localome
  e 'These organisms are available locally:'
  result = run_query(
    'select name,taxid from fasta ORDER BY taxid;',
  false, :tuples)
  splitted = result.split(N)
  splitted.each_with_index {|entry, index|
    index += 1
    inner_splitted = entry.split('|')
    name = inner_splitted[0].strip.ljust(30)
    e ' ('+index.to_s+') '+name+' -> TaxID: '+
      simp(inner_splitted[1].strip)
  }
  report_n_registered_organisms_in_localome(splitted.size)
end

#query_localome_including_pathObject Also known as: localome?

#

query_localome_including_path

We also show the path here.

#


507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
# File 'lib/bioroebe/taxonomy/interactive.rb', line 507

def query_localome_including_path
  e 'These organisms are available locally:'
  result = run_query(
    'select name,taxid,path from fasta ORDER BY taxid;',
    false, :tuples)
  splitted = result.split(N)
  splitted.each_with_index {|entry, index|
    index += 1
    inner_splitted = entry.split('|')
    name = inner_splitted[0].strip.ljust(40)
    path = 'the local path is at '+N+'       '+sfancy(inner_splitted[2])
    e ' ('+index.to_s+') '+name+' -> TaxID: '+
      simp(inner_splitted[1].strip)+', '+path
  }
  report_n_registered_organisms_in_localome(splitted.size)
end

#query_localomes_by_modtimeObject

#

query_localomes_by_modtime

#


1084
1085
1086
1087
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1084

def query_localomes_by_modtime
  _ = 'SELECT name,modification_time FROM fasta ORDER BY modification_time;'
  run_sql_query _
end

#query_whether_we_have_this_id(i) ⇒ Object

#

query_whether_we_have_this_id(i)

We query whether we have a specific ID or whether we don’t.

#


365
366
367
368
369
370
371
# File 'lib/bioroebe/taxonomy/interactive.rb', line 365

def query_whether_we_have_this_id(i)
  if has_id? i
    e 'We do have the id '+simp(i.to_s)+'.'
  else
    e 'We do not have the id '+simp(i.to_s)+'.'
  end
end

#rds(i) ⇒ Object

#

rds

#


910
911
912
# File 'lib/bioroebe/taxonomy/menu.rb', line 910

def rds(i)
  i.squeeze('/')
end

#read_in_names_and_nodes_sql_files(be_verbose = true) ⇒ Object

#

read_in_names_and_nodes_sql_files

We use two commands for populating names.sql and nodes.sql tables.

#


1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1129

def read_in_names_and_nodes_sql_files(be_verbose = true)
  be_verbose = false if be_verbose == :be_silent

  if at_home? # We use another command at home.
    cmd = POSTGRE_LOGIN_COMMAND_HOME
  else
    cmd = POSTGRE_LOGIN_COMMAND
  end

  if be_verbose
    esystem cmd+' -f '+SHARED_HOME+'names.sql'
    esystem cmd+' -f '+SHARED_HOME+'nodes.sql'
  else # Else just use system.
    system cmd+' -f '+SHARED_HOME+'names.sql'
    system cmd+' -f '+SHARED_HOME+'nodes.sql'
  end
end

#read_sql(i = :fasta) ⇒ Object

#

read_sql

Read in sql into the Postgre Database.

#


640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
# File 'lib/bioroebe/taxonomy/interactive.rb', line 640

def read_sql(i = :fasta)
  set_pgpassword
  case i
  # ======================================================================= #
  # === :fasta
  # ======================================================================= #
  when :fasta
    if at_home? # On my home system.
      cmd = POSTGRE_LOGIN_COMMAND_HOME
    else
      cmd = POSTGRE_LOGIN_COMMAND
    end
    cmd << ' -f '+FASTA_SQL
    e 'Next, we will read in from '+FASTA_SQL if be_verbose?
    esystem cmd
    e 'Done reading in the dataset!' if be_verbose?
  end
end

#record_last_command(consider_storing_this = '', optional = '') ⇒ Object

#

record_last_command

Use this method to record the last command issued.

The constant LAST_INTERACTIVE_COMMAND determines where we store this.

#


1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1166

def record_last_command(
    consider_storing_this = '',
    optional              = ''
  )
  what = consider_storing_this.to_s.dup # Work on a copy from this point onwards.
  what << '|'+optional.to_s unless optional.to_s.empty?
  unless what.empty?
    # ===================================================================== #
    # Before we can store into the file, we need to ensure that the
    # TEMP_DIR exists. We ensure this with the next check - if it
    # does not exist then we will create it.
    # ===================================================================== #
    unless Dir.exist? TEMP_DIR
      e 'We will now create the directory '+sdir(TEMP_DIR)+'.'
      ensure_that_temp_dir_exists
    end
    begin
      write_what_into(what, LAST_INTERACTIVE_COMMAND)
    rescue Exception => error
      e "A small error has happened in the method: "\
        "#{__method__}()"
      p error
      e "Could not write into `#{sfile(into)}`."
    end
  end unless what.include? 'last?' # Exception for "last?".
end

#remove_taxid_from_localome_table(i) ⇒ Object

#

remove_taxid_from_localome_table

This method will remove a TaxID from the localome table.

#


248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'lib/bioroebe/taxonomy/interactive.rb', line 248

def remove_taxid_from_localome_table(i)
  i = i.to_s
  if has_id? i
    # Ok we found an entry, thus we can remove it now:
    run_sql "
      DELETE FROM fasta
      WHERE taxid='"+i+"';
    "
    if be_verbose?
      e 'Removed entry '+simp(i)+
        ' (Taxonomy ID) from the localome (fasta) table.'
    end
  else
    e "Could not find TaxID #{simp(i)}." if be_verbose?
  end
end

#repeat_last_commandObject

#

repeat_last_command

#


1203
1204
1205
1206
1207
1208
1209
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1203

def repeat_last_command
  if File.exist? LAST_INTERACTIVE_COMMAND
    show_last_command
  else
    e 'No file at '+sfile(LAST_INTERACTIVE_COMMAND)+' could be found.'
  end
end

#report_how_long_it_took_us(i = 0, title_of_table = 'NCBI-based taxonomy table') ⇒ Object

#

report_how_long_it_took_us

The input to this method should be the number of seconds, i.e. 60 seconds.

#


623
624
625
626
627
628
629
630
631
632
633
# File 'lib/bioroebe/taxonomy/interactive.rb', line 623

def report_how_long_it_took_us(
    i = 0,
    title_of_table = 'NCBI-based taxonomy table'
  )
  n_minutes = (i.to_f / 60.0).to_s
  if n_minutes.size > 4
    n_minutes = n_minutes[0,4]
  end
  e 'Updating the '+title_of_table+' took us '+
    sfancy(i.to_s)+' seconds (= '+n_minutes.to_s+' minutes).'
end

#report_how_many_info_files_exist_and_how_many_lack_taxonomy_idObject

#

report_how_many_info_files_exist_and_how_many_lack_taxonomy_id

This will check on at least one directory.

#


1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1333

def report_how_many_info_files_exist_and_how_many_lack_taxonomy_id
  _ = get_all_info_entries_with_tax_id
  e 'We will try to assess the various .INFO files from the '+
    sdir(info_dir?)+'.'
  n_info_files = Dir[INFO_DIR+'*.INFO'].size
  if n_info_files > 0
    e 'We did find '+sfancy(_.size)+' .INFO files with Taxonomy ID. '+
      'That means that '+sfancy( Dir[INFO_DIR+'*.INFO'].size - _.size )+
      ' .INFO files do not have '
    e 'a Taxonomy ID. In total there are '+sfancy(n_info_files.to_s)+
      ' .INFO files there.'
    info_files_in_incoming_dir = Dir[INCOMING_DIR+'*.INFO']
    if info_files_in_incoming_dir.size > 0
      e 'We also found at least one .INFO file in '+sdir(INCOMING_DIR)+'.'
      e 'We will display them now:'
      pp info_files_in_incoming_dir
    end
  else
    e 'We found no .INFO file there.'
  end
end

#report_lineage_ids_and_lineage_scientific_name(i) ⇒ Object

#

report_lineage_ids_and_lineage_scientific_name

#


412
413
414
415
# File 'lib/bioroebe/taxonomy/interactive.rb', line 412

def report_lineage_ids_and_lineage_scientific_name(i)
  e 'The lineage of all parent ids for Tax ID '+sfancy(i)+' is: '+
  @lineage_ids+', and in long form '+@lineage_scientific_name
end

#report_lineage_of(f) ⇒ Object

#

report_lineage_of

#


610
611
612
613
614
615
# File 'lib/bioroebe/taxonomy/interactive.rb', line 610

def report_lineage_of(f)
  obtain_full_lineage_for(f)
  report_lineage_ids_and_lineage_scientific_name(f)
  e
  generate_html_links_for( @lineage_ids.split(' -> ') )
end

#report_n_registered_organisms_in_localome(i) ⇒ Object

#

report_n_registered_organisms_in_localome

#


527
528
529
530
# File 'lib/bioroebe/taxonomy/interactive.rb', line 527

def report_n_registered_organisms_in_localome(i)
  e 'We have a total of '+sfancy(i.to_s)+' organisms '+
    'registered in the localome (== fasta) table.'
end

#report_total_amount_of_proteomes(i) ⇒ Object

#

report_total_amount_of_proteomes

The input should be an array of Taxonomy IDs.

#


921
922
923
924
925
926
927
928
929
930
931
932
# File 'lib/bioroebe/taxonomy/interactive.rb', line 921

def report_total_amount_of_proteomes(i)
  if i.is_a? Array
    n_entries = 0
    i.each {|entry|
      n_entries += run_query("select n_accession_numbers from fasta WHERE taxid='"+entry+"';",
          false,
          :tuples).strip.to_i
    }
    e 'We have found a total of '+sfancy(n_entries.to_s)+' accession '+
      'numbers from the above dataset.'
  end
end

#report_tree_lineage(i) ⇒ Object

#

report_tree_lineage

This method expects an Array as input, which contains all the IDs that we will report in a tree (hence the name tree here).

#


236
237
238
239
240
241
# File 'lib/bioroebe/taxonomy/interactive.rb', line 236

def report_tree_lineage(i)
  i.each_with_index {|entry, index|
    padding = ' ' * (index+1)
    e padding+entry.to_s
  }
end

#resetObject

#

reset

#


101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/bioroebe/taxonomy/interactive.rb', line 101

def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === @be_verbose
  # ======================================================================= #
  @be_verbose     = BE_VERBOSE
  # ======================================================================= #
  # === @use_colours
  # ======================================================================= #
  @use_colours    = USE_COLOURS
  # ======================================================================= #
  # === @no_help
  # ======================================================================= #
  @no_help        = false
  # ======================================================================= #
  # === @run_standalone
  # ======================================================================= #
  @run_standalone = true
end

#return_dependenciesObject

#

return_dependencies

We return the dependencies file here.

#


1529
1530
1531
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1529

def return_dependencies
  PROJECT_DOC_DIR+'DEPENDENCIES'
end

#return_gemspec_fileObject

#

return_gemspec_file

We return the main taxonomy.gemspec file here.

#


779
780
781
# File 'lib/bioroebe/taxonomy/interactive.rb', line 779

def return_gemspec_file
  return PROJECT_BASE_DIR+'taxonomy.gemspec'
end

#return_instructionsObject

#

return_instructions

#


1536
1537
1538
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1536

def return_instructions
  PROJECT_DOC_DIR+'INSTRUCTIONS'
end

#return_login_fileObject

#

return_login_file

#


786
787
788
# File 'lib/bioroebe/taxonomy/interactive.rb', line 786

def 
  return Bioroebe::Taxonomy.project_base_dir?+'postgresql_login_command.rb'
end

#return_shared_codeObject

#

return_shared_code

#


770
771
772
# File 'lib/bioroebe/taxonomy/interactive.rb', line 770

def return_shared_code
  return Bioroebe::Taxonomy.project_base_dir?+'shared/shared'
end

#return_taxonomy_fileObject

#

We return the bin/taxonomy file here.

#


1513
1514
1515
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1513

def return_taxonomy_file
  return PROJECT_BASE_DIR+'bin/taxonomy'
end

#runObject Also known as: run_in_interactive_mode

#

run (run tag)

#


1947
1948
1949
1950
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1947

def run
  do_startup_actions
  fetch_user_input_via_loop
end

#run_connected?Boolean

#

run_connected?

#

Returns:

  • (Boolean)


1802
1803
1804
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1802

def run_connected?
  ! run_standalone?
end

#run_standalone?Boolean

#

run_standalone?

#

Returns:

  • (Boolean)


1795
1796
1797
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1795

def run_standalone?
  @run_standalone
end

#sanitize_user_inputObject

#

sanitize_user_input

#


1469
1470
1471
1472
1473
1474
1475
1476
1477
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1469

def sanitize_user_input
  splitted = @user_input.split(' ')
  @cmd = splitted.first
  if @user_input.empty?
    @first_argument = nil
  else
    @first_argument = splitted[1..-1].join(' ') # This is equal to all remaining arguments for now, actually.
  end
end

#search_in_database_for_name(i = 'Zygosaccharomyces rouxii') ⇒ Object

#

search_in_database_for_name

Use this method to search in a database for a name.

This is something such as the following SQL query:

select taxid FROM names WHERE name_txt LIKE '%Zygosaccharomyces rouxii%' limit 30;

It will return the TaxID of the organism.

#


944
945
946
947
948
949
# File 'lib/bioroebe/taxonomy/interactive.rb', line 944

def search_in_database_for_name(i = 'Zygosaccharomyces rouxii')
  e 'We will now try to search the names table for '+sfancy(i)+'.'
  _ = "select taxid,name_txt FROM names WHERE name_txt LIKE '%"+i+"%' LIMIT 3;"
  result = run_sql_query(_, false, :tuples)
  return result
end

#search_in_localomes(i = 'Blastocystis hominis') ⇒ Object

#

search_in_localomes

This will search in localomes.

#


664
665
666
667
668
669
670
671
# File 'lib/bioroebe/taxonomy/interactive.rb', line 664

def search_in_localomes(i = 'Blastocystis hominis')
  if be_verbose?
    e 'We will now try to search the fasta table for `'+sfancy(i)+'`.'
  end
  _ = "select name,modification_time FROM fasta WHERE name LIKE '%"+i+"%' LIMIT 3;"
  result = run_sql_query(_, true)
  return result
end

#select_name_and_lineage_idsObject

#

select_name_and_lineage_ids

#


898
899
900
# File 'lib/bioroebe/taxonomy/interactive.rb', line 898

def select_name_and_lineage_ids
  run_query('select name,lineage_ids from fasta;', false, :tuples)
end

#select_name_and_tax_id_and_lineage_idsObject

#

select_name_and_tax_id_and_lineage_ids

#


905
906
907
# File 'lib/bioroebe/taxonomy/interactive.rb', line 905

def select_name_and_tax_id_and_lineage_ids
  run_query('select name,taxid,lineage_ids from fasta;', false, :tuples)
end

#select_name_and_tax_id_and_lineage_ids_and_pathObject

#

select_name_and_tax_id_and_lineage_ids_and_path

#


912
913
914
# File 'lib/bioroebe/taxonomy/interactive.rb', line 912

def select_name_and_tax_id_and_lineage_ids_and_path
  run_query('select name,taxid,lineage_ids,path from fasta;', false, :tuples)
end

#set_commandline_arguments(i = nil) ⇒ Object

#

set_commandline_arguments

#


1739
1740
1741
1742
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1739

def set_commandline_arguments(i = nil)
  i = [i] unless i.is_a? Array
  @commandline_arguments = i # Must be an Array.
end

#set_database(i) ⇒ Object

#

set_database

#


1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1720

def set_database(i)
  i = i.to_s.chomp.delete('"')
  if i.empty?
    e 'Please provide the type of the database you wish to '\
      'use, such as "postgresql".'
  else
    case i
    when 'postgre'
      i = 'postgresql'
    end
    i = i.downcase
    e 'Storing '+i+' into '+sfile(FILE_USE_THIS_DATABASE)+'.'
    write_what_into(i, FILE_USE_THIS_DATABASE)
  end
end

#set_path(i) ⇒ Object

#

set_path

Use this method to update the path to a local fasta entry, inside the localome entry. In order for this to work, the ID must exist.

Complete usage example:

spath 1257118 /resources/seqdata/curated/sequences/localome/proteomes/Acanthamoeba_castellanii_Neff_pep.fa
#


962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
# File 'lib/bioroebe/taxonomy/interactive.rb', line 962

def set_path(i)
  if i.include? ' '
    splitted = i.split(' ')
    taxid_to_update = splitted[0].to_s
    new_path        = splitted[1].to_s
    if has_id? taxid_to_update # If localomes has this ID, we continue here:
      e 'Now updating path for TaxID '+sfancy(taxid_to_update)+'.'
      run_sql "UPDATE fasta SET path='"+new_path+"' WHERE taxid='"+taxid_to_update+"'"
    else
      e 'We could not find a TaxID '+sfancy(taxid_to_update)+
        ' in the localome table. Thus can not update the path.'
    end
  else
    if File.exist? i
      data = File.readlines(i).map(&:chomp).reject {|entry| entry.empty? }
      data.each {|entry|
        entry = entry.strip
        if entry.include? '|'
          splitted = entry.split('|')
        else # else assume \t
          splitted = entry.split("\t")
        end
        set_path(splitted.first+' '+splitted[1])
      }
      e 'Note: if you wish to see the modified dataset, input: taxid,path'
    else
      e 'Format was not correct. Please either provide a file as argument,'
      e 'or use input such as this here:'
      e
      e '   spath 1257118 /resources/seqdata/curated/sequences/localome/proteomes/Acanthamoeba_castellanii_Neff_pep.fa'
      e
    end
  end
end

#show_all_eukarya(optional_show_path = false) ⇒ Object

#

show_all_eukarya

#


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
# File 'lib/bioroebe/taxonomy/interactive.rb', line 299

def show_all_eukarya(
    optional_show_path = false
  )

  e 'We found these Eukaryota in the localomes Database:'+N+N
  if optional_show_path.is_a? String
    _ = select_name_and_tax_id_and_lineage_ids_and_path # 0,1,2,3
  else
    _ = select_name_and_tax_id_and_lineage_ids
  end

  n_entries = _.split(N).size
  result  = []
  counter = 0
  _.split(N).each_with_index {|entry|
    splitted = entry.split('|')
    lineage = splitted[2]
    if lineage =~ / #{Eukaryota_Taxonomy_ID} /
      scientific_name = splitted.first.strip
      counter += 1
      result = simp(counter.to_s)+') '+scientific_name+
               ' ('+sfancy('TaxID')+': '+splitted[1].to_s.strip+')'
      if optional_show_path.is_a? String
        result << (' Path: '+splitted[3]).ljust(40) # Append the path.
      end
      e result
      result << scientific_name
    else # debug
    end
  }
  e N+N+'Out of '+sfancy(n_entries.to_s)+' registered '\
    'entries in total in the localomes database,'
  e sfancy(result.size.to_s)+' belong to Eukaryota (the Taxonomy '\
    'ID of Eukaryota is '+sfancy(Eukaryota_Taxonomy_ID.to_s)+').'
  array = _.split(N).map {|entry| entry.split('|')[1].strip}
  report_total_amount_of_proteomes(array)
end

#show_all_prokaryaObject

#

show_all_prokarya (prokarya tag)

This method will show all entries in the database that are from Prokaryotes.

#


1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1411

def show_all_prokarya
  _ = select_name_and_tax_id_and_lineage_ids
  n_entries = _.split(N).size
  result = []
  counter = 0
  _.split(N).each_with_index {|entry|
    splitted = entry.split('|')
    lineage = splitted[2]
    if lineage =~ / #{Bacteria_Taxonomy_ID} /
      scientific_name = splitted.first.strip
      counter += 1
      e simp(counter.to_s)+') '+scientific_name+' ('+
        sfancy('TaxID')+': '+splitted[1].to_s.strip+')'
      result << scientific_name
    end
  }
  e N+N+'Out of '+sfancy(n_entries.to_s)+' registered entries in '+
    'total in the localomes database,'
  e sfancy(result.size.to_s)+' belong to Prokarya (the Taxonomy ID of '+
    'Prokarya is '+sfancy(Bacteria_Taxonomy_ID.to_s)+').'
end

#show_changelogObject

#

show_changelog

#


1520
1521
1522
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1520

def show_changelog
  cat PROJECT_DOC_DIR+'CHANGELOG_FROM_0.0.14_TO_0.0.15'
end

#show_configurationObject

#

show_configuration

#


1691
1692
1693
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1691

def show_configuration
  e which_database_to_use?
end

#show_important_directoriesObject

#

show_important_directories

Delegate towards Taxonomy.status? from here.

#


1293
1294
1295
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1293

def show_important_directories
  Taxonomy.status?
end

#show_last_commandObject

#

show_last_command

#


1543
1544
1545
1546
1547
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1543

def show_last_command
  last_command = File.read(LAST_INTERACTIVE_COMMAND)
  e 'The last command was: '+simp(last_command.to_s)
  e 'This was read in from the file '+sfile(LAST_INTERACTIVE_COMMAND)
end

#show_lineage_from_localome_table(i) ⇒ Object

#

show_lineage_from_localome_table

The TaxID must exist before we can use this.

Usage examples:

show_lineage_from_localome_table 2762
slocalome 2762
#


1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1316

def show_lineage_from_localome_table(i)
  result = run_sql(
    "select lineage_ids from fasta WHERE taxid='"+i.to_s+"';", false, :tuples
  ).chomp.strip
  if result.empty?
    e 'This TaxID was not found in the localome table.'
    e 'To find out which entries exist in the localome table, do "localome?".'
  else
    e result
  end
end

#show_login_informationObject

#

show_login_information

#


757
758
759
760
761
762
763
764
765
# File 'lib/bioroebe/taxonomy/interactive.rb', line 757

def 
  e 'The login information is stored in the file '
  e
  e '  '+sfile(
      Bioroebe::Taxonomy.project_base_dir?+'databases/postgresql_login_command.rb'
    )
  e
  show_port # Show the port as well here.
end

#show_nodes_tableObject

#

show_nodes_table

#


793
794
795
796
797
798
799
800
801
802
803
804
# File 'lib/bioroebe/taxonomy/interactive.rb', line 793

def show_nodes_table
  e 'We use these values for the nodes table:'
  e
  efancy '  taxid'
  efancy '  parent_taxid'
  efancy '  rank'
  e
  e 'We will also try to show a random selection of 10 entries from '\
    'there now:'
  run_sql 'SELECT taxid,parent_taxid,rank FROM nodes
    ORDER BY RANDOM(), taxid LIMIT 10'
end

#show_portObject

#

show_port

Use this method to show the port.

#


812
813
814
# File 'lib/bioroebe/taxonomy/interactive.rb', line 812

def show_port
  e "The port we will use is: #{simp('UNKNOWN')}"
end

#show_postgres_sizeObject

#

show_postgres_size

This method will show the size of the postgres database.

#


1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1017

def show_postgres_size
  e 'Next querying the size of the postgresql table:'
  sql_query POSTGRESQL_QUERY_SIZE, true
  # relpages are not too useful to look at, so we commented it out again.
  # sql_query 'SELECT relname, relpages FROM pg_class ORDER BY relpages DESC LIMIT 5;'
  e 'The total disk size for the robert_db is:'
  sql_query "SELECT pg_size_pretty(pg_database_size('robert_db'));",true
  e 'Size of '+sfancy(:names)+' is: '+
    sql_query(
      "SELECT pg_size_pretty(pg_total_relation_size('names'));",false, :tuples)
  e 'Size of '+sfancy(:nodes)+' is:  '+
    sql_query(
      "SELECT pg_size_pretty(pg_total_relation_size('nodes'));",false, :tuples)
  e 'Size of '+sfancy(:fasta)+' is:  '+
    sql_query(
      "SELECT pg_size_pretty(pg_total_relation_size('fasta'));",false, :tuples)
end

#show_scientific_name_of(i) ⇒ Object

#

show_scientific_name_of

#


434
435
436
437
438
439
440
441
442
443
444
# File 'lib/bioroebe/taxonomy/interactive.rb', line 434

def show_scientific_name_of(i)
  result = get_scientific_name_of(i).to_s
  if result.empty?
    e 'We tried to find a Tax ID but we got no result.'
    e 'Are you able to connect to the postgresql-database?'
    e 'Perhaps this Tax ID does not exist.'
  else
    e 'The scientific name of Tax ID '+lightblue(i.to_s)+
      ' is: '+simp(result)
  end
end

#show_shared_code_locationObject

#

show_shared_code_location

To invoke this method, do:

shared_code?
#


1282
1283
1284
1285
1286
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1282

def show_shared_code_location
  e 'You can find the file shared.rb here:'
  _ = base_dir?
  e '  '+sfile(_+'/shared.rb')
end

#show_short_helpObject

#

show_short_help

#


1007
1008
1009
1010
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1007

def show_short_help
  e '(Type "help" or "?" for help, or "nohelp" to disable '\
    'this notification here).' unless @no_help
end

#show_sql_commandsObject Also known as: sql?, table_names?

#

show_sql_commands (sql tag)

This method will feedback the SQL commands to create our postgre table and also show the Insert commands used.

#


1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1821

def show_sql_commands
  e N+'The three commands to create the '+
    simp('PostgreSQL database')+' are:'+N+N
  e '  (1) names table:'+N+N
  efancy '  '+create_table(:names).to_s
  e N+'  (2) nodes table:'+N+N
  efancy '  '+create_table(:nodes).to_s
  e N+'  (3) fasta table:'+N+N
  efancy '  '+create_table(:fasta).to_s
end

#show_sql_commands_onlyObject

#

show_sql_commands_only

#


1872
1873
1874
1875
1876
1877
1878
1879
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1872

def show_sql_commands_only
  e Commands.create_table :taxonomy_nodes
  e
  e Commands.create_table :taxonomy_names
  e
  e Commands.create_table :taxonomy_fasta
  e
end

#show_table_namesObject

#

show_table_names

#


1226
1227
1228
1229
1230
1231
1232
1233
1234
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1226

def show_table_names
  e N+'The SQL table structure is as follows:'+N+N
  efancy 'names.sql'
  e '  (1) '+NAMES_ENTRIES+N+N
  efancy 'nodes.sql'
  e '  (2) '+NODES_ENTRIES+N+N
  efancy 'fasta.sql'
  e '  (3) '+FASTA_ENTRIES+N+N
end

#show_type_of_all_info_files(i = nil) ⇒ Object

#

show_type_of_all_info_files

We will get all .INFO files and display the type.

#


1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1388

def show_type_of_all_info_files(i = nil)
  if i
    info = Info.new(i, :silent)
    info.find_fasta
    if info.fasta?
      fasta = ParseFasta.new(info.corresponding_datafile)
      e sfile(i)+' is DNA or Protein? '+fasta.type.to_s
    else
      e 'We could not locate a local fasta entry for '+sfile(i)
    end
  else # else input was nil.
    Dir[INFO_DIR+'*'].each {|entry|
      show_type_of_all_info_files(entry)
    }
  end
end

#silently_update_ncbi_databaseObject

#

silently_update_ncbi_database

This method is the one that can be used to silently update the NCBI table via a cron job.

#


887
888
889
890
891
892
893
# File 'lib/bioroebe/taxonomy/interactive.rb', line 887

def silently_update_ncbi_database
  download :ncbi, :be_silent
  menu 'names'
  menu 'nodes'
  drop_nodes_and_names_database_tables(:be_silent)
  read_in_names_and_nodes_sql_files(:be_silent)
end

#taxtree(i) ⇒ Object

#

taxtree

Obtain the taxtree, then display it. Input to this should be the Taxonomy ID. We will first check the localome table, then query from the two ncbi tables.

To test this method, try:

taxtree 106583
taxtree 77166
#


218
219
220
221
222
223
224
225
226
227
228
# File 'lib/bioroebe/taxonomy/interactive.rb', line 218

def taxtree(i)
  i = i.to_s
  e 'The lineage for Taxonomy ID '+simp(i)+' is as follows:'
  if has? i # Ok, the localome table has this entry.
    lineage_ids = get('lineage_ids', i).strip.split('->').map(&:strip)
  else
    lineage_ids = return_full_lineage_of(i)
    lineage_ids.map! {|entry| entry[0]}
  end
  report_tree_lineage(lineage_ids)
end

#try_to_display_the_status(i = nil) ⇒ Object

#

try_to_display_the_status

#


268
269
270
271
272
273
274
275
276
277
# File 'lib/bioroebe/taxonomy/interactive.rb', line 268

def try_to_display_the_status(
    i = nil
  )
  if i and !i.empty? # if an argument was provided
    StatFile.new(i) if Object.const_defined?(:StatFile)
  else
    Taxonomy.status?
    Info.status
  end
end

#try_to_show_dependenciesObject

#

try_to_show_dependencies

Show the dependencies of the Taxonomy Module. This will tell us which dependencies we have to satisfy.

#


744
745
746
747
748
749
750
751
752
# File 'lib/bioroebe/taxonomy/interactive.rb', line 744

def try_to_show_dependencies
  _ = return_dependencies
  if File.exist? _
    e 'The Taxonomy Module depends on these Ruby Gems:'+N+N
    cat _
  else
    e 'We could not find a file at position `'+sfile(_)+'`.'
  end
end

#try_to_show_instructionsObject

#

try_to_show_instructions

This method will try to show the instructions to the user, based on what the method return_instructions() will give us.

#


1500
1501
1502
1503
1504
1505
1506
1507
1508
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1500

def try_to_show_instructions
  _ = return_instructions
  if File.exist? _
    e 'Now reading in from file `'+sfile(_)+'`.'
    cat _
  else
    e 'We could not find a file at position '+_
  end
end

#try_to_show_when_the_last_update_has_happenedObject

#

try_to_show_when_the_last_update_has_happened

#


356
357
358
# File 'lib/bioroebe/taxonomy/interactive.rb', line 356

def try_to_show_when_the_last_update_has_happened
  e cat(SAVE_FILE) if File.exist? SAVE_FILE
end

#update_lineageObject

#

update_lineage

This will update only the lineage part of the localome database, which means the lineageIDs and the lineage scientific names. In order for this to work, we need to obtain the TaxID of the specific organism.

#


824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
# File 'lib/bioroebe/taxonomy/interactive.rb', line 824

def update_lineage
  e 'We will now obtain all TaxIDs in the localome table.' if be_verbose?
  obtain_taxids = run_sql('select taxid from fasta;', false, :tuples).split(N).
    map(&:strip).map(&:to_i).sort
  # Ignore all entries that are 0.
  obtain_taxids.reject! {|entry|
    entry.to_i == 0
  }
  # We will have to update the following taxids, which is the collection
  # of all TaxIDs available in the table:
  obtain_taxids.each {|taxid|
    e 'Now updating entry with the TaxID: '+sfancy(taxid.to_s)
    get_lineage_ids_and_lineage_scientific_name(taxid)
    report_lineage_ids_and_lineage_scientific_name(taxid)
    if has_id?(taxid)
      # We pad the two entries with proper quotes.
      lineage_id              = pad_with_single_quotes(@lineage_ids)
      lineage_scientific_name = pad_with_single_quotes(@lineage_scientific_name)
      _ = "UPDATE fasta SET lineage_ids="+lineage_id+", lineage_scientific_name="+lineage_scientific_name+" WHERE taxid='"+taxid.to_s+"'"
      run_sql_query(_)
      e 'Updated entry.' if be_verbose?
    else
      e 'We did not find the TaxID: '+simp(taxid.to_s)
    end
  }
  e 'Finished updating lineage.' if be_verbose?
end

#update_local_localomesObject

#

update_local_localomes

Update the local collection. This will overwrite the old dataset completely, so be careful when using this.

To invoke this method via the interactive menu, do:

update databases
#


168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/bioroebe/taxonomy/interactive.rb', line 168

def update_local_localomes
  show_current_time
  create_fasta_table # Get in a new, fresh table.
  _ = get_all_info_entries_with_tax_id
  show_current_time
  _.each {|entry|
    e "Next working on `#{sfile(entry)}`."
    create_sql_file_from_local_fasta_entry(entry)
  }
  report_how_many_info_files_exist_and_how_many_lack_taxonomy_id
  old_time = @time
  show_time_now # Show the end time.
  new_time = @time
  difference = Time.parse(new_time) - Time.parse(old_time)
  report_how_long_it_took_us(difference, 'localome table')
end

#update_ncbi_databaseObject Also known as: update_database

#

update_ncbi_database

This method can be used to update the NCBI Taxonomy database.

This includes a download, extracting it, generating the .sql files, and then populating the postgresql database.

#


569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
# File 'lib/bioroebe/taxonomy/interactive.rb', line 569

def update_ncbi_database
  # show_time_now # Show the start time. No longer needed as the next call does that.
  download :ncbi # Defined in this file here.
  if be_verbose?
    e 'We will update the local postgre NCBI Table '\
      'now (this may take about one hour in total):'
  end
  # This will generate names.sql and nodes.sql.
  menu 'names'
  menu 'nodes'
  # Next, connect to the postgre database and read in the auto-generated dumps:
  if be_verbose?
    e 'We will next load this dataset into the Database.'
    e 'First, dropping the old table entries in the Postgresql database '
    e 'via the DROP TABLE command:'
  end
  drop_nodes_and_names_database_tables
  nodes_size = File.size(NODES_SQL).to_s
  names_size = File.size(NAMES_SQL).to_s
  e 'Next we will populate the two tables with '+sfancy('names.sql')+
    ' (Filesize: '+names_size+') and '+sfancy('nodes.sql')+
    ' (Filesize: '+nodes_size+') file.'
  e 'This may take a while, possibly about an hour, so '\
    'please remain patient.'
  read_in_names_and_nodes_sql_files
  e 'Nota bene: the above commands can only work if psql '\
    'is in your $PATH.'
  e 'If it did not work, please check and see first '\
    'whether your $PATH variable is proper.'
  e N+'We will display the content of the $PATH variable '\
    'now: '+sfancy(ENV['PATH'])
  old_time = @time
  show_time_now # Show the end time.
  new_time = @time
  difference = Time.parse(new_time) - Time.parse(old_time)
  report_how_long_it_took_us(difference)
end

#use_colours?Boolean

#

use_colours?

#

Returns:

  • (Boolean)


695
696
697
# File 'lib/bioroebe/taxonomy/interactive.rb', line 695

def use_colours?
  @use_colours
end

#user_input?Boolean

#

user_input?

#

Returns:

  • (Boolean)


719
720
721
# File 'lib/bioroebe/taxonomy/interactive.rb', line 719

def user_input?
  @user_input
end

#which_database_to_use?Boolean

#

which_database_to_use?

#

Returns:

  • (Boolean)


1684
1685
1686
# File 'lib/bioroebe/taxonomy/interactive.rb', line 1684

def which_database_to_use?
  File.read(PROJECT_YAML_DIR+'use_this_database.yml')
end