Module: Chem::NCBI::PCFetch

Extended by:
Chem::NetUtils
Defined in:
lib/chem/utils/net.rb

Constant Summary collapse

PCFetchURI =
PubChemURI + 'pc_fetch/pc_fetch.cgi?'

Class Method Summary collapse

Methods included from Chem::NetUtils

http_get

Class Method Details

.fetch(params) ⇒ Object


111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/chem/utils/net.rb', line 111

def self.fetch(params)
  raise "You need to specify :retmode" if params[:retmode].nil?

  uri = PCFetchURI + params.collect{|key, value| key.to_s + "=" + value.to_s}.join("&")
  doc = http_get(uri)
  num = 0
  if m = /pubchem\/\.fetch\/(\d+).sdf/.match(doc)
    puts 'ftp'
    num = m[1].to_i
  elsif m = /reqid=(\d+)/.match(doc)
    puts 'http'
    num = m[1].to_i
  else
    raise "Cannot retrieve file"
  end

  params[:localfilename] ||= "%s%d.sdf" % [params[:db], params[:id]]

  begin
    ftp = Net::FTP.open("ftp.ncbi.nih.gov")
    ftp.
    ftp.gettextfile("pubchem/.fetch/%d.sdf" % num, params[:localfilename])
  rescue Net::FTPPermError
    puts "error : num"
    retry
  end

end