Class: Sam

Inherits:
Object
  • Object
show all
Includes:
Enumerable, Printer
Defined in:
lib/sam.rb

Defined Under Namespace

Classes: Header, Read

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Printer

#print, #write

Constructor Details

#initializeSam

Returns a new instance of Sam.



156
157
158
159
# File 'lib/sam.rb', line 156

def initialize
  @reads = []
  @mates = {}
end

Instance Attribute Details

#headerObject

Returns the value of attribute header.



155
156
157
# File 'lib/sam.rb', line 155

def header
  @header
end

#matesObject (readonly)

Returns the value of attribute mates.



154
155
156
# File 'lib/sam.rb', line 154

def mates
  @mates
end

#readsObject (readonly)

Returns the value of attribute reads.



154
155
156
# File 'lib/sam.rb', line 154

def reads
  @reads
end

Class Method Details

.read(file) ⇒ Object



172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/sam.rb', line 172

def self.read file
  sam = self.new
  header = []
  File.foreach(file) do |l|
    if l =~ /^@/
      header.push l
      next
    end
    sam.reads.push Sam::Read.new(sam, l.chomp.split(/\t/,12))
  end
  sam.header = Sam::Header.new(sam, header)
  sam
end

Instance Method Details

#add_mate(mate, record) ⇒ Object



161
162
163
164
# File 'lib/sam.rb', line 161

def add_mate mate, record
  @mates[mate] ||= []
  @mates[mate].push record
end

#eachObject



166
167
168
169
170
# File 'lib/sam.rb', line 166

def each
  @reads.each do |r|
    yield r
  end
end

#inspectObject



193
194
195
# File 'lib/sam.rb', line 193

def inspect
  "#<#{self.class.name}:#{object_id} @reads=#{reads.size}>"
end

#output(f) ⇒ Object



186
187
188
189
190
191
# File 'lib/sam.rb', line 186

def output f
  @header.output f
  @reads.each do |r|
    r.output f
  end
end