-
Notifications
You must be signed in to change notification settings - Fork 5
/
add16SRogersSpreadsheet
executable file
·46 lines (41 loc) · 1.02 KB
/
add16SRogersSpreadsheet
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
#!/usr/bin/env ruby
require 'rubygems'
require 'bio'
require 'optimist'
require 'csv'
ARGV.push("--help") if ARGV.empty?
opts = Optimist::options do
banner File.basename($0)
opt :csv, "csv file", :required=>true, :type=>:string
opt :fasta, "fasta file", :required=>true, :type=>:string
end
seqs = Hash.new
Bio::FlatFile.new(Bio::FastaFormat, File.new(opts.fasta)).each do |seq|
seqs[seq.definition.split(" ").first] = seq.seq
end
headers = false
CSV.foreach(opts.csv, :headers=>true) do |row|
if (!headers)
print (row.headers + ["Sequence"]).to_csv
headers = true
end
seq = ""
forward = row["Forward Full Name"]
if (forward)
if (!seqs[forward])
STDERR << "Error: cannot find " << forward << "\n"
next
end
seq += seqs[forward]
end
reverse = row["Reverse Full Name"]
if (reverse)
if (!seqs[reverse])
STDERR << "Error: cannot find " << reverse << "\n"
next
end
seq += "N" * 5 if seq != ""
seq += Bio::Sequence::NA.new(seqs[reverse]).complement.seq.upcase
end
print (row.fields + [seq]).to_csv
end