Class: Bio::Reference
Overview
DESCRIPTION
A class for journal reference information.
USAGE
hash = {'authors' => [ "Hoge, J.P.", "Fuga, F.B." ],
'title' => "Title of the study.",
'journal' => "Theor. J. Hoge",
'volume' => 12,
'issue' => 3,
'pages' => "123-145",
'year' => 2001,
'pubmed' => 12345678,
'medline' => 98765432,
'abstract' => "Hoge fuga. ...",
'url' => "http://example.com",
'mesh' => [],
'affiliations' => []}
ref = Bio::Reference.new(hash)
# Formats in the BiBTeX style.
ref.format("bibtex")
# Short-cut for Bio::Reference#format("bibtex")
ref.bibtex
Instance Attribute Summary collapse
-
#abstract ⇒ Object
readonly
Abstract text in String.
-
#affiliations ⇒ Object
readonly
Affiliations in an Array.
-
#authors ⇒ Object
readonly
Author names in an Array, [ “Hoge, J.P.”, “Fuga, F.B.” ].
-
#issue ⇒ Object
readonly
issue number (typically Fixnum).
-
#journal ⇒ Object
readonly
String with journal name.
-
#medline ⇒ Object
readonly
medline identifier (typically Fixnum).
-
#mesh ⇒ Object
readonly
MeSH terms in an Array.
-
#pages ⇒ Object
readonly
page range (typically String, e.g. “123-145”).
-
#pubmed ⇒ Object
readonly
pubmed identifier (typically Fixnum).
-
#title ⇒ Object
readonly
String with title of the study.
-
#url ⇒ Object
readonly
An URL String.
-
#volume ⇒ Object
readonly
volume number (typically Fixnum).
-
#year ⇒ Object
readonly
year of publication (typically Fixnum).
Instance Method Summary collapse
-
#bibitem(item = nil) ⇒ Object
Returns reference formatted in the bibitem style.
-
#bibtex(section = nil, label = nil, keywords = {}) ⇒ Object
Returns reference formatted in the BiBTeX style.
-
#cell ⇒ Object
Returns reference formatted in the CELL Press style.
-
#current ⇒ Object
Returns reference formatted in the Current Biology (current-biology.com) style.
-
#endnote ⇒ Object
Returns reference formatted in the Endnote style.
-
#format(style = nil, *options) ⇒ Object
Formats the reference in a given style.
-
#general ⇒ Object
Returns reference formatted in a general/generic style.
-
#genome_biol ⇒ Object
Returns reference formatted in the Genome Biology (genomebiology.com) style.
-
#genome_res ⇒ Object
Returns reference formatted in the Genome Research (genome.org) style.
-
#initialize(hash) ⇒ Reference
constructor
Create a new Bio::Reference object from a Hash of values.
-
#nar ⇒ Object
Returns reference formatted in the Nucleic Acids Reseach (nar.oxfordjournals.org) style.
-
#nature(short = false) ⇒ Object
Formats in the Nature Publishing Group (www.nature.com) style.
-
#pubmed_url ⇒ Object
Returns a valid URL for pubmed records.
-
#rd(str = nil) ⇒ Object
Return reference formatted in the RD style.
-
#science ⇒ Object
Returns reference formatted in the Science style.
-
#trends ⇒ Object
Returns reference formatted in the TRENDS style.
Constructor Details
#initialize(hash) ⇒ Reference
Create a new Bio::Reference object from a Hash of values. Data is extracted from the values for keys:
-
authors - expected value: Array of Strings
-
title - expected value: String
-
journal - expected value: String
-
volume - expected value: Fixnum or String
-
issue - expected value: Fixnum or String
-
pages - expected value: String
-
year - expected value: Fixnum or String
-
pubmed - expected value: Fixnum or String
-
medline - expected value: Fixnum or String
-
abstract - expected value: String
-
url - expected value: String
-
mesh - expected value: Array of Strings
-
affiliations - expected value: Array of Strings
hash = {'authors' => [ "Hoge, J.P.", "Fuga, F.B." ], 'title' => "Title of the study.", 'journal' => "Theor. J. Hoge", 'volume' => 12, 'issue' => 3, 'pages' => "123-145", 'year' => 2001, 'pubmed' => 12345678, 'medline' => 98765432, 'abstract' => "Hoge fuga. ...", 'url' => "http://example.com", 'mesh' => [], 'affiliations' => []} ref = Bio::Reference.new(hash)
Arguments:
-
(required) hash: Hash
- Returns
-
Bio::Reference object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/bio/reference.rb', line 118 def initialize(hash) hash.default = '' @authors = hash['authors'] # [ "Hoge, J.P.", "Fuga, F.B." ] @title = hash['title'] # "Title of the study." @journal = hash['journal'] # "Theor. J. Hoge" @volume = hash['volume'] # 12 @issue = hash['issue'] # 3 @pages = hash['pages'] # 123-145 @year = hash['year'] # 2001 @pubmed = hash['pubmed'] # 12345678 @medline = hash['medline'] # 98765432 @abstract = hash['abstract'] @url = hash['url'] @mesh = hash['mesh'] @affiliations = hash['affiliations'] @authors = [] if @authors.empty? @mesh = [] if @mesh.empty? @affiliations = [] if @affiliations.empty? end |
Instance Attribute Details
#abstract ⇒ Object (readonly)
Abstract text in String.
71 72 73 |
# File 'lib/bio/reference.rb', line 71 def abstract @abstract end |
#affiliations ⇒ Object (readonly)
Affiliations in an Array.
80 81 82 |
# File 'lib/bio/reference.rb', line 80 def affiliations @affiliations end |
#authors ⇒ Object (readonly)
Author names in an Array, [ “Hoge, J.P.”, “Fuga, F.B.” ].
44 45 46 |
# File 'lib/bio/reference.rb', line 44 def @authors end |
#issue ⇒ Object (readonly)
issue number (typically Fixnum)
56 57 58 |
# File 'lib/bio/reference.rb', line 56 def issue @issue end |
#journal ⇒ Object (readonly)
String with journal name
50 51 52 |
# File 'lib/bio/reference.rb', line 50 def journal @journal end |
#medline ⇒ Object (readonly)
medline identifier (typically Fixnum)
68 69 70 |
# File 'lib/bio/reference.rb', line 68 def medline @medline end |
#mesh ⇒ Object (readonly)
MeSH terms in an Array.
77 78 79 |
# File 'lib/bio/reference.rb', line 77 def mesh @mesh end |
#pages ⇒ Object (readonly)
page range (typically String, e.g. “123-145”)
59 60 61 |
# File 'lib/bio/reference.rb', line 59 def pages @pages end |
#pubmed ⇒ Object (readonly)
pubmed identifier (typically Fixnum)
65 66 67 |
# File 'lib/bio/reference.rb', line 65 def pubmed @pubmed end |
#title ⇒ Object (readonly)
String with title of the study
47 48 49 |
# File 'lib/bio/reference.rb', line 47 def title @title end |
#url ⇒ Object (readonly)
An URL String.
74 75 76 |
# File 'lib/bio/reference.rb', line 74 def url @url end |
#volume ⇒ Object (readonly)
volume number (typically Fixnum)
53 54 55 |
# File 'lib/bio/reference.rb', line 53 def volume @volume end |
#year ⇒ Object (readonly)
year of publication (typically Fixnum)
62 63 64 |
# File 'lib/bio/reference.rb', line 62 def year @year end |
Instance Method Details
#bibitem(item = nil) ⇒ Object
Returns reference formatted in the bibitem style
# ref is a Bio::Reference object
puts ref.bibitem
\bibitem{PMID:12345678}
Hoge, J.P., Fuga, F.B.
Title of the study.,
{\em Theor. J. Hoge}, 12(3):123--145, 2001.
Arguments:
-
(optional) item: label string (default:
"PMID:#{pubmed}"
).
- Returns
-
String
257 258 259 260 261 262 263 264 265 266 |
# File 'lib/bio/reference.rb', line 257 def bibitem(item = nil) item = "PMID:#{@pubmed}" unless item pages = @pages.sub('-', '--') return <<-"END".collect {|line| line.strip}.join("\n") \\bibitem{#{item}} #{@authors.join(', ')} #{@title}, {\\em #{@journal}}, #{@volume}(#{@issue}):#{pages}, #{@year}. END end |
#bibtex(section = nil, label = nil, keywords = {}) ⇒ Object
Returns reference formatted in the BiBTeX style.
# ref is a Bio::Reference object
puts ref.bibtex
@article{PMID:12345678,
author = {Hoge, J.P. and Fuga, F.B.},
title = {Title of the study.},
journal = {Theor. J. Hoge},
year = {2001},
volume = {12},
number = {3},
pages = {123--145},
}
# using a different section (e.g. "book")
# (but not really configured for anything other than articles)
puts ref.bibtex("book")
@book{PMID:12345678,
author = {Hoge, J.P. and Fuga, F.B.},
title = {Title of the study.},
journal = {Theor. J. Hoge},
year = {2001},
volume = {12},
number = {3},
pages = {123--145},
}
Arguments:
-
(optional) section: BiBTeX section as String
-
(optional) label: Label string cited by LaTeX documents.
Default is <tt>"PMID:#{pubmed}"</tt>.
-
(optional) keywords: Hash of additional keywords,
e.g. { 'abstract' => 'This is abstract.' }. You can also override default keywords. To disable default keywords, specify false as value, e.g. { 'url' => false, 'year' => false }.
- Returns
-
String
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 |
# File 'lib/bio/reference.rb', line 307 def bibtex(section = nil, label = nil, keywords = {}) section = "article" unless section = (' and ', ' and ') thepages = pages.to_s.empty? ? nil : pages.sub(/\-/, '--') unless label then label = "PMID:#{pubmed}" end theurl = if !(url.to_s.empty?) then url elsif pmurl = pubmed_url and !(pmurl.to_s.empty?) then pmurl else nil end hash = { 'author' => .empty? ? nil : , 'title' => title.to_s.empty? ? nil : title, 'number' => issue.to_s.empty? ? nil : issue, 'pages' => thepages, 'url' => theurl } keys = %w( author title journal year volume number pages url ) keys.each do |k| hash[k] = self.__send__(k.intern) unless hash.has_key?(k) end hash.merge!(keywords) { |k, v1, v2| v2.nil? ? v1 : v2 } bib = [ "@#{section}{#{label}," ] keys.concat((hash.keys - keys).sort) keys.each do |kw| ref = hash[kw] bib.push " #{kw.ljust(12)} = {#{ref}}," if ref end bib.push "}\n" return bib.join("\n") end |
#cell ⇒ Object
Returns reference formatted in the CELL Press style.
# ref is a Bio::Reference object
puts ref.cell
Hoge, J.P. and Fuga, F.B. (2001). Title of the study. Theor. J. Hoge 12, 123-145.
- Returns
-
String
501 502 503 504 |
# File 'lib/bio/reference.rb', line 501 def cell = (' and ') "#{} (#{@year}). #{@title} #{@journal} #{@volume}, #{pages}." end |
#current ⇒ Object
Returns reference formatted in the Current Biology (current-biology.com) style. (Same as the Genome Biology style)
# ref is a Bio::Reference object
puts ref.current
Hoge JP, Fuga FB: Title of the study. Theor J Hoge 2001, 12:123-145.
- Returns
-
String
459 460 461 |
# File 'lib/bio/reference.rb', line 459 def current self.genome_biol end |
#endnote ⇒ Object
Returns reference formatted in the Endnote style.
# ref is a Bio::Reference object
puts ref.endnote
%0 Journal Article
%A Hoge, J.P.
%A Fuga, F.B.
%D 2001
%T Title of the study.
%J Theor. J. Hoge
%V 12
%N 3
%P 123-145
%M 12345678
%U http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?cmd=Retrieve&db=PubMed&dopt=Citation&list_uids=12345678
%X Hoge fuga. ...
- Returns
-
String
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/bio/reference.rb', line 221 def endnote lines = [] lines << "%0 Journal Article" @authors.each do || lines << "%A #{}" end lines << "%D #{@year}" unless @year.to_s.empty? lines << "%T #{@title}" unless @title.empty? lines << "%J #{@journal}" unless @journal.empty? lines << "%V #{@volume}" unless @volume.to_s.empty? lines << "%N #{@issue}" unless @issue.to_s.empty? lines << "%P #{@pages}" unless @pages.empty? lines << "%M #{@pubmed}" unless @pubmed.to_s.empty? url = @url.empty? ? pubmed_url : @url lines << "%U #{url}" unless url.empty? lines << "%X #{@abstract}" unless @abstract.empty? @mesh.each do |term| lines << "%K #{term}" end lines << "%+ #{@affiliations.join(' ')}" unless @affiliations.empty? return lines.join("\n") end |
#format(style = nil, *options) ⇒ Object
Formats the reference in a given style.
Styles:
-
nil - general
-
endnote - Endnote
-
bibitem - Bibitem (option available)
-
bibtex - BiBTeX (option available)
-
rd - rd (option available)
-
nature - Nature (option available)
-
science - Science
-
genome_biol - Genome Biology
-
genome_res - Genome Research
-
nar - Nucleic Acids Research
-
current - Current Biology
-
trends - Trends in *
-
cell - Cell Press
See individual methods for details. Basic usage is:
# ref is Bio::Reference object
# using simplest possible call (for general style)
puts ref.format
# output in Nature style
puts ref.format("nature") # alternatively, puts ref.nature
# output in Nature short style (see Bio::Reference#nature)
puts ref.format("nature",true) # alternatively, puts ref.nature(true)
Arguments:
-
(optional) style: String with style identifier
-
(optional) options: Options for styles accepting one
- Returns
-
String
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/bio/reference.rb', line 171 def format(style = nil, *) case style when 'endnote' return endnote when 'bibitem' return bibitem(*) when 'bibtex' return bibtex(*) when 'rd' return rd(*) when /^nature$/i return nature(*) when /^science$/i return science when /^genome\s*_*biol/i return genome_biol when /^genome\s*_*res/i return genome_res when /^nar$/i return nar when /^current/i return current when /^trends/i return trends when /^cell$/i return cell else return general end end |
#general ⇒ Object
Returns reference formatted in a general/generic style.
# ref is a Bio::Reference object
puts ref.general
Hoge, J.P., Fuga, F.B. (2001). "Title of the study." Theor. J. Hoge 12:123-145.
- Returns
-
String
351 352 353 354 |
# File 'lib/bio/reference.rb', line 351 def general = @authors.join(', ') "#{} (#{@year}). \"#{@title}\" #{@journal} #{@volume}:#{@pages}." end |
#genome_biol ⇒ Object
Returns reference formatted in the Genome Biology (genomebiology.com) style.
# ref is a Bio::Reference object
puts ref.genome_biol
Hoge JP, Fuga FB: Title of the study. Theor J Hoge 2001, 12:123-145.
- Returns
-
String
444 445 446 447 448 |
# File 'lib/bio/reference.rb', line 444 def genome_biol = @authors.collect {|name| strip_dots(name)}.join(', ') journal = strip_dots(@journal) "#{}: #{@title} #{journal} #{@year}, #{@volume}:#{@pages}." end |
#genome_res ⇒ Object
Returns reference formatted in the Genome Research (genome.org) style.
# ref is a Bio::Reference object
puts ref.genome_res
Hoge, J.P. and Fuga, F.B. 2001.
Title of the study. Theor. J. Hoge 12: 123-145.
- Returns
-
String
473 474 475 476 |
# File 'lib/bio/reference.rb', line 473 def genome_res = (' and ') "#{} #{@year}.\n #{@title} #{@journal} #{@volume}: #{@pages}." end |
#nar ⇒ Object
Returns reference formatted in the Nucleic Acids Reseach (nar.oxfordjournals.org) style.
# ref is a Bio::Reference object
puts ref.nar
Hoge, J.P. and Fuga, F.B. (2001) Title of the study. Theor. J. Hoge, 12, 123-145.
- Returns
-
String
487 488 489 490 |
# File 'lib/bio/reference.rb', line 487 def nar = (' and ') "#{} (#{@year}) #{@title} #{@journal}, #{@volume}, #{@pages}." end |
#nature(short = false) ⇒ Object
Formats in the Nature Publishing Group (www.nature.com) style.
# ref is a Bio::Reference object
puts ref.nature
Hoge, J.P. & Fuga, F.B. Title of the study. Theor. J. Hoge 12, 123-145 (2001).
# optionally, output short version
puts ref.nature(true) # or puts ref.nature(short=true)
Hoge, J.P. & Fuga, F.B. Theor. J. Hoge 12, 123-145 (2001).
Arguments:
-
(optional) short: Boolean (default false)
- Returns
-
String
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 |
# File 'lib/bio/reference.rb', line 400 def nature(short = false) if short if @authors.size > 4 = "#{@authors[0]} et al." elsif @authors.size == 1 = "#{@authors[0]}" else = (' & ') end "#{} #{@journal} #{@volume}, #{@pages} (#{@year})." else = (' & ') "#{} #{@title} #{@journal} #{@volume}, #{@pages} (#{@year})." end end |
#pubmed_url ⇒ Object
Returns a valid URL for pubmed records
- Returns
-
String
529 530 531 532 533 534 535 536 |
# File 'lib/bio/reference.rb', line 529 def pubmed_url unless @pubmed.to_s.empty? cgi = "http://www.ncbi.nlm.nih.gov/entrez/query.fcgi" opts = "cmd=Retrieve&db=PubMed&dopt=Citation&list_uids" return "#{cgi}?#{opts}=#{@pubmed}" end '' end |
#rd(str = nil) ⇒ Object
Return reference formatted in the RD style.
# ref is a Bio::Reference object
puts ref.rd
== Title of the study.
* Hoge, J.P. and Fuga, F.B.
* Theor. J. Hoge 2001 12:123-145 [PMID:12345678]
Hoge fuga. ...
An optional string argument can be supplied, but does nothing.
Arguments:
-
(optional) str: String (default nil)
- Returns
-
String
374 375 376 377 378 379 380 381 382 |
# File 'lib/bio/reference.rb', line 374 def rd(str = nil) @abstract ||= str lines = [] lines << "== " + @title lines << "* " + (' and ') lines << "* #{@journal} #{@year} #{@volume}:#{@pages} [PMID:#{@pubmed}]" lines << @abstract return lines.join("\n\n") end |
#science ⇒ Object
Returns reference formatted in the Science style.
# ref is a Bio::Reference object
puts ref.science
J.P. Hoge, F.B. Fuga, Theor. J. Hoge 12 123 (2001).
- Returns
-
String
425 426 427 428 429 430 431 432 433 |
# File 'lib/bio/reference.rb', line 425 def science if @authors.size > 4 = rev_name(@authors[0]) + " et al." else = @authors.collect {|name| rev_name(name)}.join(', ') end page_from, = @pages.split('-') "#{}, #{@journal} #{@volume} #{page_from} (#{@year})." end |
#trends ⇒ Object
Returns reference formatted in the TRENDS style.
# ref is a Bio::Reference object
puts ref.trends
Hoge, J.P. and Fuga, F.B. (2001) Title of the study. Theor. J. Hoge 12, 123-145
- Returns
-
String
515 516 517 518 519 520 521 522 523 524 |
# File 'lib/bio/reference.rb', line 515 def trends if @authors.size > 2 = "#{@authors[0]} et al." elsif @authors.size == 1 = "#{@authors[0]}" else = (' and ') end "#{} (#{@year}) #{@title} #{@journal} #{@volume}, #{@pages}" end |