6
7
8
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
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
|
# File 'lib/bio-locus/locus.rb', line 6
def Keys::each_key(line,options)
use_alt = (options[:alt] == :include or options[:alt] == :only)
use_pos = (options[:alt] == :include or options[:alt] == :exclude)
if line =~ /^[[:alnum:]]+/
fields = nil
chr,pos,id,no_use,alt,rest = line.split(/\t/,6)[0..-1]
if options[:in_format] or options[:eval_chr] or options[:eval_pos] or options[:eval_alt]
fields = line.split(/\t/)
field = fields
case options[:in_format]
when :tab then
alt = field[3].strip.split(/,/)[0] if field[3]
when :snv then
alt = field[2].split(/\//)[1] if field[2]
when :cosmic then
locus_field = field[17]
locus_field = field[13] if locus_field !~ /:/
if field[15] !~ /delet/i and locus_field =~ /:/
chr = /^([^:]+)/.match(locus_field)[1]
a = /:(\d+)-(\d+)/.match(locus_field)
pos = a[1] if a[1]==a[2]
end
end
if options[:eval_chr]
chr = eval(options[:eval_chr])
end
if options[:eval_pos]
pos = eval(options[:eval_pos])
end
if options[:eval_alt]
alt = eval(options[:eval_alt])
end
end
if pos =~ /^\d+$/ and chr and chr != ''
alts = if use_pos
['']
else
[]
end
alts += alt.split(/,/) if use_alt and alt
alts.each do | nuc |
key = chr+"\t"+pos
key += "\t"+nuc if nuc != ''
if options[:once]
return if @@in_list[key]
@@in_list[key] = true
end
yield key
end
else
if options[:ignore_errors]
$stderr.print "WARNING, <#{chr}:#{pos}> skipping: ",line if not options[:quiet]
else
p line
p fields
raise "Parse error chr <#{chr}> pos <#{pos}>\n"
end
end
end
end
|