Module: Qu::Cmdwrapper

Defined in:
lib/qu/cmdwrapper.rb,
lib/qu/cmdwrapper/cmd.rb,
lib/qu/cmdwrapper/version.rb

Defined Under Namespace

Classes: ShellError

Constant Summary collapse

BIN_ROOT =
File.join(__dir__, 'ext_bin')
BIN_PATH =
File.join(BIN_ROOT, Utils::platform_os, Utils::platform_bit.to_s)
THERMO_PATH =
File.join(__dir__, 'primer3_config') + '/'
VERSION =
"1.0.0"

Class Method Summary collapse

Class Method Details

.faToTwoBit(fasta, twobit) ⇒ Object



41
42
43
44
# File 'lib/qu/cmdwrapper/cmd.rb', line 41

def faToTwoBit(fasta, twobit)
  cmd = File.join(BIN_PATH, 'faToTwoBit')
  `#{cmd} #{fasta} #{twobit}`
end

.get_binding_seq_list(binding_range_list, twobit_file) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/qu/cmdwrapper/cmd.rb', line 66

def get_binding_seq_list(binding_range_list, twobit_file) 
  amp_seq_list = []
  
  return amp_seq_list if binding_range_list.empty?

  begin
    fh = Tempfile.new('binding_range_list')
    fh.write(binding_range_list.join("\n"))
    fh.close
    amp_seq_list = twoBitToFa(fh.path, twobit_file)
  ensure
    fh.unlink
  end
  return amp_seq_list   
end

.ntthal(s1, s2 = nil, mv = 50, dv = 1.5, d = 50, n = 0.25, mode = 'ANY') ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/qu/cmdwrapper/cmd.rb', line 30

def ntthal(s1, s2=nil, mv=50, dv=1.5, d=50, n=0.25, mode='ANY')
  cmd = File.join(BIN_PATH, 'ntthal')
  if s2
    tm = `#{cmd} -mv #{mv} -dv #{dv} -d #{d} -n #{n} -s1 #{s1} -s2 #{s2} -r -path #{THERMO_PATH} -a #{mode}`
  else
    tm = `#{cmd} -mv #{mv} -dv #{dv} -d #{d} -n #{n} -s1 #{s1} -r -path #{THERMO_PATH} -a HAIRPIN`
  end

  return tm.to_f
end

.primer3_core(p3_input_file) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/qu/cmdwrapper/cmd.rb', line 16

def primer3_core(p3_input_file)
  begin
    cmd = File.join(BIN_PATH, 'primer3_core')
    begin
      return system_quietly("#{cmd} #{File.realpath(p3_input_file)}")
    rescue ShellError
      return ''
    end
  rescue IOError
    $stderr.puts "Primer3 input file not exists: #{p3_input_file}"
    exit
  end
end

.system_quietly(*cmd) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/qu/cmdwrapper/cmd.rb', line 84

def system_quietly(*cmd)
  exit_status=nil
  err=nil
  out=nil
  Open3.popen3(*cmd) do |stdin, stdout, stderr, wait_thread|
    err = stderr.gets(nil)
    out = stdout.gets(nil)
    [stdin, stdout, stderr].each{|stream| stream.send('close')}
    exit_status = wait_thread.value
  end
  if exit_status.to_i > 0
    err = err.chomp if err
    raise ShellError, err
  elsif out
    return out.chomp
  else
    return true
  end
end

.twoBitToFa(seq_list_file, twobit_file) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/qu/cmdwrapper/cmd.rb', line 46

def twoBitToFa(seq_list_file, twobit_file)
  cmd = File.join(BIN_PATH, 'twoBitToFa')

  records = []
  begin
    out_file = Tempfile.new('twobit')
    `#{cmd} -seqList=#{seq_list_file} #{twobit_file} #{out_file.path}`
    out_file.rewind

    Bio::FlatFile.new(Bio::FastaFormat, out_file).each do |record|
      records << record.naseq.seq
    end
  ensure
    out_file.close
    out_file.unlink
  end

  return records
end