Module: Bio::PL::GFF3

Defined in:
lib/bio-gff3-pltools/filtering.rb

Class Method Summary collapse

Class Method Details

.filter_data(data, filter_string, options = {}) ⇒ Object

Runs the gff3-ffetch utility with the specified parameters while passing data to its stdin. Options include :output and :at_most.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/bio-gff3-pltools/filtering.rb', line 29

def self.filter_data data, filter_string, options = {}
  output_option = nil
  output = nil
  if !options[:output].nil?
    output_option = "--output #{options[:output]}"
  end
  if !options[:at_most].nil?
    at_most_option = "--at-most #{options[:at_most]}"
  end
  gff3_ffetch = IO.popen("gff3-ffetch --filter #{filter_string} - #{output_option} #{at_most_option}", "r+")
  gff3_ffetch.write data
  gff3_ffetch.close_write
  if output_option.nil?
    output = gff3_ffetch.read
  end
  gff3_ffetch.close
  output
end

.filter_file(filename, filter_string, options = {}) ⇒ Object

Runs the gff3-ffetch utility with the specified parameters on an external file. Options include :output and :at_most.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/bio-gff3-pltools/filtering.rb', line 6

def self.filter_file filename, filter_string, options = {}
  if !File.exists?(filename)
    raise Exception.new("No such file - #{filename}")
  end

  output_option = nil
  output = nil
  if !options[:output].nil?
    output_option = "--output #{options[:output]}"
  end
  if !options[:at_most].nil?
    at_most_option = "--at-most #{options[:at_most]}"
  end
  gff3_ffetch = IO.popen("gff3-ffetch --filter #{filter_string} #{filename} #{output_option} #{at_most_option}")
  if output_option.nil?
    output = gff3_ffetch.read
  end
  gff3_ffetch.close
  output
end