-
Notifications
You must be signed in to change notification settings - Fork 4
/
rename_reads.rb
108 lines (92 loc) · 2.51 KB
/
rename_reads.rb
1
2
3
4
5
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
require 'optparse'
require "erubis"
require 'logger'
path = File.expand_path(File.dirname(__FILE__))
require "#{path}/logging"
include Logging
$logger = Logger.new(STDERR)
# Initialize logger
def setup_logger(loglevel)
case loglevel
when "debug"
$logger.level = Logger::DEBUG
when "warn"
$logger.level = Logger::WARN
when "info"
$logger.level = Logger::INFO
else
$logger.level = Logger::ERROR
end
end
def setup_option(args)
options = {
:loglevel => "error",
:debug => false,
:nummer => 10000000,
:fill => true,
:read_length => 100,
:start => 1
}
opt_parser = OptionParser.new do |opts|
opts.separator ""
opts.banner = "\nUsage: ruby rename_reads.rb [options] file.sam > fixed.sam"
opts.separator ""
# enumeration
#opts.on('-a', '--algorithm ENUM', [:all, :contextmap2,
# :crac, :gsnap, :hisat, :mapsplice2, :olego, :rum,
# :star,:soap,:soapsplice, :subread, :tophat2],'Choose from below:','all: DEFAULT',
# 'contextmap2','crac','gsnap','hisat', 'mapsplice2',
# 'olego','rum','star','soap','soapsplice','subread','tophat2') do |v|
# options[:algorithm] = v
#end
opts.on("-d", "--debug", "Run in debug mode") do |v|
options[:log_level] = "debug"
options[:debug] = true
end
#opts.on("-o", "--out_file [OUT_FILE]",
# :REQUIRED,String,
# "File for the output, Default: overview_table.xls") do |anno_file|
# options[:out_file] = anno_file
#end
opts.on("-s", "--start [INT]",
:REQUIRED,Integer,
"start number of framgment that should be in the fixed.sam, DEFAULT: 1") do |s|
options[:start] = s
end
opts.on("-v", "--verbose", "Run verbosely") do |v|
options[:log_level] = "info"
end
opts.separator ""
end
args = ["-h"] if args.length == 0
opt_parser.parse!(args)
setup_logger(options[:log_level])
if args.length != 1
$logger.error("You provided #{args.length} input file(s), but 1 required!")
raise "Please specify the input (file.sam)"
end
options
end
def run_all(arguments)
$logger.info(arguments)
options = setup_option(arguments)
sam_file = File.open(arguments[0])
startnum = options[:start]-1
while !sam_file.eof?
line = sam_file.readline()
line.chomp!
if line =~ /^@/
puts line
next
end
fields = line.split("\t")
fields[0] =~ /(\d+)/
num = $1.to_i
fields[0] = "seq.#{num+startnum}"
puts fields.join("\t")
end
$logger.info("All done!")
end
if __FILE__ == $0
run_all(ARGV)
end