-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEx4.rb
34 lines (28 loc) · 897 Bytes
/
Ex4.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
#!/usr/bin/env ruby
require 'bio'
input = ARGV[0]
output = ARGV[1]
pattern = ARGV[2].upcase
type = ARGV[3]
# Set default email for NCBI to enable REST API use
Bio::NCBI.default_email = "rolivera@itba.edu.ar"
File.open(output, 'w') do |f|
f.puts "Pattern: #{pattern}"
Bio::Blast.reports(File.new (input)) do |report|
# Iterate through each report
report.each do |hit|
# If there is a match with the pattern
if hit.definition.upcase.index pattern
f.puts '-------------------------------------------'
f.puts "Accession: #{hit.accession}"
f.puts "Fasta sequence: "
# Get the FASTA from the accession
if type.eql? '--nucleotid'
f.puts Bio::NCBI::REST::EFetch.nucleotide(hit.accession, "fasta")
else
f.puts Bio::NCBI::REST::EFetch.protein(hit.accession, "fasta")
end
end
end
end
end