Sha256: abdc0d231fb2ecfbf7190cfc24a8585fbb56efd7f011b1c13d9c9cbeaf7fe9b3
Contents?: true
Size: 1.92 KB
Versions: 2
Compression:
Stored size: 1.92 KB
Contents
#!/usr/bin/env ruby require 'typhoeus' require 'cri' Signal.trap("PIPE", "EXIT") Signal.trap("INT", "EXIT") valid_formats = Set.new ["fasta", "txt", "xml", "rdf", "gff"] def get_uniprot_entry(arg, format) if format.nil? || format.empty? resp = Typhoeus.get("http://www.uniprot.org/uniprot/#{arg}.fasta") if resp.success? puts resp.response_body.lines.map(&:chomp)[1..-1].join("") end else # other format has been specified, just download and output resp = Typhoeus.get("http://www.uniprot.org/uniprot/#{arg}.#{format}") if resp.success? puts resp.response_body end end end root_cmd = Cri::Command.new_basic_root.modify do name 'uniprot' summary 'Command line interface to Uniprot web services.' usage 'uniprot [options]' description <<-EOS The uniprot command is a command line wrapper around the Uniprot web services. The command expects a list of Uniprot Accession Numbers that are passed - as separate command line arguments - in one or more text files that are passed as an argument to the -i option - to standard input The command will give priority to the first way Uniprot Accession Numbers are passed, in the order as listed above. Text files and standard input should have one Uniprot Accession Number per line. The uniprot command yields Uniprot records as output. EOS required :f, :format, "specify output format (available: " + valid_formats.to_a.join(", ") + ")" run do |opts, args, cmd| if !opts[:format].nil? and !valid_formats.include? opts[:format] $stderr.puts opts[:format] + " is not a valid output format. Available formats are: " + valid_formats.to_a.join(", ") exit 1 end iterator = args.empty? ? $stdin.each_line : args iterator.each do |pept| get_uniprot_entry(pept.chomp, opts[:format]) end end end # run_this runs this command without subcommands! Absolutely needed here root_cmd.run_this(ARGV)
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
unipept-0.7.1 | bin/uniprot |
unipept-0.7.0 | bin/uniprot |