class BioTCM::Databases::Medline
Class for retrieving medlines in PubMed
Constants
- VERSION
Current version of
Medline
Attributes
last_webenv[RW]
WebEnv used last time
count[R]
Number of entries for current query @return [Fixnum]
term[R]
Query term @return [String]
webenv[R]
Web environment @return [String]
Public Class Methods
new(query, webenv = self.class.last_webenv)
click to toggle source
Perform a search of medlines @param query [String] query terms @param webenv [String]
# File lib/biotcm/databases/medline.rb, line 27 def initialize(query, webenv = self.class.last_webenv) @webenv = webenv search(query) end
Public Instance Methods
and(other)
click to toggle source
AND operation search @param other [String/Medline] @return [self]
# File lib/biotcm/databases/medline.rb, line 44 def and(other) other = '%23' + other.query_key if other.is_a?(self.class) search("%23#{@query_key}+AND+#{other}") end
Also aliased as: &
download_abstracts(filename)
click to toggle source
Download all abstracts @param filename [String] path to expected file @return [self]
# File lib/biotcm/databases/medline.rb, line 76 def download_abstracts(filename) retstart = 0 retmax = 500 total_count = @count BioTCM.logger.info('Medline') { "Downloading #{total_count} medlines ..." } File.open(filename, 'w') do |fout| while retstart < total_count fout.puts EUtilities.efetch( db: 'pubmed', rettype: 'medline', retmode: 'text', retstart: retstart, retmax: retmax, query_key: @query_key, webenv: @webenv ) retstart += retmax retstart = total_count unless retstart < total_count BioTCM.logger.info('Medline') { "#{retstart}/#{total_count}" } end end self end
fetch_pubmed_ids()
click to toggle source
Fetch all pubmed ids @return [Array]
# File lib/biotcm/databases/medline.rb, line 52 def fetch_pubmed_ids rtn = [] retstart = 0 retmax = 500 total_count = @count while retstart < total_count rtn += EUtilities.esearch( db: 'pubmed', retstart: retstart, retmax: retmax, query_key: @query_key, webenv: @webenv ).scan(%r{<Id>(\d+)</Id>}).flatten retstart += retmax retstart = total_count unless retstart < total_count end rtn end
inspect()
click to toggle source
@private
# File lib/biotcm/databases/medline.rb, line 105 def inspect "<BioTCM::Databases::Medline last_term=#{@term.inspect} count=#{@count.inspect} query_key=#{@query_key.inspect} webenv=#{@webenv.inspect}>" end
or(other)
click to toggle source
OR operation search @param other [String/Medline] @return [self]
# File lib/biotcm/databases/medline.rb, line 35 def or(other) other = '%23' + other.query_key if other.is_a?(self.class) search("%23#{@query_key}+OR+#{other}") end
Also aliased as: |
to_s()
click to toggle source
@private
# File lib/biotcm/databases/medline.rb, line 110 def to_s inspect end
Private Instance Methods
search(term)
click to toggle source
Append an esearch
# File lib/biotcm/databases/medline.rb, line 117 def search(term) # Make sure term is valid @term = term.chomp.gsub(/\s+/, '+') @xml = EUtilities.esearch( db: 'pubmed', term: @term, webenv: @webenv, usehistory: 'y' ) @xml =~ %r{<Count>(\d+)</Count>.*<QueryKey>(\d+)</QueryKey>.*<WebEnv>(\S+)</WebEnv>} @count = Regexp.last_match[1].to_i @query_key = Regexp.last_match[2] self.class.last_webenv = @webenv = Regexp.last_match[3] File.open(BioTCM.path_to("tmp/Medline_#{@webenv}_##{@query_key}.txt"), 'w').puts @xml BioTCM.logger.debug('Medline') { "Object updated to => #{self}" } self end