-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmin_reads.rb
executable file
·61 lines (44 loc) · 1.55 KB
/
min_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
#! /usr/bin/env ruby
require 'optparse'
#################################################################################################
## INPUT PARSING
#################################################################################################
options = {}
optparse = OptionParser.new do |opts|
options[:file] = nil
opts.on( '-f', '--file PATH', 'Input reads file') do |file|
options[:file] = file
end
options[:min_reads] = 10
opts.on( '-m', '--min_reads INTEGER', 'Minimun reads per sequence (default 10)' ) do |min_reads|
options[:min_reads] = min_reads.to_i
end
# Set a banner, displayed at the top of the help screen.
opts.banner = "Usage: #{__FILE__} -f file_path -m min_reads \n\n"
# This displays the help screen
opts.on( '-h', '--help', 'Display this screen' ) do
puts opts
exit
end
end # End opts
# parse options and remove from ARGV
optparse.parse!
#################################################################################################
if options[:file].nil?
puts 'Reads file not defined'
Process.exit
end
array = []
File.open(options[:file]).each do |line|
line.chomp!
fields = line.split("\t")
gene_name = fields.shift
fields.map!{|col| col.to_i}
if fields.select{|col| col >= options[:min_reads]}.count == fields.length
row_array = [gene_name].concat(fields)
array << row_array
end
end
array.each do |row|
puts "#{row[0]}"
end