Class: Mpileup

Inherits:
Object
  • Object
show all
Defined in:
lib/full_lengther_next/mapping.rb

Instance Method Summary collapse

Constructor Details

#initialize(file_path) ⇒ Mpileup

Returns a new instance of Mpileup.



4
5
6
7
# File 'lib/full_lengther_next/mapping.rb', line 4

def initialize(file_path)
	@mpileup_file = ScbiZcatFile.new(file_path)
	@last_line = nil
end

Instance Method Details

#closeObject



51
52
53
# File 'lib/full_lengther_next/mapping.rb', line 51

def close
	@mpileup_file.close
end

#initialize_contig(contig_length) ⇒ Object



45
46
47
48
49
# File 'lib/full_lengther_next/mapping.rb', line 45

def initialize_contig(contig_length)
	coverages = Array.new(contig_length, 0) 
	coverages[@last_line[1].to_i-1] = @last_line[2].to_i
	return coverages
end

#read_contig(contig_name, contig_length) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/full_lengther_next/mapping.rb', line 9

def read_contig(contig_name, contig_length)
	coverages = []
	if !@last_line.nil?
		if @last_line[0] != contig_name
			return nil
		else
			coverages = initialize_contig(contig_length)
		end
	else
		line = @mpileup_file.readline
		if line.nil?
			@last_line = nil
			return nil
		else
			@last_line = line.chomp.split("\t")
			if @last_line[0] != contig_name
				return nil
			else
				coverages = initialize_contig(contig_length)
			end
		end
	end
	
	while !@mpileup_file.eof
		fields = @mpileup_file.readline.chomp.split("\t")
		contig = fields[0]
		if contig == contig_name
			coverages[fields[1].to_i-1] = fields[2].to_i
		else
			@last_line = fields
			break
		end
	end
	return coverages
end