Class: FileParser
- Inherits:
-
Object
- Object
- FileParser
- Defined in:
- lib/anncrsnp/file_parser.rb
Direct Known Subclasses
Constant Summary collapse
- @@parsers =
{}
Class Method Summary collapse
-
.available? ⇒ Boolean
PARSER DEPENDANT METHODS.
- .format ⇒ Object
- .get_descendants ⇒ Object
- .load ⇒ Object
- .select(format) ⇒ Object
Instance Method Summary collapse
-
#initialize(folder, chunk_size) ⇒ FileParser
constructor
A new instance of FileParser.
- #parse(line) ⇒ Object
- #write_compressed_data ⇒ Object
Constructor Details
#initialize(folder, chunk_size) ⇒ FileParser
Returns a new instance of FileParser.
33 34 35 36 37 38 39 |
# File 'lib/anncrsnp/file_parser.rb', line 33 def initialize(folder, chunk_size) @folder = folder @chunk_size = chunk_size @chrom = nil @coords = [] @packs = 0 end |
Class Method Details
.available? ⇒ Boolean
PARSER DEPENDANT METHODS
25 26 27 |
# File 'lib/anncrsnp/file_parser.rb', line 25 def self.available? return FALSE end |
.format ⇒ Object
29 30 31 |
# File 'lib/anncrsnp/file_parser.rb', line 29 def self.format return 'master' end |
.get_descendants ⇒ Object
4 5 6 |
# File 'lib/anncrsnp/file_parser.rb', line 4 def self.get_descendants return ObjectSpace.each_object(Class).select { |klass| klass < self } end |
.load ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/anncrsnp/file_parser.rb', line 8 def self.load path_parsers = File.join(File.dirname(__FILE__), 'file_parsers') Dir.glob(path_parsers+'/*').each do |parser| require parser end get_descendants.each do |descendant| @@parsers[descendant.format] = descendant if descendant.available? end end |
.select(format) ⇒ Object
18 19 20 |
# File 'lib/anncrsnp/file_parser.rb', line 18 def self.select(format) return @@parsers[format] end |
Instance Method Details
#parse(line) ⇒ Object
41 42 43 |
# File 'lib/anncrsnp/file_parser.rb', line 41 def parse(line) end |
#write_compressed_data ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/anncrsnp/file_parser.rb', line 45 def write_compressed_data p = @packs * @chunk_size gz_path = File.join(@folder, "#{@chrom}_#{p}.gz") Zlib::GzipWriter.open(gz_path) do |writer| Yajl::Encoder.encode(@coords, writer) end @packs += 1 end |