Module: ViralSeq::Muscle
- Defined in:
- lib/viral_seq/muscle.rb
Overview
alignment using MUSCLE alignment program
Class Method Summary collapse
-
.align(ref_seq = "", test_seq = "", algorithm = :PPP, path_to_muscle = false) ⇒ Array
align a sequence with reference sequence Strings.
-
.check_muscle?(path_to_muscle) ⇒ boolean
check if path_to_muscle is correct, prompt error messages if MUSCLE is not found.
Class Method Details
.align(ref_seq = "", test_seq = "", algorithm = :PPP, path_to_muscle = false) ⇒ Array
align a sequence with reference sequence Strings
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 |
# File 'lib/viral_seq/muscle.rb', line 42 def self.align(ref_seq = "", test_seq = "", algorithm = :PPP, path_to_muscle = false) temp_dir = Dir.home temp_name = "_" + SecureRandom.alphanumeric temp_file = File.join(temp_dir, temp_name) temp_aln = File.join(temp_dir, (temp_name + "_aln")) name = ">test" temp_in = File.open(temp_file,"w") temp_in.puts ">ref" temp_in.puts ref_seq temp_in.puts name temp_in.puts test_seq temp_in.close if path_to_muscle unless ViralSeq::Muscle.check_muscle?(path_to_muscle) File.unlink(temp_file) return nil; end print `#{path_to_muscle} -in #{temp_file} -out #{temp_aln} -quiet` else if MuscleBio::VERSION.to_f < 0.5 MuscleBio.run("muscle -in #{temp_file} -out #{temp_aln} -quiet") else MuscleBio.exec(temp_file, temp_aln, algorithm) end end aln_seq_hash = ViralSeq::SeqHash.fa(temp_aln).dna_hash File.unlink(temp_file) File.unlink(temp_aln) return [aln_seq_hash[">ref"], aln_seq_hash[">test"]] end |
.check_muscle?(path_to_muscle) ⇒ boolean
check if path_to_muscle is correct, prompt error messages if MUSCLE is not found.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/viral_seq/muscle.rb', line 11 def self.check_muscle?(path_to_muscle) begin `#{path_to_muscle} -version` return true rescue Errno::ENOENT puts " Error: MUSCLE is not found for at the provided {path_to_muscle}!! MUSLCE can be download at http://www.drive5.com/muscle Add MUSCLE excutable path to $PATH using $ export PATH=$PATH:/path/to/muscle or provide path_to_MUSCLE in the function arguments\n " return false end end |