Module: Bio::PL::GTF

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

Class Method Summary collapse

Class Method Details

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

Runs the gtf-ffetch utility with the specified parameters while passing data to its stdin. Options include :output and :at_most, :keep_fasta, :keep_comments, :keep_pragmas, :gff3_output, :json_output, :select



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/bio-gff3-pltools/filtering.rb', line 138

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[:gff3_output]
    gff3_output_option = "--gff3-output"
  end
  if options[:json_output]
    json_output_option = "--json"
  end
  if !options[:select].nil?
    select_option = "--select \"#{options[:select]}\""
  end
  gtf_ffetch = IO.popen("gtf-ffetch --filter \"#{filter_string}\" - #{output_option} #{at_most_option} #{fasta_option} #{comments_option} #{pragmas_option} #{gff3_output_option} #{json_output_option} #{select_option}", "r+")
  gtf_ffetch.write data
  gtf_ffetch.close_write
  if output_option.nil?
    output = gtf_ffetch.read
  end
  gtf_ffetch.close
  output
end

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

Runs the gtf-ffetch utility with the specified parameters on an external file. Options include :output, :at_most, :keep_fasta, :keep_comments, :keep_pragmas, :gff3_output, :json_output, :select



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/bio-gff3-pltools/filtering.rb', line 95

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[:gff3_output]
    gff3_output_option = "--gff3-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("gtf-ffetch --filter \"#{filter_string}\" #{filename} #{output_option} #{at_most_option} #{fasta_option} #{comments_option} #{pragmas_option} #{gff3_output_option} #{json_output_option} #{select_option}")
  if output_option.nil?
    output = gtf_ffetch.read
  end
  gtf_ffetch.close
  output
end