Class: Bio::Assembly::Contig

Inherits:
Object
  • Object
show all
Defined in:
lib/bio-assembly/contig.rb

Direct Known Subclasses

Ace::Contig, Bio::Assembly::Caf::Contig

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str = "") ⇒ Contig

Returns a new instance of Contig.



10
11
12
13
14
15
# File 'lib/bio-assembly/contig.rb', line 10

def initialize(str="")
  @reads = Hash.new
  @seq = Bio::Sequence::NA.new(str)
  # counter for Reads
  @rds_parsed = 0
end

Instance Attribute Details

#fromObject

Returns the value of attribute from.



7
8
9
# File 'lib/bio-assembly/contig.rb', line 7

def from
  @from
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/bio-assembly/contig.rb', line 7

def name
  @name
end

#orientationObject

Returns the value of attribute orientation.



7
8
9
# File 'lib/bio-assembly/contig.rb', line 7

def orientation
  @orientation
end

#qualityObject

Returns the value of attribute quality.



7
8
9
# File 'lib/bio-assembly/contig.rb', line 7

def quality
  @quality
end

#readsObject

Returns the value of attribute reads.



7
8
9
# File 'lib/bio-assembly/contig.rb', line 7

def reads
  @reads
end

#seqObject Also known as: consensus_seq

Returns the value of attribute seq.



7
8
9
# File 'lib/bio-assembly/contig.rb', line 7

def seq
  @seq
end

#toObject

Returns the value of attribute to.



7
8
9
# File 'lib/bio-assembly/contig.rb', line 7

def to
  @to
end

Instance Method Details

#add_read(read) ⇒ Object



40
41
42
43
# File 'lib/bio-assembly/contig.rb', line 40

def add_read(read)
  # TODO do some checks for pos location
  @reads[read.name] = read
end

#each_readObject



45
46
47
# File 'lib/bio-assembly/contig.rb', line 45

def each_read
  @reads.each_value { |read| yield read }
end

#find_read_by_name(name) ⇒ Object



17
18
19
# File 'lib/bio-assembly/contig.rb', line 17

def find_read_by_name(name)
  @reads[name]
end

#find_reads_in_range(clear_range_from, clear_range_to) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/bio-assembly/contig.rb', line 21

def find_reads_in_range(clear_range_from, clear_range_to)
  reads_in_range = Array.new
  each_read do |read|
    
    # Read starts in region
    if read.from+read.clear_range_from > clear_range_from and read.from+read.clear_range_from < clear_range_to
       reads_in_range.push read
    # Read ends in region
    elsif read.to+read.clear_range_to < clear_range_to and read.to+read.clear_range_to > clear_range_from
       reads_in_range.push read
    # Read encompasses region
    elsif read.from+read.clear_range_from < clear_range_from and read.to+read.clear_range_to > clear_range_to
       reads_in_range.push read
    end
    
  end
  reads_in_range;
end

#num_base_segmentsObject



61
62
63
64
65
66
67
# File 'lib/bio-assembly/contig.rb', line 61

def num_base_segments
  num_base_sequences = 0
  each_read do |read|
    num_base_sequences += read.base_sequences.size unless read.base_sequences.nil?
  end
  num_base_sequences
end

#num_basesObject



53
54
55
# File 'lib/bio-assembly/contig.rb', line 53

def num_bases
  seq.length
end

#num_readsObject



49
50
51
# File 'lib/bio-assembly/contig.rb', line 49

def num_reads
  @reads.size
end