Class: Bio::Faster
- Inherits:
-
Object
- Object
- Bio::Faster
- Extended by:
- FFI::Library
- Defined in:
- lib/bio/faster.rb,
lib/bio/faster/library.rb
Defined Under Namespace
Classes: FastQRecord, Library
Instance Attribute Summary collapse
-
#encoding ⇒ Object
Returns the value of attribute encoding.
-
#file ⇒ Object
Returns the value of attribute file.
Instance Method Summary collapse
- #each_record ⇒ Object
-
#initialize(file, encoding = :sanger) ⇒ Faster
constructor
A new instance of Faster.
Constructor Details
#initialize(file, encoding = :sanger) ⇒ Faster
Returns a new instance of Faster.
16 17 18 19 |
# File 'lib/bio/faster.rb', line 16 def initialize(file, encoding = :sanger) self.file = file self.encoding = encoding end |
Instance Attribute Details
#encoding ⇒ Object
Returns the value of attribute encoding.
15 16 17 |
# File 'lib/bio/faster.rb', line 15 def encoding @encoding end |
#file ⇒ Object
Returns the value of attribute file.
14 15 16 |
# File 'lib/bio/faster.rb', line 14 def file @file end |
Instance Method Details
#each_record ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/bio/faster.rb', line 35 def each_record if self.file == :stdin self.file = "stdin" elsif !File.exists? self.file raise ArgumentError, "File #{self.file} does not exist" end record = FastQRecord.new scale_factor = nil case self.encoding when :sanger then scale_factor = 33 when :solexa then scale_factor = 64 end record[:filename] = FFI::MemoryPointer.from_string self.file while (result = Bio::Faster.fastQ_iterator(record,scale_factor)) == 1 yield [record[:id].read_string,record[:seq].read_string,record[:quality].read_array_of_int(record[:raw_quality].read_string.length)] end case result when -1 then raise RuntimeError, "Bad formatted FastQ file!" when -2 then raise RuntimeError, "Sequence or quality is truncated!" end end |