Class: Bio::Ngs::FastQuality

Inherits:
Object
  • Object
show all
Defined in:
lib/bio/ngs/quality.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, format = :fastq_sanger) ⇒ FastQuality

as reported in dx.doi.org/10.1093/nar/gkp1137 we set the default to fastq_sanger, is a better policy to specify ALWAYS the format



23
24
25
26
27
28
29
30
# File 'lib/bio/ngs/quality.rb', line 23

def initialize(file, format=:fastq_sanger)
  begin
    @file = file
    @stream = Bio::FlatFile.auto(file)  
    @format = format
    raise ArgumentError, "the method only accepts FASTQ" unless @stream.dbclass == Bio::Fastq
  end  
end

Instance Attribute Details

#formatObject

Returns the value of attribute format.



19
20
21
# File 'lib/bio/ngs/quality.rb', line 19

def format
  @format
end

Instance Method Details

#quality_profileObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/bio/ngs/quality.rb', line 32

def quality_profile
  qual = nil
  tot_reads = 0
  @stream.each do |read|
    if qual then
      qual += Vector[*read.quality_scores]
    else
      qual = Vector[*read.quality_scores]
    end
    tot_reads += 1
  end
  qual = qual/tot_reads.to_f
  return qual.to_a
end

#track_b_countObject

Restart from the beginning of the file and draw a profile of B qalities



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/bio/ngs/quality.rb', line 48

def track_b_count
  quals = Hash.new(0) # a new element is initialized at zero
  reads_count=0
  @stream = Bio::FlatFile.auto(@file)
  @stream.each do |read|
    read.format = format
    reads_count+=1
    read_qualities = read.quality_scores
    read_qualities.each_index do |read_index|            
      quals[read_index]+=1 if read_qualities[read_index] == 2
    end #seq
  end#reads
  OpenStruct.new(:n_reads=>reads_count, :b_profile=>quals.sort)
end