Class: WigfixParser

Inherits:
FileParser show all
Defined in:
lib/anncrsnp/file_parsers/wigfix_parser.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from FileParser

get_descendants, load, select, #write_compressed_data

Constructor Details

#initialize(folder, chunk_size) ⇒ WigfixParser

Returns a new instance of WigfixParser.



2
3
4
5
6
# File 'lib/anncrsnp/file_parsers/wigfix_parser.rb', line 2

def initialize(folder, chunk_size)
	super
	@start = 1
	@step = 1
end

Class Method Details

.available?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/anncrsnp/file_parsers/wigfix_parser.rb', line 8

def self.available?
	return TRUE
end

.formatObject



12
13
14
# File 'lib/anncrsnp/file_parsers/wigfix_parser.rb', line 12

def self.format
	return 'wigfix'
end

Instance Method Details

#get_dataObject



62
63
64
# File 'lib/anncrsnp/file_parsers/wigfix_parser.rb', line 62

def get_data
	return @coords
end

#parse(line) ⇒ Object



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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/anncrsnp/file_parsers/wigfix_parser.rb', line 16

def parse(line)
	#fixedStep chrom=chr11 start=60001 step=1
	if line.include?('fixedStep')
		line =~ /fixedStep chrom=(\S+) start=(\d+) step=(\d+)/
		if !@chrom.nil? && @chrom != $1 #We change of chromosome, we write the buffered coordinates
			#puts "=> #{@packs}\t#{@start}\tx"
			#puts @coords.first.inspect
			#puts @coords.last.inspect
			write_compressed_data
			@coords = []
		end
		@chrom = $1
		last_start = @start
		@start = $2.to_i
		diff = @start - last_start #Create dummy files to fill gaps on coordinate scores
		if diff >= @chunk_size
			(diff/@chunk_size).times do 
				#puts "=> #{@packs}\t#{@start}\td"
				#puts @coords.first.inspect
				#puts @coords.last.inspect
				write_compressed_data
				@coords = []
			end
		else
			if @start/@chunk_size != last_start/@chunk_size #Current coordinate belongs to another pack that the previous, write the buffered coordinates
				#puts "=> #{@packs}\t#{@start}\te"
				#puts @coords.first.inspect
				#puts @coords.last.inspect
				write_compressed_data
				@coords = []
			end
		end
		@step = $3.to_i
	else
		if @start % @chunk_size == 0 # We have reached the chun size, write it to disk
			#puts "=> #{@packs}\t#{@start}\tl"
			#puts @coords.first.inspect
			#puts @coords.last.inspect
			write_compressed_data
			@coords = []
		end
		@coords << [@start, line.to_f]
		@start += @step
	end
end