[BioRuby-cvs] bioruby/lib/bio reference.rb,1.21,1.22
Katayama Toshiaki
k at dev.open-bio.org
Sun Mar 26 02:32:58 UTC 2006
Update of /home/repository/bioruby/bioruby/lib/bio
In directory dev.open-bio.org:/tmp/cvs-serv28888
Modified Files:
reference.rb
Log Message:
* comprehensive documentation contributed by Ryan Raaum is added
Index: reference.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/reference.rb,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -d -r1.21 -r1.22
*** reference.rb 8 Feb 2006 15:06:26 -0000 1.21
--- reference.rb 26 Mar 2006 02:32:56 -0000 1.22
***************
*** 2,45 ****
# = bio/reference.rb - Journal reference classes
#
! # Copyright:: Copyright (C) 2001
! # KATAYAMA Toshiaki <k at bioruby.org>
! # Lisence:: LGPL
#
# $Id$
#
- # == Description
- #
- # Journal reference classes.
- #
- # == Examples
- #
- # == References
- #
- #
- #
- #--
- #
- # This library is free software; you can redistribute it and/or
- # modify it under the terms of the GNU Lesser General Public
- # License as published by the Free Software Foundation; either
- # version 2 of the License, or (at your option) any later version.
- #
- # This library is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- # Lesser General Public License for more details.
- #
- # You should have received a copy of the GNU Lesser General Public
- # License along with this library; if not, write to the Free Software
- # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- #
- #++
- #
module Bio
# A class for journal reference information.
#
! # === Examples
#
# hash = {'authors' => [ "Hoge, J.P.", "Fuga, F.B." ],
--- 2,20 ----
# = bio/reference.rb - Journal reference classes
#
! # Copyright:: Copyright (C) 2001, 2006
! # Toshiaki Katayama <k at bioruby.org>,
! # Ryan Raaum <ryan at raaum.org>
! # Lisence:: Ruby's
#
# $Id$
#
module Bio
+ # = DESCRIPTION
+ #
# A class for journal reference information.
#
! # = USAGE
#
# hash = {'authors' => [ "Hoge, J.P.", "Fuga, F.B." ],
***************
*** 69,100 ****
attr_reader :authors
! # "Title of the study."
attr_reader :title
! # "Theor. J. Hoge"
attr_reader :journal
! # 12
attr_reader :volume
! # 3
attr_reader :issue
! # "123-145"
attr_reader :pages
! # 2001
attr_reader :year
! # 12345678
attr_reader :pubmed
! # 98765432
attr_reader :medline
! # Abstract test in String.
attr_reader :abstract
! # A URL String.
attr_reader :url
--- 44,75 ----
attr_reader :authors
! # String with title of the study
attr_reader :title
! # String with journal name
attr_reader :journal
! # volume number (typically Fixnum)
attr_reader :volume
! # issue number (typically Fixnum)
attr_reader :issue
! # page range (typically String, e.g. "123-145")
attr_reader :pages
! # year of publication (typically Fixnum)
attr_reader :year
! # pubmed identifier (typically Fixnum)
attr_reader :pubmed
! # medline identifier (typically Fixnum)
attr_reader :medline
! # Abstract text in String.
attr_reader :abstract
! # An URL String.
attr_reader :url
***************
*** 105,109 ****
attr_reader :affiliations
! #
def initialize(hash)
hash.default = ''
--- 80,119 ----
attr_reader :affiliations
! # 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
def initialize(hash)
hash.default = ''
***************
*** 131,138 ****
# 0. nil - general
# 1. endnote - Endnote
! # 2. bibitem - Bibitem (option acceptable)
! # 3. bibtex - BiBTeX (option acceptable)
! # 4. rd - rd (option acceptable)
! # 5. nature - Nature (option acceptable)
# 6. science - Science
# 7. genome_biol - Genome Biology
--- 141,148 ----
# 0. nil - general
# 1. endnote - Endnote
! # 2. bibitem - Bibitem (option available)
! # 3. bibtex - BiBTeX (option available)
! # 4. rd - rd (option available)
! # 5. nature - Nature (option available)
# 6. science - Science
# 7. genome_biol - Genome Biology
***************
*** 142,145 ****
--- 152,172 ----
# 11. trends - Trends in *
# 12. 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) _option_: Option for styles accepting one
+ # *Returns*:: String
def format(style = nil, option = nil)
case style
***************
*** 173,177 ****
end
! # Formats in the Endonote style.
def endnote
lines = []
--- 200,222 ----
end
! # 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
def endnote
lines = []
***************
*** 201,205 ****
end
! # Formats in the bibitem.
def bibitem(item = nil)
item = "PMID:#{@pubmed}" unless item
--- 246,260 ----
end
! # 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.
! # ---
! # *Returns*:: String
def bibitem(item = nil)
item = "PMID:#{@pubmed}" unless item
***************
*** 213,217 ****
end
! # Formats in the BiBTeX style.
def bibtex(section = nil)
section = "article" unless section
--- 268,303 ----
end
! # 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
! # *Returns*:: String
def bibtex(section = nil)
section = "article" unless section
***************
*** 231,235 ****
end
! # Formats in a general style.
def general
authors = @authors.join(', ')
--- 317,328 ----
end
! # 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
def general
authors = @authors.join(', ')
***************
*** 237,241 ****
end
! # Formats in the RD style.
def rd(str = nil)
@abstract ||= str
--- 330,351 ----
end
! # 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
def rd(str = nil)
@abstract ||= str
***************
*** 248,253 ****
end
! # Formats in the Nature Publish Group style.
! # * http://www.nature.com
def nature(short = false)
if short
--- 358,377 ----
end
! # Formats in the Nature Publishing Group
! # (http://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
def nature(short = false)
if short
***************
*** 266,271 ****
end
! # Formats in the Science style.
! # * http://www.siencemag.com/
def science
if @authors.size > 4
--- 390,402 ----
end
! # Returns reference formatted in the
! # Science[http://www.sciencemag.org] style.
! #
! # # ref is a Bio::Reference object
! # puts ref.science
! #
! # J.P. Hoge, F.B. Fuga, Theor. J. Hoge 12 123 (2001).
! # ---
! # *Returns*:: String
def science
if @authors.size > 4
***************
*** 278,283 ****
end
! # Formats in the Genome Biology style.
! # * http://genomebiology.com/
def genome_biol
authors = @authors.collect {|name| strip_dots(name)}.join(', ')
--- 409,421 ----
end
! # Returns reference formatted in the Genome Biology
! # (http://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
def genome_biol
authors = @authors.collect {|name| strip_dots(name)}.join(', ')
***************
*** 285,294 ****
"#{authors}: #{@title} #{journal} #{@year}, #{@volume}:#{@pages}."
end
! # Formats in the Current Biology style.
! # * http://www.current-biology.com/
! alias current genome_biol
! # Formats in the Genome Research style.
! # * http://genome.org/
def genome_res
authors = authors_join(' and ')
--- 423,450 ----
"#{authors}: #{@title} #{journal} #{@year}, #{@volume}:#{@pages}."
end
!
! # Returns reference formatted in the Current Biology
! # (http://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
! def current
! self.genome_biol
! end
! # Returns reference formatted in the Genome Research
! # (http://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
def genome_res
authors = authors_join(' and ')
***************
*** 296,301 ****
end
! # Formats in the Nucleic Acids Reseach style.
! # * http://nar.oxfordjournals.org/
def nar
authors = authors_join(' and ')
--- 452,464 ----
end
! # Returns reference formatted in the Nucleic Acids Reseach
! # (http://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
def nar
authors = authors_join(' and ')
***************
*** 303,308 ****
end
! # Formats in the CELL Press style.
! # http://www.cell.com/
def cell
authors = authors_join(' and ')
--- 466,478 ----
end
! # Returns reference formatted in the
! # CELL[http://www.cell.com] 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
def cell
authors = authors_join(' and ')
***************
*** 310,315 ****
end
! # Formats in the TRENDS Journals.
! # * http://www.trends.com/
def trends
if @authors.size > 2
--- 480,492 ----
end
! # Returns reference formatted in the
! # TRENDS[http://www.trends.com] 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
def trends
if @authors.size > 2
***************
*** 352,358 ****
end
! # Set of Bio::Reference.
#
! # === Examples
#
# refs = Bio::References.new
--- 529,537 ----
end
! # = DESCRIPTION
#
! # A container class for Bio::Reference objects.
! #
! # = USAGE
#
# refs = Bio::References.new
***************
*** 364,371 ****
class References
! # Array of Bio::Reference.
attr_accessor :references
#
def initialize(ary = [])
@references = ary
--- 543,556 ----
class References
! # Array of Bio::Reference objects
attr_accessor :references
+ # Create a new Bio::References object
#
+ # refs = Bio::References.new
+ # ---
+ # *Arguments*:
+ # * (optional) __: Array of Bio::Reference objects
+ # *Returns*:: Bio::References object
def initialize(ary = [])
@references = ary
***************
*** 373,377 ****
! # Append a Bio::Reference object.
def append(reference)
@references.push(reference) if reference.is_a? Reference
--- 558,568 ----
! # Add a Bio::Reference object to the container.
! #
! # refs.append(reference)
! # ---
! # *Arguments*:
! # * (required) _reference_: Bio::Reference object
! # *Returns*:: current Bio::References object
def append(reference)
@references.push(reference) if reference.is_a? Reference
***************
*** 379,383 ****
end
! # Iterates each Bio::Reference object.
def each
@references.each do |reference|
--- 570,580 ----
end
! # Iterate through Bio::Reference objects.
! #
! # refs.each do |reference|
! # ...
! # end
! # ---
! # *Block*:: yields each Bio::Reference object
def each
@references.each do |reference|
More information about the bioruby-cvs
mailing list