Class: Quorum::BuildBlastDB

Inherits:
Object
  • Object
show all
Defined in:
lib/tasks/blastdb/build_blast_db.rb

Overview

Build Blast Database(s)

Constant Summary collapse

VALID_TYPES =

Valid values for @type.

["both", "prot", "nucl"]
DEPENDENCIES =

Blast dependencies

["makeblastdb"]
GZIP =

File bz2 and gz extensions.

/\.(tgz$)|(tar.gz$)/
BZIP =
/\.(tbz$)|(tar.bz2$)/

Instance Method Summary collapse

Instance Method Details

#build_blast_db_dataObject

Parse Blast database data.



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
# File 'lib/tasks/blastdb/build_blast_db.rb', line 155

def build_blast_db_data
  # Create necessary directories and return.
  if @empty
    make_directories
    return
  end

  if @dir.blank?
    raise "DIR must be set to continue. Execute `rake -D` for more information."
  end

  unless VALID_TYPES.include?(@type)
    raise "Unknown type: #{@type}. " <<
      "Please provide one: both, nucl or prot."
  end

  check_dependencies

  make_directories

  begin
    @dir.split(':').each do |d|
      unless File.directory?(d)
        raise "Directory not found: #{d}"
      end

      @data = Dir.glob("#{d}/*.{tgz,tar.gz,tbz,tar.bz2}")

      if @data.blank?
        raise "Data not found. Please check your directory and try " <<
        "again.\nDirectory Entered: #{d}"
      end

      @data.each do |s|
        if s =~ GZIP
          files = `tar -tzf #{s}`
          flag  = "z"
        elsif s =~ BZIP
          files = `tar -tjf #{s}`
          flag  = "j"
        end
        files = files.split(/\n/)
        files.each do |f|
          if f.include?(@prot_file)
            file_name = create_file_name(f, @blastdb_dir)
            extract_files(s, f, flag, File.join(@blastdb_dir, file_name, "peptides.fa"))
          elsif f.include?(@nucl_file)
            file_name = create_file_name(f, @blastdb_dir)
            extract_files(s, f, flag, File.join(@blastdb_dir, file_name, "contigs.fa"))
          elsif f.include?("gff")
            file_name = create_file_name(f, @gff_dir)
            extract_files(s, f, flag, File.join(@gff_dir, file_name, "annots.gff"))
          end
        end
      end
    end
    build_blast_db(@blastdb_dir)
  rescue Exception => e
    # Remove empty directories.
    `rm -rf #{@blastdb_dir}/*` if File.directory?(@blastdb_dir)
    `rm -rf #{@gff_dir}/*` if File.directory?(@gff_dir)
    raise e
  end
  readme
end