Module: Bio::PL::GFF3

Defined in:
lib/bio-gff3-pltools/filtering.rb,
lib/bio-gff3-pltools/validation.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, :keep_fasta, :keep_comments, :keep_pragmas, :gtf_output, :json_output, :select



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/bio-gff3-pltools/filtering.rb', line 52

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
  if options[:keep_fasta]
    fasta_option = "--keep-fasta"
  end
  if options[:keep_comments]
    comments_option = "--keep-comments"
  end
  if options[:keep_pragmas]
    pragmas_option = "--keep-pragmas"
  end
  if options[:gtf_output]
    gtf_output_option = "--gtf-output"
  end
  if options[:json_output]
    json_output_option = "--json"
  end
  if !options[:select].nil?
    select_option = "--select \"#{options[:select]}\""
  end
  gff3_ffetch = IO.popen("gff3-ffetch --filter \"#{filter_string}\" - #{output_option} #{at_most_option} #{fasta_option} #{comments_option} #{pragmas_option} #{gtf_output_option} #{json_output_option} #{select_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, :at_most, :keep_fasta, :keep_comments, :keep_pragmas, :gtf_output, :json_output, :select



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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 8

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
  if options[:keep_fasta]
    fasta_option = "--keep-fasta"
  end
  if options[:keep_comments]
    comments_option = "--keep-comments"
  end
  if options[:keep_pragmas]
    pragmas_option = "--keep-pragmas"
  end
  if options[:gtf_output]
    gtf_output_option = "--gtf-output"
  end
  if options[:json_output]
    json_output_option = "--json"
  end
  if !options[:select].nil?
    select_option = "--select \"#{options[:select]}\""
  end
  puts "gff3-ffetch --filter \"#{filter_string}\" #{filename} #{output_option} #{at_most_option} #{fasta_option} #{comments_option} #{pragmas_option} #{gtf_output_option} #{json_output_option} #{select_option}"
  gff3_ffetch = IO.popen("gff3-ffetch --filter \"#{filter_string}\" #{filename} #{output_option} #{at_most_option} #{fasta_option} #{comments_option} #{pragmas_option} #{gtf_output_option} #{json_output_option} #{select_option}")
  if output_option.nil?
    output = gff3_ffetch.read
  end
  gff3_ffetch.close
  output
end

.validate_file(filename) ⇒ Object

Runs the gff3-validate utility with the specified filename as argument. Returns error messages if the utility found issues in the file.



7
8
9
10
11
12
13
14
15
16
# File 'lib/bio-gff3-pltools/validation.rb', line 7

def self.validate_file filename
  if !File.exists?(filename)
    raise Exception.new("No such file - #{filename}")
  end

  gff3_validate = IO.popen(["gff3-validate", "#{filename}", :err=>[:child, :out]])
  output = gff3_validate.read
  gff3_validate.close
  output
end