quorum 0.5.2 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. data/.gitignore +3 -5
  2. data/.travis.yml +0 -2
  3. data/Gemfile.lock +2 -2
  4. data/HISTORY.md +12 -0
  5. data/Rakefile +13 -48
  6. data/app/models/quorum/blastn_job.rb +15 -22
  7. data/app/models/quorum/blastp_job.rb +15 -22
  8. data/app/models/quorum/blastx_job.rb +15 -22
  9. data/app/models/quorum/tblastn_job.rb +15 -22
  10. data/app/views/quorum/jobs/form/_blastn_form.html.erb +4 -4
  11. data/app/views/quorum/jobs/form/_blastp_form.html.erb +4 -4
  12. data/app/views/quorum/jobs/form/_blastx_form.html.erb +4 -4
  13. data/app/views/quorum/jobs/form/_tblastn_form.html.erb +4 -4
  14. data/app/views/quorum/jobs/templates/_blast_detailed_report_template.html.erb +6 -17
  15. data/db/migrate/20120918205556_rename_max_score_column.rb +15 -0
  16. data/lib/generators/templates/blast.rb +37 -31
  17. data/lib/quorum/version.rb +1 -1
  18. data/spec/config/quorum_settings.yml +55 -0
  19. data/spec/javascripts/fixtures/quorum_search_form.html +8 -8
  20. data/spec/javascripts/jobs_spec.js +8 -8
  21. data/spec/lib/tasks/travis.rake +120 -0
  22. data/spec/models/blastn_job_spec.rb +41 -22
  23. data/spec/models/blastp_job_spec.rb +41 -22
  24. data/spec/models/blastx_job_spec.rb +41 -22
  25. data/spec/models/job_spec.rb +1 -1
  26. data/spec/models/tblastn_job_spec.rb +41 -22
  27. data/spec/requests/jobs_spec.rb +8 -8
  28. data/spec/templates/blast_db_spec.rb +1 -1
  29. data/spec/templates/blast_spec.rb +1 -1
  30. metadata +7 -32
  31. data/spec/dummy/config/initializers/quorum_initializer.rb +0 -36
  32. data/spec/dummy/config/locales/quorum.en.yml +0 -8
  33. data/spec/dummy/config/quorum_settings.yml +0 -141
  34. data/spec/dummy/db/schema.rb +0 -213
  35. data/spec/dummy/quorum/bin/fetch +0 -115
  36. data/spec/dummy/quorum/bin/search +0 -141
  37. data/spec/dummy/quorum/blastdb/test/contigs.fa +0 -15
  38. data/spec/dummy/quorum/blastdb/test/peptides.fa +0 -4
  39. data/spec/dummy/quorum/blastdb/test.nhd +0 -2
  40. data/spec/dummy/quorum/blastdb/test.nhi +0 -0
  41. data/spec/dummy/quorum/blastdb/test.nhr +0 -0
  42. data/spec/dummy/quorum/blastdb/test.nin +0 -0
  43. data/spec/dummy/quorum/blastdb/test.nog +0 -0
  44. data/spec/dummy/quorum/blastdb/test.nsd +0 -2
  45. data/spec/dummy/quorum/blastdb/test.nsi +0 -0
  46. data/spec/dummy/quorum/blastdb/test.nsq +0 -0
  47. data/spec/dummy/quorum/blastdb/test.phd +0 -2
  48. data/spec/dummy/quorum/blastdb/test.phi +0 -0
  49. data/spec/dummy/quorum/blastdb/test.phr +0 -0
  50. data/spec/dummy/quorum/blastdb/test.pin +0 -0
  51. data/spec/dummy/quorum/blastdb/test.pog +0 -0
  52. data/spec/dummy/quorum/blastdb/test.psd +0 -2
  53. data/spec/dummy/quorum/blastdb/test.psi +0 -0
  54. data/spec/dummy/quorum/blastdb/test.psq +0 -0
  55. data/spec/dummy/quorum/lib/fetch_tools/blast_db.rb +0 -106
  56. data/spec/dummy/quorum/lib/logger.rb +0 -43
  57. data/spec/dummy/quorum/lib/search_tools/blast.rb +0 -452
  58. data/spec/dummy/quorum/lib/trollop.rb +0 -781
@@ -1,213 +0,0 @@
1
- # encoding: UTF-8
2
- # This file is auto-generated from the current state of the database. Instead
3
- # of editing this file, please use the migrations feature of Active Record to
4
- # incrementally modify your database, and then regenerate this schema definition.
5
- #
6
- # Note that this schema.rb definition is the authoritative source for your
7
- # database schema. If you need to create the application database on another
8
- # system, you should be using db:schema:load, not running all the migrations
9
- # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
- # you'll amass, the slower it'll run and the greater likelihood for issues).
11
- #
12
- # It's strongly recommended to check this file into your version control system.
13
-
14
- ActiveRecord::Schema.define(:version => 20120910180642) do
15
-
16
- create_table "quorum_blastn_job_reports", :force => true do |t|
17
- t.string "query"
18
- t.integer "query_len"
19
- t.string "hit_id"
20
- t.string "hit_def"
21
- t.string "hit_accession"
22
- t.integer "hit_len"
23
- t.integer "hsp_num"
24
- t.text "hsp_group"
25
- t.integer "bit_score"
26
- t.integer "score"
27
- t.string "evalue"
28
- t.integer "query_from"
29
- t.integer "query_to"
30
- t.integer "hit_from"
31
- t.integer "hit_to"
32
- t.string "query_frame"
33
- t.string "hit_frame"
34
- t.integer "identity"
35
- t.integer "positive"
36
- t.integer "align_len"
37
- t.text "qseq"
38
- t.text "hseq"
39
- t.text "midline"
40
- t.boolean "results"
41
- t.integer "blastn_job_id"
42
- t.datetime "created_at", :null => false
43
- t.datetime "updated_at", :null => false
44
- t.string "hit_display_id"
45
- t.integer "gaps"
46
- end
47
-
48
- create_table "quorum_blastn_jobs", :force => true do |t|
49
- t.string "expectation"
50
- t.integer "max_score"
51
- t.integer "min_bit_score"
52
- t.boolean "filter"
53
- t.boolean "gapped_alignments"
54
- t.integer "gap_opening_penalty"
55
- t.integer "gap_extension_penalty"
56
- t.text "blast_dbs"
57
- t.boolean "queue"
58
- t.integer "job_id"
59
- t.datetime "created_at", :null => false
60
- t.datetime "updated_at", :null => false
61
- end
62
-
63
- create_table "quorum_blastp_job_reports", :force => true do |t|
64
- t.string "query"
65
- t.integer "query_len"
66
- t.string "hit_id"
67
- t.string "hit_def"
68
- t.string "hit_accession"
69
- t.integer "hit_len"
70
- t.integer "hsp_num"
71
- t.text "hsp_group"
72
- t.integer "bit_score"
73
- t.integer "score"
74
- t.string "evalue"
75
- t.integer "query_from"
76
- t.integer "query_to"
77
- t.integer "hit_from"
78
- t.integer "hit_to"
79
- t.string "query_frame"
80
- t.string "hit_frame"
81
- t.integer "identity"
82
- t.integer "positive"
83
- t.integer "align_len"
84
- t.text "qseq"
85
- t.text "hseq"
86
- t.text "midline"
87
- t.boolean "results"
88
- t.integer "blastp_job_id"
89
- t.datetime "created_at", :null => false
90
- t.datetime "updated_at", :null => false
91
- t.string "hit_display_id"
92
- t.integer "gaps"
93
- end
94
-
95
- create_table "quorum_blastp_jobs", :force => true do |t|
96
- t.string "expectation"
97
- t.integer "max_score"
98
- t.integer "min_bit_score"
99
- t.boolean "filter"
100
- t.boolean "gapped_alignments"
101
- t.integer "gap_opening_penalty"
102
- t.integer "gap_extension_penalty"
103
- t.text "blast_dbs"
104
- t.boolean "queue"
105
- t.integer "job_id"
106
- t.datetime "created_at", :null => false
107
- t.datetime "updated_at", :null => false
108
- end
109
-
110
- create_table "quorum_blastx_job_reports", :force => true do |t|
111
- t.string "query"
112
- t.integer "query_len"
113
- t.string "hit_id"
114
- t.string "hit_def"
115
- t.string "hit_accession"
116
- t.integer "hit_len"
117
- t.integer "hsp_num"
118
- t.text "hsp_group"
119
- t.integer "bit_score"
120
- t.integer "score"
121
- t.string "evalue"
122
- t.integer "query_from"
123
- t.integer "query_to"
124
- t.integer "hit_from"
125
- t.integer "hit_to"
126
- t.string "query_frame"
127
- t.string "hit_frame"
128
- t.integer "identity"
129
- t.integer "positive"
130
- t.integer "align_len"
131
- t.text "qseq"
132
- t.text "hseq"
133
- t.text "midline"
134
- t.boolean "results"
135
- t.integer "blastx_job_id"
136
- t.datetime "created_at", :null => false
137
- t.datetime "updated_at", :null => false
138
- t.string "hit_display_id"
139
- t.integer "gaps"
140
- end
141
-
142
- create_table "quorum_blastx_jobs", :force => true do |t|
143
- t.string "expectation"
144
- t.integer "max_score"
145
- t.integer "min_bit_score"
146
- t.boolean "filter"
147
- t.boolean "gapped_alignments"
148
- t.integer "gap_opening_penalty"
149
- t.integer "gap_extension_penalty"
150
- t.text "blast_dbs"
151
- t.boolean "queue"
152
- t.integer "job_id"
153
- t.datetime "created_at", :null => false
154
- t.datetime "updated_at", :null => false
155
- end
156
-
157
- create_table "quorum_jobs", :force => true do |t|
158
- t.text "sequence", :null => false
159
- t.text "na_sequence"
160
- t.text "aa_sequence"
161
- t.string "sequence_hash"
162
- t.datetime "created_at", :null => false
163
- t.datetime "updated_at", :null => false
164
- end
165
-
166
- create_table "quorum_tblastn_job_reports", :force => true do |t|
167
- t.string "query"
168
- t.integer "query_len"
169
- t.string "hit_id"
170
- t.string "hit_def"
171
- t.string "hit_accession"
172
- t.integer "hit_len"
173
- t.integer "hsp_num"
174
- t.text "hsp_group"
175
- t.integer "bit_score"
176
- t.integer "score"
177
- t.string "evalue"
178
- t.integer "query_from"
179
- t.integer "query_to"
180
- t.integer "hit_from"
181
- t.integer "hit_to"
182
- t.string "query_frame"
183
- t.string "hit_frame"
184
- t.integer "identity"
185
- t.integer "positive"
186
- t.integer "align_len"
187
- t.text "qseq"
188
- t.text "hseq"
189
- t.text "midline"
190
- t.boolean "results"
191
- t.integer "tblastn_job_id"
192
- t.datetime "created_at", :null => false
193
- t.datetime "updated_at", :null => false
194
- t.string "hit_display_id"
195
- t.integer "gaps"
196
- end
197
-
198
- create_table "quorum_tblastn_jobs", :force => true do |t|
199
- t.string "expectation"
200
- t.integer "max_score"
201
- t.integer "min_bit_score"
202
- t.boolean "filter"
203
- t.boolean "gapped_alignments"
204
- t.integer "gap_opening_penalty"
205
- t.integer "gap_extension_penalty"
206
- t.text "blast_dbs"
207
- t.boolean "queue"
208
- t.integer "job_id"
209
- t.datetime "created_at", :null => false
210
- t.datetime "updated_at", :null => false
211
- end
212
-
213
- end
@@ -1,115 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- $LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))
4
-
5
- require 'trollop'
6
- require 'fetch_tools/blast_db'
7
-
8
- FETCH_TOOLS = {
9
- "blastdbcmd" => ["blastdbcmd"]
10
- }
11
-
12
- module Quorum
13
- #
14
- # Parse Options for Quorum Fetch
15
- #
16
- class Fetch
17
-
18
- def initialize
19
- opts = Trollop::options do
20
- text <<-HEAD
21
-
22
- Quorum
23
-
24
- A flexible bioinformatics search tool.
25
-
26
- Options:
27
-
28
- HEAD
29
-
30
- # Fetch tool
31
- opt :fetch_tool, "Fetch tool to execute. Available tools: " <<
32
- "#{FETCH_TOOLS.keys.join(', ')}", :type => :string,
33
- :required => true, :short => "-f"
34
-
35
- # General settings
36
- opt :log_directory, "Path to log directory", :type => :string,
37
- :required => true, :short => "-l"
38
- opt :tmp_directory, "Path to tmp directory", :type => :string,
39
- :required => true, :short => "-m"
40
-
41
- # Global settings
42
- opt :fetch_database, "Path to fetch tool database", :type => :string,
43
- :short => "-d"
44
- opt :fetch_database_names, "Semicolon delimited database names",
45
- :type => :string, :short => "-n"
46
-
47
- # Algorithm specific opts
48
- opt :blast_hit_id, "Blast hit id", :type => :string, :short => "-b"
49
- opt :blast_hit_display_id, "Blast hit display id", :type => :string,
50
- :short => "-s"
51
- opt :blast_algo, "Blast algorithm", :type => :string, :short => "-a"
52
- end
53
-
54
- @args = {} # Contains valid opts.
55
-
56
- ## Additional opt validation. ##
57
-
58
- unless FETCH_TOOLS.keys.include?(opts[:fetch_tool].downcase)
59
- Trollop::die :fetch_tool, "fetch_tool not found\n" <<
60
- "Available tools: " + FETCH_TOOLS.keys.join(", ")
61
- end
62
-
63
- @args[:fetch_tool] = opts[:fetch_tool].downcase
64
-
65
- unless opts[:fetch_database] && Dir.exists?(opts[:fetch_database])
66
- Trollop::die :fetch_database, "fetch tool database not found\n" <<
67
- "Supplied directory: " + opts[:fetch_database]
68
- end
69
-
70
- @args[:fetch_database] = opts[:fetch_database]
71
- @args[:fetch_database_names] = opts[:fetch_database_names]
72
-
73
- unless Dir.exists?(opts[:log_directory])
74
- Trollop::die :log_directory, "log directory not found\n" <<
75
- "Supplied directory: " + opts[:log_directory]
76
- end
77
-
78
- @args[:log_directory] = opts[:log_directory]
79
- @args[:tmp_directory] = opts[:tmp_directory]
80
- @args[:blast_hit_id] = opts[:blast_hit_id]
81
- @args[:blast_hit_display_id] = opts[:blast_hit_display_id]
82
- @args[:blast_algo] = opts[:blast_algo]
83
-
84
- ## Check System Dependancies ##
85
-
86
- check_dependencies
87
-
88
- ## Execute fetch tool ##
89
-
90
- if @args[:fetch_tool].include? "blastdbcmd"
91
- blast = Quorum::FetchTools::BlastDb.new(@args)
92
- blast.execute_blast_db_cmd
93
- end
94
- end
95
-
96
- #
97
- # Check system dependencies.
98
- #
99
- def check_dependencies
100
- FETCH_TOOLS[@args[:fetch_tool]].each do |f|
101
- system("which #{f} > /dev/null 2>&1")
102
- if $?.exitstatus > 0
103
- Trollop::die "Quorum dependency not found for tool " <<
104
- "#{@args[:fetch_tool].to_s}. Please add `#{f}` to your PATH."
105
- end
106
- end
107
- end
108
-
109
- end
110
- end
111
-
112
- if __FILE__ == $0
113
- Quorum::Fetch.new
114
- end
115
-
@@ -1,141 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- $LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))
4
-
5
- require 'trollop'
6
- require 'active_record'
7
- require 'search_tools/blast'
8
-
9
- # Quorum search tools and dependencies.
10
- SEARCH_TOOLS = {
11
- "blastn" => ["blastn"],
12
- "blastx" => ["blastx"],
13
- "tblastn" => ["tblastn"],
14
- "blastp" => ["blastp"]
15
- }
16
-
17
- module Quorum
18
- #
19
- # Parse Options for Quorum Search Tools
20
- #
21
- class Search
22
-
23
- def initialize
24
- opts = Trollop::options do
25
- text <<-HEAD
26
-
27
- Quorum
28
-
29
- A flexible bioinformatics search tool.
30
-
31
- Options:
32
-
33
- HEAD
34
-
35
- # Search tool
36
- opt :search_tool, "Search tool to execute. Available tools: " <<
37
- "#{SEARCH_TOOLS.keys.join(', ')}", :type => :string,
38
- :required => true, :short => "-s"
39
-
40
- # General settings
41
- opt :log_directory, "Path to log directory", :type => :string,
42
- :required => true, :short => "-l"
43
- opt :tmp_directory, "Path to tmp directory", :type => :string,
44
- :required => true, :short => "-m"
45
-
46
- # ActiveRecord database settings
47
- opt :id, "Database record ID", :type => :int, :required => true,
48
- :short => "-i"
49
- opt :database, "Database name", :type => :string, :required => true,
50
- :short => "-d"
51
- opt :database_adapter, "ActiveRecord database adapter",
52
- :type => :string, :required => true, :short => "-a"
53
- opt :database_host, "Database host", :type => :string,
54
- :required => true, :short => "-k"
55
- opt :database_user, "Database username", :type => :string,
56
- :required => true, :short => "-u"
57
- opt :database_password, "Database password", :type => :string,
58
- :required => true, :short => "-p"
59
-
60
- # Global settings
61
- opt :search_database, "Path to search tool database", :type => :string,
62
- :short => "-b"
63
- opt :threads, "Number of threads to spawn for search tool",
64
- :type => :int, :short => "-t"
65
- end
66
-
67
- @args = {} # Contains valid opts.
68
-
69
- ## Additional opt validation. ##
70
-
71
- unless SEARCH_TOOLS.keys.include?(opts[:search_tool].downcase)
72
- Trollop::die :search_tool, "search_tool not found\n" <<
73
- "Available search tools: " + SEARCH_TOOLS.keys.join(", ")
74
- end
75
-
76
- @args[:search_tool] = opts[:search_tool].downcase
77
-
78
- unless opts[:search_database] && Dir.exists?(opts[:search_database])
79
- Trollop::die :search_database, "search tool database not found\n" <<
80
- "Supplied directory: " + opts[:search_database]
81
- end
82
-
83
- @args[:search_database] = opts[:search_database]
84
-
85
- @args[:id] = opts[:id]
86
- @args[:threads] = opts[:threads]
87
-
88
- unless Dir.exists?(opts[:log_directory])
89
- Trollop::die :log_directory, "log directory not found\n" <<
90
- "Supplied directory: " + opts[:log_directory]
91
- end
92
-
93
- @args[:log_directory] = opts[:log_directory]
94
- @args[:tmp_directory] = opts[:tmp_directory]
95
-
96
- ## Check System Dependancies ##
97
-
98
- check_dependencies
99
-
100
- ## Establish ActiveRecord Connection ##
101
-
102
- begin
103
- ActiveRecord::Base.establish_connection(
104
- :adapter => opts[:database_adapter],
105
- :host => opts[:database_host],
106
- :username => opts[:database_user],
107
- :password => opts[:database_password],
108
- :database => opts[:database]
109
- )
110
- rescue Exception => e
111
- Trollop::die puts e.message
112
- end
113
-
114
- ## Execute search tool ##
115
-
116
- if @args[:search_tool].include? "blast"
117
- blast = Quorum::SearchTools::Blast.new(@args)
118
- blast.execute_blast
119
- end
120
- end
121
-
122
- #
123
- # Check system dependencies.
124
- #
125
- def check_dependencies
126
- SEARCH_TOOLS[@args[:search_tool]].each do |b|
127
- system("which #{b} > /dev/null 2>&1")
128
- if $?.exitstatus > 0
129
- Trollop::die "Quorum dependency not found for tool " <<
130
- "#{@args[:search_tool].to_s}. Please add `#{b}` to your PATH."
131
- end
132
- end
133
- end
134
-
135
- end
136
- end
137
-
138
- if __FILE__ == $0
139
- Quorum::Search.new
140
- end
141
-
@@ -1,15 +0,0 @@
1
- >TOG900080
2
- TGATAGGATAATTCTAGACAAAACATTAGCCGATCAAGTGTCATCATGGAAAAGCAGCAGGGGCCTTAGTGATACAGTGGTGACTGATCATGCTTGTTCTGGGGAAACATGCTCGTACTACGCAATTGGAGATGTATTTATTTGTGAAAAGACTGGACAAGTTCATGTTTGTGACGAAACATGTAGGGAAGTAGTAATGGATCCCACCAACGAGCTTTTGGTCTGTACAATATCTGGCCACTGTTTTGACAGATTGCTATCACCTGCTGAAATGGAGCCTGATGCTGAGCAGCAGCAAGGTGGTGCGGCAGATGAGGCAGAACCGTTTATGGGATCTGGCCGTTTTGCACGGGCTTATTTGCTGGGATACAATTGTGCTGATGAAAAGGAGCTTGAAGCTACTTTGAGGTTTTGCTGATCCCTATTGGCCCTTCTGGAGTGGATGATCTCATGTCTCAGCATTTACCTATTTAAGATCAAATAAATCGGGTTTCCTTTTCGTGTTTCTCTTGGCATAAGAATGTTTGATTAGATCTAGATTATGAAACTCTAATCGTCTTCTATATTAATAATTGTATGCTTAAATTTATAGTTGAAATTCCATTGATGAATTTTTCTT
3
- >reverse translation of ADA84676.1 protein L-isoaspartyl methyltransferase 1 [Cicer arietinum] to a 687 base sequence of most likely codons.
4
- atggaacagtattggagcggcagcgcgattaacgaaaacaaaggcatggtggaaaacctg
5
- cagcgctatggcattattaaaagcagcaaagtggcggaaaccatggaaaaaattgatcgc
6
- ggcctgtttgtgccgaacggcgtgcagccgtatattgatagcccgatgagcattggctat
7
- aacgcgaccattagcgcgccgcatatgcatgcgacctgcctgcagctgctggaaaactat
8
- ctgcagccgggcatgcatgcgctggatgtgggcagcggcaccggctatctgaccgcgtgc
9
- tttgcgatgatggtgggcccgaacggccgcgcggtgggcgtggaacatattccggaactg
10
- gtgagctttagcattaacaacattgaaaaaagcgcggcggcgccgcagctgaaagatggc
11
- agcctgagcgtgcatgaaggcgatggccgccagggctggccggaatttgcgacctatgat
12
- gcgattcatgtgggcgcggcggcgccggaaattccgcagccgctgattgatcagctgaaa
13
- accggcggccgcatgattattccggtgggcaacgtgtttcaggatctgaaagtggtggat
14
- aaaaacagcgatggcagcattagcattcgcaccgaaaccagcgtgcgctatgtgccgctg
15
- accagcaaagaagcgcagctgaaagaa
@@ -1,4 +0,0 @@
1
- >ADA84676.1 protein L-isoaspartyl methyltransferase 1 [Cicer arietinum]
2
- MEQYWSGSAINENKGMVENLQRYGIIKSSKVAETMEKIDRGLFVPNGVQPYIDSPMSIGYNATISAPHMHATCLQLLENYLQPGMHALDVGSGTGYLTACFAMMVGPNGRAVGVEHIPELVSFSINNIEKSAAAPQLKDGSLSVHEGDGRQGWPEFATYDAIHVGAAAPEIPQPLIDQLKTGGRMIIPVGNVFQDLKVVDKNSDGSISIRTETSVRYVPLTSKEAQLKE
3
- >VIRT10447
4
- TVLPHLPHHLAAAQHQAPFQQVIAICQNSGQILYRPKARWWDPLLLPYMFRHKHELVQSFHK
@@ -1,2 +0,0 @@
1
- 34432766131
2
- 8824380950
Binary file
Binary file
Binary file
Binary file
@@ -1,2 +0,0 @@
1
- gnl|bl_ord_id|00
2
- gnl|bl_ord_id|11
Binary file
Binary file
@@ -1,2 +0,0 @@
1
- 24330897691
2
- 28413460680
Binary file
Binary file
Binary file
Binary file
@@ -1,2 +0,0 @@
1
- gnl|bl_ord_id|00
2
- gnl|bl_ord_id|11
Binary file
Binary file
@@ -1,106 +0,0 @@
1
- $LOAD_PATH.unshift(File.expand_path("../../", __FILE__))
2
-
3
- require 'logger'
4
-
5
- module Quorum
6
- module FetchTools
7
- #
8
- # Blast DB Fetch Tool
9
- #
10
- class BlastDb
11
-
12
- # blastdbcmd -dbtype
13
- DB_TYPE = {
14
- "blastn" => "nucl",
15
- "blastx" => "prot",
16
- "tblastn" => "nucl",
17
- "blastp" => "prot"
18
- }
19
-
20
- private
21
-
22
- def initialize(args)
23
- @tool = args[:fetch_tool]
24
- @entry = args[:blast_hit_id]
25
- @hit_display_id = args[:blast_hit_display_id]
26
- @blast_algo = args[:blast_algo]
27
- @log_directory = args[:log_directory]
28
- @tmp_directory = args[:tmp_directory]
29
- @fetch_database = args[:fetch_database]
30
- @databases = args[:fetch_database_names]
31
-
32
- @logger = Quorum::Logger.new(@log_directory)
33
-
34
- @db = @databases.split(';')
35
- @db.map! { |d| File.join(@fetch_database, d) }
36
-
37
- @db_type = DB_TYPE[@blast_algo]
38
- @db_type ||= 'guess'
39
- end
40
-
41
- #
42
- # Generate the blastdbcmd(s).
43
- #
44
- def generate_blast_db_cmds
45
- @cmds = []
46
- @db.each do |d|
47
- blastdbcmd = "blastdbcmd " <<
48
- "-db '#{d}' " <<
49
- "-dbtype '#{@db_type}' " <<
50
- "-entry '#{@entry}' "
51
- @cmds << blastdbcmd
52
- end
53
- end
54
-
55
- #
56
- # Parse the blastdbcmd returned sequence(s) and delete if @hit_display_id
57
- # is not present.
58
- #
59
- def parse_and_send_results
60
- seqs = @seqs.split('>')
61
- seqs.delete_if { |s| s.empty? || !s.include?(@hit_display_id) }
62
- if seqs.length != 1
63
- @logger.log(
64
- "Quorum::FetchTools::BlastDb#parse_and_send_results",
65
- "blastdbcmd returned #{seqs.length} sequence(s). Please ensure " <<
66
- "your Blast database source FASTA headers are unique across ALL " <<
67
- "databases. See the entry above for details."
68
- )
69
- "An error occurred while processing your request."
70
- else
71
- ">" << seqs.first
72
- end
73
- end
74
-
75
- public
76
-
77
- #
78
- # Execute the blastdbcmd(s) and return the matching sequence.
79
- #
80
- # To make Blast execute as quickly as possible, each selected
81
- # algorithm blasts against all supplied databases at once.
82
- #
83
- # See quorum/lib/search_tools/blast.rb for more information.
84
- #
85
- # One consequence of this is not knowing which Blast database to use
86
- # when retrieving a hit sequence via blastdbcmd.
87
- #
88
- # See blastdbcmd -help for more information.
89
- #
90
- # To work around this issue, simply execute blastdbcmd against all
91
- # Blast databases and filter on hit_display_id.
92
- #
93
- def execute_blast_db_cmd
94
- generate_blast_db_cmds
95
- @logger.log("NCBI Blast", @cmds.join('; '))
96
-
97
- @seqs = ""
98
- @cmds.each { |c| @seqs << `#{c} 2> /dev/null` }
99
-
100
- seq = parse_and_send_results
101
- $stdout.print seq
102
- end
103
-
104
- end
105
- end
106
- end
@@ -1,43 +0,0 @@
1
- module Quorum
2
- class Logger
3
-
4
- def initialize(dir)
5
- @log_directory = dir
6
- @log_file = "quorum.log"
7
- end
8
-
9
- #
10
- # Write to log file and exit if exit_status is present.
11
- #
12
- def log(program, message, exit_status = nil, files = nil)
13
- File.open(File.join(@log_directory, @log_file), "a") do |log|
14
- log.puts ""
15
- log.puts Time.now.to_s + " " + program
16
- log.puts message
17
- log.puts ""
18
- end
19
-
20
- if exit_status
21
- remove_files(files) unless files.nil?
22
- exit exit_status.to_i
23
- end
24
- end
25
-
26
- private
27
-
28
- #
29
- # Removes instance files.
30
- #
31
- def remove_files(files)
32
- if Dir.glob(files).empty?
33
- log(
34
- "remove_files",
35
- "Unable to remove #{files}"
36
- )
37
- else
38
- `rm #{files}`
39
- end
40
- end
41
-
42
- end
43
- end