Class: Genfrag::App::IndexCommand::DB
- Inherits:
-
Object
- Object
- Genfrag::App::IndexCommand::DB
- Defined in:
- lib/genfrag/app/index_command/db.rb
Instance Attribute Summary collapse
-
#freq_lookup ⇒ Object
Returns the value of attribute freq_lookup.
-
#input_filenames ⇒ Object
Returns the value of attribute input_filenames.
-
#normalized_fasta ⇒ Object
Returns the value of attribute normalized_fasta.
-
#ops ⇒ Object
an OpenStruct of the options.
Instance Method Summary collapse
- #close ⇒ Object
- #close_csv ⇒ Object
- #close_sqlite ⇒ Object
-
#initialize(ops, input_filenames) ⇒ DB
constructor
A new instance of DB.
- #sc ⇒ Object
- #write_entry_to_fasta(normalized_fasta_id, seq, definitions) ⇒ Object
- #write_entry_to_fasta_csv(normalized_fasta_id, seq, definitions) ⇒ Object
- #write_entry_to_fasta_sqlite(normalized_fasta_id, seq, definitions) ⇒ Object
- #write_entry_to_freq(i, size, str) ⇒ Object
- #write_entry_to_freq_csv(i, size, str) ⇒ Object
- #write_entry_to_freq_sqlite(i, size, str) ⇒ Object
- #write_headers ⇒ Object
- #write_headers_csv ⇒ Object
- #write_headers_sqlite ⇒ Object
Constructor Details
#initialize(ops, input_filenames) ⇒ DB
Returns a new instance of DB.
12 13 14 15 16 17 18 |
# File 'lib/genfrag/app/index_command/db.rb', line 12 def initialize( ops, input_filenames ) @normalized_fasta = nil @freq_lookup = nil @ops = ops @input_filenames = input_filenames end |
Instance Attribute Details
#freq_lookup ⇒ Object
Returns the value of attribute freq_lookup.
10 11 12 |
# File 'lib/genfrag/app/index_command/db.rb', line 10 def freq_lookup @freq_lookup end |
#input_filenames ⇒ Object
Returns the value of attribute input_filenames.
8 9 10 |
# File 'lib/genfrag/app/index_command/db.rb', line 8 def input_filenames @input_filenames end |
#normalized_fasta ⇒ Object
Returns the value of attribute normalized_fasta.
9 10 11 |
# File 'lib/genfrag/app/index_command/db.rb', line 9 def normalized_fasta @normalized_fasta end |
#ops ⇒ Object
an OpenStruct of the options
7 8 9 |
# File 'lib/genfrag/app/index_command/db.rb', line 7 def ops @ops end |
Instance Method Details
#close ⇒ Object
88 89 90 |
# File 'lib/genfrag/app/index_command/db.rb', line 88 def close self.send("close_#{sc}") end |
#close_csv ⇒ Object
95 96 97 98 |
# File 'lib/genfrag/app/index_command/db.rb', line 95 def close_csv @normalized_fasta.close @freq_lookup.close end |
#close_sqlite ⇒ Object
92 93 |
# File 'lib/genfrag/app/index_command/db.rb', line 92 def close_sqlite end |
#sc ⇒ Object
20 21 22 |
# File 'lib/genfrag/app/index_command/db.rb', line 20 def sc @ops.sqlite ? 'sqlite' : 'csv' end |
#write_entry_to_fasta(normalized_fasta_id, seq, definitions) ⇒ Object
62 63 64 |
# File 'lib/genfrag/app/index_command/db.rb', line 62 def write_entry_to_fasta(normalized_fasta_id, seq, definitions) self.send("write_entry_to_fasta_#{sc}", normalized_fasta_id, seq, definitions) end |
#write_entry_to_fasta_csv(normalized_fasta_id, seq, definitions) ⇒ Object
70 71 72 |
# File 'lib/genfrag/app/index_command/db.rb', line 70 def write_entry_to_fasta_csv(normalized_fasta_id, seq, definitions) @normalized_fasta.puts [normalized_fasta_id,definitions.join('!!-genfrag-!!'),seq].join("\t") end |
#write_entry_to_fasta_sqlite(normalized_fasta_id, seq, definitions) ⇒ Object
66 67 68 |
# File 'lib/genfrag/app/index_command/db.rb', line 66 def write_entry_to_fasta_sqlite(normalized_fasta_id, seq, definitions) @normalized_fasta.execute( "insert into db_normalized_fasta values ( ?, ?, ? )", normalized_fasta_id, definitions.join('!!-genfrag-!!'), seq ) end |
#write_entry_to_freq(i, size, str) ⇒ Object
75 76 77 |
# File 'lib/genfrag/app/index_command/db.rb', line 75 def write_entry_to_freq(i, size, str) self.send("write_entry_to_freq_#{sc}", i, size, str) end |
#write_entry_to_freq_csv(i, size, str) ⇒ Object
83 84 85 |
# File 'lib/genfrag/app/index_command/db.rb', line 83 def write_entry_to_freq_csv(i, size, str) @freq_lookup.puts [i,size,str].join("\t") end |
#write_entry_to_freq_sqlite(i, size, str) ⇒ Object
79 80 81 |
# File 'lib/genfrag/app/index_command/db.rb', line 79 def write_entry_to_freq_sqlite(i, size, str) @freq_lookup.execute( "insert into db_freq_lookup values ( ?, ?, ? )", i, size, str ) end |
#write_headers ⇒ Object
25 26 27 |
# File 'lib/genfrag/app/index_command/db.rb', line 25 def write_headers self.send("write_headers_#{sc}") end |
#write_headers_csv ⇒ Object
54 55 56 57 58 59 |
# File 'lib/genfrag/app/index_command/db.rb', line 54 def write_headers_csv @normalized_fasta = File.new(File.join(@ops.outdir,Genfrag.name_normalized_fasta(@input_filenames,@ops.filefasta) + '.tdf'), 'w') @normalized_fasta.puts %w(id Definitions Sequence).join("\t") @freq_lookup = File.new( File.join(@ops.outdir,Genfrag.name_freq_lookup(@input_filenames,@ops.filefasta,@ops.filelookup,@ops.re5,@ops.re3) + '.tdf'), 'w') @freq_lookup.puts %w(id Size Positions).join("\t") end |
#write_headers_sqlite ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/genfrag/app/index_command/db.rb', line 29 def write_headers_sqlite @normalized_fasta = SQLite3::Database.new( File.join(@ops.outdir, Genfrag.name_normalized_fasta(@input_filenames,@ops.filefasta) + '.db') ) sql = <<-SQL drop table if exists db_normalized_fasta; create table db_normalized_fasta ( id integer, definitions text, sequence text ); create unique index db_normalized_fasta_idx on db_normalized_fasta(id); SQL @normalized_fasta.execute_batch( sql ) @freq_lookup = SQLite3::Database.new( File.join(@ops.outdir, Genfrag.name_freq_lookup(@input_filenames,@ops.filefasta,@ops.filelookup,@ops.re5,@ops.re3) + '.db') ) sql = <<-SQL drop table if exists db_freq_lookup; create table db_freq_lookup ( id integer, size integer, positions text ); create unique index db_freq_lookup_idx on db_freq_lookup(id); SQL @freq_lookup.execute_batch( sql ) end |