bioroebe 0.10.80 → 0.11.12

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

Potentially problematic release.


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

Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +507 -310
  3. data/bioroebe.gemspec +3 -3
  4. data/doc/README.gen +506 -309
  5. data/doc/todo/bioroebe_todo.md +29 -40
  6. data/lib/bioroebe/aminoacids/display_aminoacid_table.rb +1 -0
  7. data/lib/bioroebe/base/colours_for_base/colours_for_base.rb +18 -8
  8. data/lib/bioroebe/base/commandline_application/commandline_arguments.rb +13 -11
  9. data/lib/bioroebe/base/commandline_application/misc.rb +18 -8
  10. data/lib/bioroebe/base/prototype/misc.rb +1 -1
  11. data/lib/bioroebe/codons/show_codon_tables.rb +6 -2
  12. data/lib/bioroebe/constants/aminoacids_and_proteins.rb +1 -0
  13. data/lib/bioroebe/constants/files_and_directories.rb +8 -1
  14. data/lib/bioroebe/count/count_amount_of_nucleotides.rb +3 -0
  15. data/lib/bioroebe/gui/gtk3/protein_to_DNA/protein_to_DNA.rb +18 -18
  16. data/lib/bioroebe/gui/shared_code/protein_to_DNA/protein_to_DNA_module.rb +14 -14
  17. data/lib/bioroebe/parsers/genbank_parser.rb +353 -24
  18. data/lib/bioroebe/python/README.md +1 -0
  19. data/lib/bioroebe/python/__pycache__/mymodule.cpython-39.pyc +0 -0
  20. data/lib/bioroebe/python/gui/gtk3/widget1.py +22 -0
  21. data/lib/bioroebe/python/mymodule.py +8 -0
  22. data/lib/bioroebe/python/protein_to_dna.py +30 -0
  23. data/lib/bioroebe/python/shell/shell.py +19 -0
  24. data/lib/bioroebe/python/to_rna.py +14 -0
  25. data/lib/bioroebe/python/toplevel_methods/to_camelcase.py +11 -0
  26. data/lib/bioroebe/sequence/nucleotide_module/nucleotide_module.rb +28 -25
  27. data/lib/bioroebe/sequence/sequence.rb +54 -2
  28. data/lib/bioroebe/shell/menu.rb +3336 -3304
  29. data/lib/bioroebe/shell/readline/readline.rb +1 -1
  30. data/lib/bioroebe/shell/shell.rb +11233 -28
  31. data/lib/bioroebe/siRNA/siRNA.rb +81 -1
  32. data/lib/bioroebe/string_matching/find_longest_substring.rb +3 -2
  33. data/lib/bioroebe/toplevel_methods/aminoacids_and_proteins.rb +31 -24
  34. data/lib/bioroebe/toplevel_methods/nucleotides.rb +22 -5
  35. data/lib/bioroebe/toplevel_methods/open_in_browser.rb +2 -0
  36. data/lib/bioroebe/toplevel_methods/to_camelcase.rb +5 -0
  37. data/lib/bioroebe/version/version.rb +2 -2
  38. data/lib/bioroebe/yaml/configuration/browser.yml +1 -1
  39. data/lib/bioroebe/yaml/restriction_enzymes/restriction_enzymes.yml +3 -3
  40. metadata +17 -36
  41. data/doc/setup.rb +0 -1655
  42. data/lib/bioroebe/genbank/genbank_parser.rb +0 -291
  43. data/lib/bioroebe/shell/add.rb +0 -108
  44. data/lib/bioroebe/shell/assign.rb +0 -360
  45. data/lib/bioroebe/shell/chop_and_cut.rb +0 -281
  46. data/lib/bioroebe/shell/constants.rb +0 -166
  47. data/lib/bioroebe/shell/download.rb +0 -335
  48. data/lib/bioroebe/shell/enable_and_disable.rb +0 -158
  49. data/lib/bioroebe/shell/enzymes.rb +0 -310
  50. data/lib/bioroebe/shell/fasta.rb +0 -345
  51. data/lib/bioroebe/shell/gtk.rb +0 -76
  52. data/lib/bioroebe/shell/history.rb +0 -132
  53. data/lib/bioroebe/shell/initialize.rb +0 -217
  54. data/lib/bioroebe/shell/loop.rb +0 -74
  55. data/lib/bioroebe/shell/misc.rb +0 -4341
  56. data/lib/bioroebe/shell/prompt.rb +0 -107
  57. data/lib/bioroebe/shell/random.rb +0 -289
  58. data/lib/bioroebe/shell/reset.rb +0 -335
  59. data/lib/bioroebe/shell/scan_and_parse.rb +0 -135
  60. data/lib/bioroebe/shell/search.rb +0 -337
  61. data/lib/bioroebe/shell/sequences.rb +0 -200
  62. data/lib/bioroebe/shell/show_report_and_display.rb +0 -2901
  63. data/lib/bioroebe/shell/startup.rb +0 -127
  64. data/lib/bioroebe/shell/taxonomy.rb +0 -14
  65. data/lib/bioroebe/shell/tk.rb +0 -23
  66. data/lib/bioroebe/shell/user_input.rb +0 -88
  67. data/lib/bioroebe/shell/xorg.rb +0 -45
@@ -1,310 +0,0 @@
1
- #!/usr/bin/ruby -w
2
- # Encoding: UTF-8
3
- # frozen_string_literal: true
4
- # =========================================================================== #
5
- # Enzyme-related components of the BioShell will be stored here.
6
- # =========================================================================== #
7
- # require 'bioroebe/shell/enzymes.rb'
8
- # =========================================================================== #
9
- module Bioroebe
10
-
11
- class Shell < ::Bioroebe::CommandlineApplication
12
-
13
- require 'bioroebe/enzymes/has_this_restriction_enzyme.rb'
14
- require 'bioroebe/enzymes/restriction_enzymes_file.rb'
15
-
16
- # ========================================================================= #
17
- # === return_random_restriction_enzyme
18
- #
19
- # This method will return a random restriction enzyme, such as:
20
- #
21
- # ["EgeI", "GGCGCC 3"]
22
- #
23
- # ========================================================================= #
24
- def return_random_restriction_enzyme(be_verbose = false)
25
- splitted = ::Bioroebe.restriction_enzymes.sample
26
- _ = splitted[1].split(' ')[0]
27
- if be_verbose
28
- erev 'Now adding restriction site `'+red(splitted[0])+
29
- '` (cuts at '+simp(_)+').'
30
- end
31
- return _
32
- end
33
-
34
- # ========================================================================= #
35
- # === find_restriction_enzymes_that_cut_at
36
- #
37
- # A wrapper over find_restriction_sites().
38
- # ========================================================================= #
39
- def find_restriction_enzymes_that_cut_at(i)
40
- erev 'Trying to find restriction enzymes that '\
41
- 'cut at `'+sfancy(i)+rev+'`.'
42
- result = find_restriction_sites(i)
43
- unless result
44
- erev 'Found no result for this sequence.'
45
- end
46
- end
47
-
48
- # ========================================================================= #
49
- # === show_restriction_enzymes
50
- #
51
- # Display the available restriction enzymes here.
52
- #
53
- # If we pass an argument, then we assume that we wish to show only
54
- # these restriction enzymes that cut at n bp.
55
- #
56
- # Invocation example:
57
- #
58
- # show_restriction_enzymes(:show_all)
59
- #
60
- # ========================================================================= #
61
- def show_restriction_enzymes(optional_input = nil)
62
- case optional_input
63
- when nil, :show_all # This means to show everything.
64
- ::Bioroebe.show_restriction_enzymes # Defined in module_methods.rb
65
- else # Ok we gave input then.
66
- _ = ::Bioroebe.restriction_enzymes
67
- _.select! {|entry|
68
- last = entry.last
69
- last = last.split(' ').last
70
- if last == optional_input
71
- true
72
- else
73
- false
74
- end
75
- }
76
- if _.empty?
77
- erev 'We found no match for '+optional_input+'.'
78
- else # else display the cutters.
79
- erev 'These enzymes cut at `'+sfancy(optional_input)+rev+'` nucleotides.'
80
- _.each {|entry|
81
- entry[0] = entry[0].rjust(15)
82
- entry[1] = entry[1].gsub(/ (.+)/, swarn(' \\1')+rev)
83
- e " #{entry.join(' -> ')}"
84
- }
85
- erev 'These are '+simp(_.size.to_s)+rev+' restriction enzymes.'
86
- end
87
- end
88
- end
89
-
90
- # ========================================================================= #
91
- # === try_to_find_this_restriction_enzyme
92
- #
93
- # Use this method to find a specific restriction enzyme.
94
- #
95
- # The restriction enzymes are stored in this yaml file here:
96
- #
97
- # bl $BIOROEBE/yaml/restriction_enzymes/restriction_enzymes.yml
98
- #
99
- # Usage example:
100
- #
101
- # MvnI?
102
- #
103
- # ========================================================================= #
104
- def try_to_find_this_restriction_enzyme(i)
105
- i = i.dup if i.frozen?
106
- i.delete!('?') # We do not need any '?' characters.
107
- original_input = i.dup
108
- # i = i.downcase # No longer downcase since as of June 2018.
109
- if i.include? 'restriction'
110
- i.sub!(/restriction/,'')
111
- end
112
- if i.include? '.site' # Assume a syntax such as: Restriction.EcoRI.site
113
- e ::Bioroebe.restriction_enzyme(i)
114
- else # else it will be more verbose
115
- i.delete!('.') if i.include? '.'
116
- if i.end_with?('1') and !::Bioroebe.has_this_restriction_enzyme?(i) # Is invalid.
117
- erev 'The input `'+simp(i)+rev+'` ends with the number 1. This '\
118
- 'is not possible, so'
119
- erev 'we replace the trailing 1 with a capital I.'
120
- i[-1,1] = 'i' # Ok not a capital one, because we store in a downcased variant.
121
- original_input[-1,1] = 'I'
122
- end
123
- if ::Bioroebe.has_this_restriction_enzyme? i
124
- target_sequence_data = ::Bioroebe.return_restriction_enzyme_sequence_and_cut_position(i)
125
- # =================================================================== #
126
- # Tap into the method Bioroebe.restriction_enzyme
127
- # =================================================================== #
128
- _ = ::Bioroebe.restriction_enzyme(i) # bl $BIOROEBE/module_methods.rb
129
- erev "We have found a restriction enzyme called "\
130
- "#{sfancy(original_input)}#{rev}."
131
- e
132
- e "#{rev}The sequence this #{mediumorchid(_.size.to_s+'-cutter')}#{rev}"\
133
- " relates to is: `"\
134
- "#{sfancy(five_prime+simp(_)+rev)}"\
135
- "#{sfancy(three_trailer)}#{rev}`"
136
- e
137
- # =================================================================== #
138
- # The variable target_sequence_data will look like this:
139
- # ["GCCNNNNNGGC", "7", "7"]
140
- # =================================================================== #
141
- if target_sequence_data.last == :blunt
142
- erev "This restriction enzyme will produce a "\
143
- "#{seagreen('blunt')}#{rev} overhang."
144
- e
145
- else
146
- erev "This restriction enzyme will produce a "\
147
- "#{seagreen('sticky-end')}#{rev} overhang."
148
- e
149
- end
150
- # =================================================================== #
151
- # Next, show the exact cut that will be made.
152
- # =================================================================== #
153
- sequence = ::Bioroebe.return_sequence_that_is_cut_via_restriction_enzyme(i)
154
- erev 'It will specifically cut between: '+
155
- sfancy(five_prime)+rev+
156
- simp(sequence)+
157
- sfancy(three_trailer)+rev
158
- # =================================================================== #
159
- # And the complementary sequence follows next. The colour used
160
- # is swarn().
161
- # =================================================================== #
162
- complementary_sequence = reverse(
163
- Colours.remove_escape_sequences(sequence)
164
- )
165
- # =================================================================== #
166
- # We must insert a | at the right position.
167
- # =================================================================== #
168
- target_sequence_data = target_sequence_data[1].to_i
169
- complementary_sequence[-target_sequence_data,0] = swarn('|')+rev
170
- erev ''.ljust(38)+sfancy(leading_three_prime)+rev+
171
- complementary_sequence+rev+
172
- sfancy(five_prime_trailer)+rev
173
- else
174
- erev 'We were unable to find a restriction enzyme called '\
175
- '`'+sfancy(i)+'`'+rev
176
- end
177
- end
178
- end
179
-
180
- # ========================================================================= #
181
- # === try_to_find_restriction_enzymes_for
182
- #
183
- # This method name is a slight misnomer; we can simply find any
184
- # target sequence.
185
- #
186
- # The method can also handle some Symbols as input, such as the symbol
187
- # :shine_dalgarno, which will be replaced accordingly to the SD
188
- # sequence.
189
- # ========================================================================= #
190
- def try_to_find_restriction_enzymes_for(
191
- i
192
- )
193
- # ======================================================================= #
194
- # === We always have to work with an Array as input
195
- # ======================================================================= #
196
- unless i.is_a? Array
197
- i = [i]
198
- end
199
- i.map! {|entry|
200
- case entry # Use special sequences.
201
- when :shine_dalgarno
202
- entry = 'AGGAGGT'
203
- end
204
- # ===================================================================== #
205
- # Past this point, we will assume a String as input. But we will have
206
- # to make sure, still.
207
- # ===================================================================== #
208
- entry = entry.to_s unless entry.is_a? String
209
- entry.delete!('-') if entry.include? '-'
210
- entry
211
- }
212
- i.each {|entry|
213
- report_main_sequence(entry) { :with_ruler }
214
- possible_results = dna_string?.scan(/#{entry}/)
215
- unless possible_results.empty?
216
- e
217
- erev "Start nucleotide position is at: "\
218
- "#{simp((dna_string?.index(entry)+1))}#{rev}"
219
- e
220
- end
221
- }
222
- end; alias find_this_sequence try_to_find_restriction_enzymes_for # === find_this_sequence
223
- alias find_in_main_sequence try_to_find_restriction_enzymes_for # === find_in_main_sequence
224
-
225
- # ========================================================================= #
226
- # === restriction_enzyme_digest
227
- #
228
- # This method allows us to simulate a restriction digest, on a
229
- # DNA polymer.
230
- #
231
- # You can either give the matching DNA nucleotides or you can
232
- # use the name of a restriction enzyme instead, such as 'EcoRI'.
233
- #
234
- # Usage examples:
235
- #
236
- # random 750; digest_at TTGC
237
- # random 750; digest_at EcoRI
238
- # random 2000; [33,0] = GAATTC; digest_at EcoRI
239
- #
240
- # ========================================================================= #
241
- def restriction_enzyme_digest(
242
- split_at = nil # Default value is nil.
243
- )
244
- _ = dna_sequence? # Keep a copy of the DNA sequence.
245
- # ======================================================================= #
246
- # === Grab the first entry if we have an Array
247
- # ======================================================================= #
248
- split_at = split_at.first if split_at.is_a? Array
249
- split_at = 'TTG' if split_at.nil?
250
- split_at = split_at.to_s # Work on Strings past this point here.
251
- split_at.sub!(/^first_/,'') if split_at.include? 'first_ATG'
252
- # ======================================================================= #
253
- # === Chop off all '?' in the sequence
254
- # ======================================================================= #
255
- split_at.delete!('?') if split_at.include? '?'
256
- # ======================================================================= #
257
- # Next, allow the user to substitute for names of restriction enzymes.
258
- # How do we determine that a restriction enzyme was given to this
259
- # method? Simple - we first remove all instances of 'A','T','C','G'
260
- # in our DNA sequence string. If the string is then still not empty,
261
- # we will assume that it is the name of a restriction enzyme.
262
- # ======================================================================= #
263
- unless (_.delete('ATGC').size > 0)
264
- erev 'Assumingly a restriction enzyme was given as input.'
265
- target_sequence = ::Bioroebe.restriction_enzyme(split_at)
266
- # Must check for nil values still
267
- if target_sequence
268
- erev "Substituting with `#{simp(target_sequence)}#{rev}` next (for #{split_at})."
269
- split_at = target_sequence
270
- else
271
- erev 'No substitute could be found for `'+sfancy(split_at)+rev+'`.'
272
- end
273
- end
274
- if _.include? split_at
275
- splitted = _.split(split_at)
276
- e
277
- erev 'We will next display all '+simp(splitted.size.to_s)+rev+
278
- ' segments that were found (in orange is the part that '\
279
- 'is cut-out):'
280
- e
281
- splitted.each_with_index {|sequence, index|
282
- index += 1
283
- erev lpad?+lead_five_prime+sfancy(sequence)+rev+
284
- trail_three_prime+' (size: '+
285
- violet(sequence.size.to_s)+rev+')'
286
- unless index > (splitted.size-1)
287
- erev lpad?+lead_five_prime+orange(split_at)+rev+
288
- trail_three_prime+rev
289
- end
290
- }
291
- e
292
- erev 'Note that this will NOT be the actual DNA fragments, '\
293
- 'because the restriction'
294
- erev 'enzyme may cut differentially within that orange sequence.'
295
- else # The target sequence was not included in this case.
296
- erev "No target match for `"\
297
- "#{simp(target_sequence)}#{rev}` was "\
298
- "found in the given DNA sequence."
299
- end
300
- end; alias digest restriction_enzyme_digest # === digest
301
-
302
- # ========================================================================= #
303
- # === restriction_enzymes_run
304
- # ========================================================================= #
305
- def restriction_enzymes_run
306
- require 'bioroebe/gui/gtk2/restriction_enzymes/restriction_enzymes.rb'
307
- ::Bioroebe::GUI::Gtk::RestrictionEnzymes.start_gui_application
308
- end
309
-
310
- end; end
@@ -1,345 +0,0 @@
1
- #!/usr/bin/ruby -w
2
- # Encoding: UTF-8
3
- # frozen_string_literal: true
4
- # =========================================================================== #
5
- # require 'bioroebe/shell/fasta.rb'
6
- # =========================================================================== #
7
- module Bioroebe
8
-
9
- class Shell < ::Bioroebe::CommandlineApplication
10
-
11
- # ========================================================================= #
12
- # === handle_fasta
13
- #
14
- # Use this method to properly handle a fasta file.
15
- #
16
- # The argument should be the (local) path to a fasta file.
17
- # ========================================================================= #
18
- def handle_fasta(i)
19
- if i.nil?
20
- if File.exist? fasta_file?.to_s
21
- e sfile(fasta_file?.to_s)
22
- else
23
- show_my_fasta_file # As a reminder.
24
- end
25
- else
26
- i = i.to_s unless i.is_a? String # Need a String past this point.
27
- if File.exist?(i) and i.end_with?('.fasta')
28
- opnn; erev 'Trying to parse the file `'+sfile(i)+rev+'` next.'
29
- parse_fasta_format(i)
30
- else
31
- fasta_files = Dir['*.fasta']
32
- unless fasta_files.empty?
33
- erev 'There seems to be at least one .fasta file in this '\
34
- 'directory ('+sdir(return_pwd)+').'
35
- end
36
- end
37
- end
38
- end; alias assign_fasta handle_fasta # === assign_fasta
39
- alias handle_this_fasta_file handle_fasta # === handle_this_fasta_file
40
-
41
- require 'bioroebe/fasta_and_fastq/parse_fasta/misc.rb'
42
- # ========================================================================= #
43
- # === parse_fasta_format
44
- #
45
- # Parse FASTA format here. We will delegate into class
46
- # Bioroebe::ParseFasta for that.
47
- #
48
- # Usage example:
49
- #
50
- # pfasta NM_001180897.3_Saccharomyces_cerevisiae_S288c_Aga2p_AGA2.fasta
51
- #
52
- # ========================================================================= #
53
- def parse_fasta_format(
54
- i = nil
55
- )
56
- if i.is_a? Array
57
- i.each {|entry|
58
- parse_fasta_format(entry)
59
- }
60
- else
61
- # ===================================================================== #
62
- # === If input is only numbers.
63
- # ===================================================================== #
64
- i = Dir['*'][i.to_i + 1] if i =~ /^\d+$/ # <- Only numbers.
65
- case i
66
- # ===================================================================== #
67
- # === ASSIGN
68
- #
69
- # This entry point can be used by the user to input ad-hoc data
70
- # for a FASTA sequence.
71
- # ===================================================================== #
72
- when /^ASSIGN$/i
73
- opnn; erev 'Input your FASTA Data now (Use __ to terminate input):'
74
- i = $stdin.gets('__').chomp
75
- end
76
- # ===================================================================== #
77
- # If we did not provide an input, we scan for entries with .fa
78
- # in the current directory.
79
- # ===================================================================== #
80
- if i.nil?
81
- unless Dir['*.fa'].empty?
82
- i = Dir['*.fa']
83
- end
84
- end
85
- if i.is_a? Array
86
- i = i.first
87
- end
88
- if i
89
- erev "Now loading from `#{sfancy(i)}#{rev}`."
90
- end
91
- @internal_hash[:fasta_file] = i
92
- parse_fasta_object = ::Bioroebe.parse_fasta(i) # bl $RSRC/bioroebe/lib/bioroebe/fasta/parse_fasta.rb
93
- # ===================================================================== #
94
- # === We will store all created fasta objects in an Array
95
- # ===================================================================== #
96
- array_fasta? << parse_fasta_object
97
- this_sequence = parse_fasta_object.sequence?
98
- # ===================================================================== #
99
- # Handle large sequences next - we will add a timer. The purpose of
100
- # this timer is to notify the user how long it took to assign to
101
- # the main string. At a later point, we can optimize the speed and
102
- # do the assignment in pure C rather than ruby.
103
- # ===================================================================== #
104
- if this_sequence.size > 1_000_000
105
- add_timer_snapshot
106
- erev 'The sequence is fairly large - we will time how long it takes to'
107
- erev 'assign it to the main sequence.'
108
- end
109
- # ===================================================================== #
110
- # Obtain the type next:
111
- # ===================================================================== #
112
- type = parse_fasta_object.type?
113
- unless type == :protein
114
- set_dna_sequence(this_sequence)
115
- if this_sequence.size > 1_000_000
116
- add_timer_snapshot
117
- n_seconds_difference = calculate_time_difference.abs.to_f.round(3).to_s
118
- erev "Loading these #{springgreen(this_sequence.size.to_s)}"\
119
- "#{rev}"\
120
- " nucleotides "\
121
- "took #{sfancy(n_seconds_difference)}#{rev} seconds."
122
- end
123
- end
124
- end
125
- end; alias parse_this_fasta_file parse_fasta_format # === parse_this_fasta_file
126
-
127
- require 'bioroebe/toplevel_methods/delimiter.rb'
128
- # ========================================================================= #
129
- # === obtain_multiline_fasta
130
- #
131
- # If we want to obtain multiline FASTA input, that is input that includes
132
- # the "\n" newline character, then we can use the following method here.
133
- #
134
- # We will use $stdin to obtain the input. The end-delimiter will
135
- # be ___
136
- # ========================================================================= #
137
- def obtain_multiline_fasta
138
- delimiter = ::Bioroebe.delimiter?
139
- erev 'Input your Fasta format or nucleotide sequence next - '\
140
- 'delimit/end via "'+lightgreen(delimiter)+rev+'" (3x the _ '\
141
- 'character).'
142
- # ======================================================================= #
143
- # Chop away all newlines.
144
- # ======================================================================= #
145
- dataset = $stdin.gets(delimiter)
146
- # ======================================================================= #
147
- # Format the dataset a little.
148
- # ======================================================================= #
149
- dataset.chomp!
150
- dataset.delete!('_')
151
- dataset.delete!(N)
152
- dataset.strip!
153
- parse_fasta_format(dataset)
154
- # assign_sequence(dataset)
155
- end
156
-
157
- # ========================================================================= #
158
- # === array_fasta?
159
- # ========================================================================= #
160
- def array_fasta?
161
- @internal_hash[:array_fasta]
162
- end
163
-
164
- require 'bioroebe/toplevel_methods/fasta_and_fastq.rb'
165
- # ========================================================================= #
166
- # === index_this_fasta_file
167
- #
168
- # This will index FASTA files (.fa or .fasta) via the samtools.
169
- # ========================================================================= #
170
- def index_this_fasta_file(i)
171
- # ======================================================================= #
172
- # === Handle blocks first
173
- # ======================================================================= #
174
- if block_given?
175
- yielded = yield
176
- case yielded
177
- when :use_all_fasta_files_if_no_argument_was_given
178
- if i.nil? or i.empty?
179
- i = Dir['*.fasta']+
180
- Dir['*.fa'].flatten.compact
181
- end
182
- end
183
- end
184
- if i.is_a? Array
185
- i.each {|entry| index_this_fasta_file(entry) }
186
- else
187
- i = i.to_s # Need to work on a String past this point.
188
- if File.exist? i
189
- erev "Indexing the following file next, via "\
190
- "#{steelblue('samtools')}#{rev}:"
191
- Bioroebe.index_this_fasta_file(i)
192
- else
193
- no_file_exists_at(i)
194
- end
195
- end
196
- end
197
-
198
- # ========================================================================= #
199
- # === try_to_display_this_fasta_entry
200
- # ========================================================================= #
201
- def try_to_display_this_fasta_entry(i)
202
- if i.is_a? String
203
- i = i.to_i - 1 # -1 because Arrays in ruby begin at 0.
204
- end
205
- last_entry = array_fasta?.last
206
- sequence_data = last_entry[i]
207
- erev sequence_data
208
- if block_given?
209
- yielded = yield
210
- case yielded
211
- # ===================================================================== #
212
- # === :and_assign_it_as_well
213
- # ===================================================================== #
214
- when :and_assign_it_as_well
215
- assign(sequence_data) # In this case it will become the new main sequence data.
216
- end
217
- end
218
- end
219
-
220
- # ========================================================================= #
221
- # === parse_this_fasta_sequence
222
- # ========================================================================= #
223
- def parse_this_fasta_sequence(i)
224
- if i and File.file?(i)
225
- set_aminoacid(File.read(i).delete("\n"))
226
- end
227
- end
228
-
229
- # ========================================================================= #
230
- # === fasta?
231
- #
232
- # We need a query method over the main fasta object, IF it was set.
233
- #
234
- # Since we already have an Array that keeps track of these objects,
235
- # we can simply grab the last one from that collection.
236
- # ========================================================================= #
237
- def fasta?
238
- array_fasta?.last
239
- end; alias last_fasta? fasta? # === fasta?
240
- alias last_fasta_entry? fasta? # === last_fasta_entry?
241
-
242
- # ========================================================================= #
243
- # === colourize_fasta_file
244
- #
245
- # Invocation example:
246
- #
247
- # colourize_fasta_file /Depot/Temp/bioroebe/sequence.fasta
248
- #
249
- # ========================================================================= #
250
- def colourize_fasta_file(i)
251
- if i.is_a? Array
252
- i.each {|entry| colourize_fasta_file(entry) }
253
- else
254
- # ===================================================================== #
255
- # First, get the raw content of the fasta sequence here.
256
- # ===================================================================== #
257
- if File.exist? i
258
- sequence = ::Bioroebe.parse_fasta_file(i).sequence?
259
- # =================================================================== #
260
- # Now that we have the sequence, colourize it.
261
- # =================================================================== #
262
- cliner {
263
- ColourSchemeDemo.new(sequence)
264
- }
265
- end
266
- end
267
- end
268
-
269
- # ========================================================================= #
270
- # === to_fasta
271
- #
272
- # Create a Fasta format from the target sequence.
273
- # ========================================================================= #
274
- def to_fasta(
275
- i = dna_sequence?
276
- )
277
- array = i.scan(/.{,80}/).reject {|entry| entry.empty? }
278
- name_of_the_gene = sequence_object?.name_of_gene?.to_s
279
- if name_of_the_gene.empty?
280
- name_of_the_gene << 'Drosophila melanogaster chromosome'
281
- end
282
- array[0,0] = '>gi|671162122:c7086083-7083225 '+name_of_the_gene
283
- e array.join(N)
284
- end
285
-
286
- # ========================================================================= #
287
- # === fasta_file?
288
- # ========================================================================= #
289
- def fasta_file?(i = :fasta_file)
290
- if @internal_hash[:fasta_file].has_key?(i)
291
- @internal_hash[:fasta_file].fetch(i)
292
- else
293
- erev 'We could not find the key called `'+simp(i.to_s)+rev+'`.'
294
- end
295
- end
296
-
297
- # ========================================================================= #
298
- # === create_fasta_file
299
- # ========================================================================= #
300
- def create_fasta_file
301
- set_save_file :default_fasta
302
- e 'Now creating a new fasta file. Will store into `'+sfile(@save_file)+'`.'
303
- _ = '>gi|12345|pir|TVHGG| some unknown protein'+N
304
- _ << string?
305
- save_file(_, @internal_hash[:save_file])
306
- end
307
-
308
- # ========================================================================= #
309
- # === return_fasta_files_in_the_log_directory
310
- # ========================================================================= #
311
- def return_fasta_files_in_the_log_directory
312
- Dir[::Bioroebe.log_dir?+'*.fa*']
313
- end
314
-
315
- # ========================================================================= #
316
- # === use_this_fasta_file
317
- #
318
- # Use a fasta file based on its position.
319
- #
320
- # For instance, fasta file at position 2 will be the second fasta file
321
- # kept in the main log directory.
322
- # ========================================================================= #
323
- def use_this_fasta_file(at_position = 1)
324
- # ======================================================================= #
325
- # We need to map the given position to the existing (local) file at hand.
326
- # ======================================================================= #
327
- this_fasta_file = return_fasta_files_in_the_log_directory[at_position.to_i - 1]
328
- if this_fasta_file
329
- assign_fasta(this_fasta_file)
330
- else
331
- erev 'Could not find any file at position '+simp(at_position.to_s)+rev+'.'
332
- erev 'Use "'+steelblue('show_fasta_files')+rev+
333
- '" to see which fasta files are available.'
334
- end
335
- end
336
-
337
- # ========================================================================= #
338
- # === show_my_fasta_file
339
- # ========================================================================= #
340
- def show_my_fasta_file
341
- e HOME_DIRECTORY_OF_USER_X+
342
- 'data/science/BIOINFORMATIK/DATA/FASTA/tardigrada_fasta.ffn'
343
- end
344
-
345
- end; end