Module: Medvane::Eutils

Defined in:
lib/medvane.rb

Constant Summary collapse

EUTILS_URL =
"http://eutils.ncbi.nlm.nih.gov/entrez/eutils/"
TOOL_NAME =
"medvane.org"
TOOL_EMAIL =
"[email protected]"

Class Method Summary collapse

Class Method Details

.efetch(webenv, retstart = 0, retmax = 1000000, rettype = "uilist", db = "pubmed") ⇒ Object



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
# File 'lib/medvane.rb', line 29

def efetch(webenv, retstart = 0, retmax = 1000000, rettype = "uilist", db = "pubmed")
  server = EUTILS_URL + "efetch.fcgi"
  params = {
    "db"          => db,
    "tool"        => TOOL_NAME,
    "email"       => TOOL_EMAIL,
    "WebEnv"      => webenv,
    "retmax"      => retmax,
    "rettype"     => rettype,
    "retmode"     => "text",
    "retstart"    => retstart,
    "query_key"   => 1,
  }
  response = Net::HTTP.post_form(URI.parse(server), params)
  medline = []
  unless response.body.blank?
    case rettype
    when "uilist"
      medline = response.body.split(/\n/)
    when "medline"
      medline = response.body.split(/\n\n+/).map {|e| Bio::MEDLINE.new(e) }
    end
  end
  return medline
end

.efetchids(ids, db = "nuccore", retstart = 0, retmax = 10000, rettype = "gb", retmode = "xml") ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/medvane.rb', line 72

def efetchids(ids, db = "nuccore", retstart = 0, retmax = 10000, rettype = "gb", retmode = "xml")
  server = EUTILS_URL + "efetch.fcgi"
  params = {
     "id"          => ids,
     "db"          => db,
     "tool"        => TOOL_NAME,
     "email"       => TOOL_EMAIL,
     "retmax"      => retmax,
     "rettype"     => rettype,
     "retmode"     => retmode,
     "retstart"    => retstart,
   }
   response = Net::HTTP.post_form(URI.parse(server), params)
   return response.body
end

.epost(ids) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/medvane.rb', line 89

def epost(ids)
  server = EUTILS_URL + "epost.fcgi"
  params = {
    "db"          => "pubmed",
    "id"          => ids.join(","),
    "tool"        => TOOL_NAME,
    "email"       => TOOL_EMAIL,
  }
  response = Net::HTTP.post_form(URI.parse(server), params)
  result = response.body
  webenv = result.scan(/<WebEnv>(.*?)<\/WebEnv>/m).flatten.first.to_s
  return webenv
end

.esearch(query, db = "pubmed") ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/medvane.rb', line 11

def esearch(query, db = "pubmed")
  server = EUTILS_URL + "esearch.fcgi"
  params = {
    "db"          => db,
    "term"        => query,
    "tool"        => TOOL_NAME,
    "email"       => TOOL_EMAIL,
    "retmax"      => 0,
    "usehistory"  => "y",
  }
  response = Net::HTTP.post_form(URI.parse(server), params)
  result = response.body
  count = result.scan(/<Count>(.*?)<\/Count>/m).flatten.first.to_i
  webenv = result.scan(/<WebEnv>(.*?)<\/WebEnv>/m).flatten.first.to_s
  return webenv, count
end

.esearchgis(query, db = "nuccore", retmax = 24) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/medvane.rb', line 56

def esearchgis(query, db = "nuccore", retmax = 24)
  server = EUTILS_URL + "esearch.fcgi"
  params = {
    "db"          => db,
    "term"        => query,
    "tool"        => TOOL_NAME,
    "email"       => TOOL_EMAIL,
    "retmax"      => retmax,
  }
  response = Net::HTTP.post_form(URI.parse(server), params)
  result = response.body
  gis = result.scan(/<Id>(\d+)<\/Id>/).flatten
  return gis
end