Module: ViralSeq::Muscle

Defined in:
lib/viral_seq/muscle.rb

Overview

alignment using MUSCLE alignment program

Class Method Summary collapse

Class Method Details

.align(ref_seq = "", test_seq = "", algorithm = :PPP, path_to_muscle = false) ⇒ Array

align a sequence with reference sequence Strings

Examples:

seq1 = 'AAGGCGTAGGAC'
seq2 = 'AAGCTTAGGACG'
aligned_seqs = ViralSeq::Muscle.align(seq1,seq2)
=> ["AAGGCGTAGGAC-", "-AAGCTTAGGACG"]

Parameters:

  • ref_seq (String) (defaults to: "")

    reference sequence

  • test_seq (String) (defaults to: "")

    test sequence

  • algorithm (Symbol) (defaults to: :PPP)

    , algorithm for MUSCLE5 only. Choose from :PPP or :Super5.

  • path_to_muscle (String) (defaults to: false)

    , path to MUSCLE excutable. if not provided (as default), it will use RubyGem::MuscleBio

  • path_to_muscle (String) (defaults to: false)

    , path to MUSCLE excutable. if not provided (as default), it will use RubyGem::MuscleBio

Returns:

  • (Array)

    a pair of [:ref_seq_aligned, :test_seq_aligned] or nil if the cannot find MUSCLE excutable



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.

Parameters:

  • path_to_muscle (String)

    path to muscle excutable

Returns:

  • (boolean)


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