forked from bioruby/bioruby
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New shell plugin ncbirest.rb to provide efetch etc.
* New shell plugin lib/bio/shell/plugin/ncbirest.rb, providing "efetch", "einfo", "esearch", and "esearch_count" methods. They act the same as those defined in Bio::NCBI::REST, except that efetch automatically selects databases if no options are given and only 1 id is given. * A shell command "getobj" is changed to use "efetch" method when "gb" or some variant is specified as the database.
- Loading branch information
Showing
3 changed files
with
77 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# | ||
# = bio/shell/plugin/ncbirest.rb - plugin for NCBI eUtils | ||
# | ||
# Copyright:: Copyright (C) 2009 | ||
# Naohisa Goto <ng@bioruby.org> | ||
# License:: The Ruby License | ||
# | ||
# $Id:$ | ||
# | ||
|
||
module Bio::Shell | ||
|
||
private | ||
|
||
# NCBI eUtils EFetch service. | ||
# When two or more arguments are given, or multiple accession numbers | ||
# are given it acts the same as Bio::NCBI::REST.efetch. | ||
# Otherwise, assumes nucleotide or protein accessin is given, and | ||
# automatically tries several databases. | ||
def efetch(ids, *arg) | ||
if !arg.empty? or ids.kind_of?(Array) or /\,/ =~ ids then | ||
return Bio::NCBI::REST.efetch(ids, *arg) | ||
end | ||
|
||
rettype = 'gb' | ||
prot_dbs = [ 'protein' ] | ||
nucl_dbs = [ 'nuccore', 'nucleotide', 'nucgss', 'nucest' ] | ||
|
||
case ids | ||
when /\A[A-Z][A-Z][A-Z][0-9]+(\.[0-9]+)?\z/i, | ||
/\A[OPQ][A-Z0-9]+(\.[0-9]+)?\z/i | ||
# protein accession | ||
dbs = prot_dbs | ||
when /\A[0-9]+\z/, /\A[A-Z0-9]+\_[A-Z0-9]+\z/i | ||
# NCBI GI or UniProt accession (with fail-safe) | ||
dbs = prot_dbs + nucl_dbs | ||
else | ||
# nucleotide accession | ||
dbs = nucl_dbs | ||
end | ||
result = nil | ||
dbs.each do |db| | ||
hash = { 'db' => db, 'rettype' => 'gb' } | ||
result = Bio::NCBI::REST.efetch(ids, hash) | ||
break if result and !result.empty? | ||
end | ||
result | ||
end | ||
|
||
# NCBI eUtils EInfo | ||
def einfo | ||
Bio::NCBI::REST.einfo | ||
end | ||
|
||
# NCBI eUtils ESearch | ||
def esearch(str, *arg) | ||
Bio::NCBI::REST.esearch(str, *arg) | ||
end | ||
|
||
# Same as Bio::NCBI::REST.esearch_count | ||
def esearch_count(str, *arg) | ||
Bio::NCBI::REST.esearch_count(str, *arg) | ||
end | ||
|
||
end | ||
|