Class: Bio::Ngs::Converter::Qseq

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(default_type = nil) ⇒ Qseq

Returns a new instance of Qseq.



24
25
26
27
# File 'lib/bio/ngs/converter.rb', line 24

def initialize(default_type=nil)
  @type=default_type if [:pe, :se].include?(default_type)
  @stats = {}
end

Instance Attribute Details

#bufferObject

Source buffer: String with n as line separator File (reading)



20
21
22
# File 'lib/bio/ngs/converter.rb', line 20

def buffer
  @buffer
end

#statsObject (readonly)

keep statistics about total reads, passed filter or not.



22
23
24
# File 'lib/bio/ngs/converter.rb', line 22

def stats
  @stats
end

#typeObject

Returns the value of attribute type.



21
22
23
# File 'lib/bio/ngs/converter.rb', line 21

def type
  @type
end

Instance Method Details

#qseq2fastq_pe(qseq) ⇒ Object

Return the reads in fastq from a paired-end read dataset qseq_line is an Array of strings generated from raw line of qseq file.



85
86
87
88
# File 'lib/bio/ngs/converter.rb', line 85

def qseq2fastq_pe(qseq)
  #          qseq = qseq_line.split #logic here
  "@#{qseq[0]}:#{qseq[2]}:#{qseq[3]}:#{qseq[4]}:#{qseq[5]}#0/#{qseq[7]}\n#{qseq[8].gsub(/\./,'N')}\n+\n#{qseq[9]}" if qseq[10]=="1"
end

#qseq2fastq_se(qseq) ⇒ Object

Return the reads in fastq from a single read dataset qseq_line is an Array of strings generated from raw line of qseq file.



92
93
94
95
# File 'lib/bio/ngs/converter.rb', line 92

def qseq2fastq_se(qseq)
  #         qseq = qseq_line.split #logic here
  "@#{qseq[0]}:#{qseq[2]}:#{qseq[3]}:#{qseq[4]}:#{qseq[5]}#0/\n#{qseq[8].gsub(/\./,'N')}\n+\n#{qseq[9]}" if qseq[10]=="1"
end

#to_fastq(stats = false) ⇒ Object

Return each line converted in fastq, is a line is not valid because is not good enough that line will return a nil rember to remove the nil values if you are building an array

TODO: benchmark the performances, I suspect this is not ooptimized



41
42
43
44
45
46
47
48
49
50
51
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
# File 'lib/bio/ngs/converter.rb', line 41

def to_fastq(stats=false)
if (type.nil?)            
  raise "Type of qseq not specifed."
else
  total = 0
  passed = 0
  rejected = 0
  bases_passed_b_quality = 0
  bases_rejected_b_quality = 0
  bases_passed_total = 0
  bases_rejected_total  = 0
  bases_passed_N = 0
  bases_rejected_N = 0
  @buffer.lines do |line|
    qseq_line_array = line.split
    read  = (send "qseq2fastq_#{type}", qseq_line_array)
    total += 1
    if read
      passed+=1
      bases_passed_b_quality += qseq_line_array[9].scan("B").size
      bases_passed_N += qseq_line_array[9].scan("N").size
      bases_passed_total += qseq_line_array[9].size                
    else
      rejected+=1
      bases_rejected_b_quality += qseq_line_array[9].scan("B").size
      bases_rejected_N += qseq_line_array[9].scan("N").size
      bases_rejected_total += qseq_line_array[9].size
    end
    yield read
  end
  @stats={:reads_total=>total,
    :reads_passed=>passed,
    :reads_rejected=>rejected,
    :bases_passed_total => bases_passed_total,
    :bases_rejected_total => bases_rejected_total,
    :bases_passed_with_b_quality => bases_passed_b_quality,
    :bases_rejected_with_b_quality => bases_rejected_b_quality,
    :bases_passed_with_n => bases_passed_N,
    :bases_rejected_with_n => bases_rejected_N}
  end
end