bio 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/bio.rb CHANGED
@@ -5,12 +5,12 @@
5
5
  # Toshiaki Katayama <k@bioruby.org>
6
6
  # License:: The Ruby License
7
7
  #
8
- # $Id: bio.rb,v 1.87 2007/12/14 16:04:54 k Exp $
8
+ # $Id: bio.rb,v 1.88 2007/12/29 19:19:07 k Exp $
9
9
  #
10
10
 
11
11
  module Bio
12
12
 
13
- BIORUBY_VERSION = [1, 2, 0].extend(Comparable)
13
+ BIORUBY_VERSION = [1, 2, 1].extend(Comparable)
14
14
 
15
15
  ### Basic data types
16
16
 
@@ -6,7 +6,7 @@
6
6
  #
7
7
  # License:: The Ruby License
8
8
  #
9
- # $Id: alignment.rb,v 1.23 2007/07/16 12:21:39 ngoto Exp $
9
+ # $Id: alignment.rb,v 1.24 2007/12/26 14:08:02 ngoto Exp $
10
10
  #
11
11
  # = About Bio::Alignment
12
12
  #
@@ -93,21 +93,21 @@ module Bio
93
93
 
94
94
  # Returns regular expression for checking gap.
95
95
  def gap_regexp
96
- @gap_regexp or GAP_REGEXP
96
+ ((defined? @gap_regexp) ? @gap_regexp : nil) or GAP_REGEXP
97
97
  end
98
98
  # regular expression for checking gap
99
99
  attr_writer :gap_regexp
100
100
 
101
101
  # Gap character.
102
102
  def gap_char
103
- @gap_char or GAP_CHAR
103
+ ((defined? @gap_char) ? @gap_char : nil) or GAP_CHAR
104
104
  end
105
105
  # gap character
106
106
  attr_writer :gap_char
107
107
 
108
108
  # Character if the site is missing or unknown.
109
109
  def missing_char
110
- @missing_char or MISSING_CHAR
110
+ ((defined? @missing_char) ? @missing_char : nil) or MISSING_CHAR
111
111
  end
112
112
  # Character if the site is missing or unknown.
113
113
  attr_writer :missing_char
@@ -118,7 +118,7 @@ module Bio
118
118
  # Otherwise, returns the first sequence's class.
119
119
  # If no sequences are found, returns nil.
120
120
  def seqclass
121
- @seqclass or String
121
+ ((defined? @seqclass) ? @seqclass : nil) or String
122
122
  end
123
123
 
124
124
  # The class of the sequence.
@@ -347,7 +347,7 @@ module Bio
347
347
  # Otherwise, returns the first sequence's class.
348
348
  # If no sequences are found, returns nil.
349
349
  def seqclass
350
- if @seqclass then
350
+ if (defined? @seqclass) and @seqclass then
351
351
  @seqclass
352
352
  else
353
353
  klass = nil
@@ -481,11 +481,12 @@ module Bio
481
481
  def each_window(window_size, step_size = 1)
482
482
  return nil if window_size < 0
483
483
  if step_size >= 0 then
484
- i = nil
484
+ last_step = nil
485
485
  0.step(alignment_length - window_size, step_size) do |i|
486
486
  yield alignment_window(i, window_size)
487
+ last_step = i
487
488
  end
488
- alignment_window((i+window_size)..-1)
489
+ alignment_window((last_step + window_size)..-1)
489
490
  else
490
491
  i = alignment_length - window_size
491
492
  while i >= 0
@@ -1820,8 +1821,9 @@ module Bio
1820
1821
  # Returns the key for a given sequence. If not found, returns nil.
1821
1822
  def index(seq)
1822
1823
  #(Hash-like)
1823
- k = nil
1824
+ last_key = nil
1824
1825
  self.each_pair do |k, s|
1826
+ last_key = k
1825
1827
  if s.class == seq.class then
1826
1828
  r = (s == seq)
1827
1829
  else
@@ -1829,7 +1831,7 @@ module Bio
1829
1831
  end
1830
1832
  break if r
1831
1833
  end
1832
- k
1834
+ last_key
1833
1835
  end
1834
1836
 
1835
1837
  # Sequences in the alignment are duplicated.
@@ -4,7 +4,7 @@
4
4
  # Copyright:: Copyright (C) 2003-2006 GOTO Naohisa <ng@bioruby.org>
5
5
  # License:: The Ruby License
6
6
  #
7
- # $Id: format0.rb,v 1.24 2007/12/14 16:12:17 k Exp $
7
+ # $Id: format0.rb,v 1.25 2007/12/27 17:28:57 ngoto Exp $
8
8
  #
9
9
  # == Description
10
10
  #
@@ -223,11 +223,22 @@ module Bio
223
223
  end
224
224
 
225
225
  # Returns the bibliography reference of the BLAST software.
226
+ # Note that this method shows only the first reference.
227
+ # When you want to get additional references,
228
+ # you can use <tt>references</tt> method.
226
229
  def reference
227
- unless defined?(@reference)
228
- @reference = @f0reference.to_s.gsub(/\s+/, ' ').strip
230
+ references[0]
231
+ end
232
+
233
+ # Returns the bibliography references of the BLAST software.
234
+ # Returns an array of strings.
235
+ def references
236
+ unless defined?(@references)
237
+ @references = @f0references.collect do |x|
238
+ x.to_s.gsub(/\s+/, ' ').strip
239
+ end
229
240
  end #unless
230
- @reference
241
+ @references
231
242
  end
232
243
 
233
244
  # Returns the name (filename or title) of the database.
@@ -276,7 +287,10 @@ module Bio
276
287
  # database line.
277
288
  def format0_split_headers(data)
278
289
  @f0header = data.shift
279
- @f0reference = data.shift
290
+ @f0references = []
291
+ while data[0] and /\AQuery\=/ !~ data[0]
292
+ @f0references.push data.shift
293
+ end
280
294
  @f0query = data.shift
281
295
  @f0database = data.shift
282
296
  end
@@ -1020,6 +1034,10 @@ module Bio
1020
1034
  pv = sc[2]
1021
1035
  pv = '1' + pv if pv[0] == ?e
1022
1036
  @pvalue = pv.to_f
1037
+ elsif sc.skip(/Method\:\s*(.+)/) then
1038
+ # signature of composition-based statistics method
1039
+ # for example, "Method: Composition-based stats."
1040
+ @stat_method = sc[1]
1023
1041
  else
1024
1042
  raise ScanError
1025
1043
  end
@@ -1089,6 +1107,13 @@ module Bio
1089
1107
  attr_reader :hit_strand if false #dummy
1090
1108
  method_after_parse_score :hit_strand
1091
1109
 
1110
+ # statistical method for calculating evalue and/or score
1111
+ # (nil or a string)
1112
+ # (note that composition-based statistics for blastp or tblastn
1113
+ # were enabled by default after NCBI BLAST 2.2.17)
1114
+ attr_reader :stat_method if false #dummy
1115
+ method_after_parse_score :stat_method
1116
+
1092
1117
  # Parses alignments.
1093
1118
  def parse_alignment
1094
1119
  unless defined?(@parse_alignment)
@@ -4,7 +4,7 @@
4
4
  # Copyright:: Copyright (C) 2003 GOTO Naohisa <ng@bioruby.org>
5
5
  # License:: The Ruby License
6
6
  #
7
- # $Id: wublast.rb,v 1.11 2007/04/21 08:58:17 ngoto Exp $
7
+ # $Id: wublast.rb,v 1.12 2007/12/27 17:28:57 ngoto Exp $
8
8
  #
9
9
  # == Description
10
10
  #
@@ -70,10 +70,11 @@ module Bio
70
70
  # Splits headers.
71
71
  def format0_split_headers(data)
72
72
  @f0header = data.shift
73
+ @f0references = []
73
74
  while r = data.first
74
75
  case r
75
76
  when /^Reference\: /
76
- @f0reference = data.shift
77
+ @f0references.push data.shift
77
78
  when /^Copyright /
78
79
  @f0copyright = data.shift
79
80
  when /^Notice\: /
@@ -5,7 +5,7 @@
5
5
  # Toshiaki Katayama <k@bioruby.org>
6
6
  # License:: The Ruby License
7
7
  #
8
- # $Id: medline.rb,v 1.16 2007/04/05 23:35:40 trevor Exp $
8
+ # $Id: medline.rb,v 1.17 2007/12/21 05:12:41 k Exp $
9
9
  #
10
10
 
11
11
  require 'bio/db'
@@ -25,7 +25,6 @@ module Bio
25
25
  #
26
26
  class MEDLINE < NCBIDB
27
27
 
28
- #
29
28
  def initialize(entry)
30
29
  @pubmed = Hash.new('')
31
30
 
@@ -37,6 +36,7 @@ class MEDLINE < NCBIDB
37
36
  @pubmed[tag] += line[6..-1] if line.length > 6
38
37
  end
39
38
  end
39
+ attr_reader :pubmed
40
40
 
41
41
 
42
42
  # returns a Reference object.
@@ -187,12 +187,18 @@ class MEDLINE < NCBIDB
187
187
  end
188
188
  alias affiliations ad
189
189
 
190
-
191
- ### Other MEDLINE tags
192
-
193
190
  # AID - Article Identifier
194
191
  # Article ID values may include the pii (controlled publisher identifier)
195
192
  # or doi (Digital Object Identifier).
193
+ def doi
194
+ @pubmed['AID'][/(\S+) \[doi\]/, 1]
195
+ end
196
+
197
+ def pii
198
+ @pubmed['AID'][/(\S+) \[pii\]/, 1]
199
+ end
200
+
201
+ ### Other MEDLINE tags
196
202
 
197
203
  # CI - Copyright Information
198
204
  # Copyright statement.
@@ -6,7 +6,7 @@
6
6
  # Naohisa Goto <ng@bioruby.org>
7
7
  # License:: The Ruby License
8
8
  #
9
- # $Id: chain.rb,v 1.8 2007/04/05 23:35:41 trevor Exp $
9
+ # $Id: chain.rb,v 1.9 2007/12/18 13:48:42 ngoto Exp $
10
10
  #
11
11
  # = Bio::PDB::Chain
12
12
  #
@@ -172,6 +172,12 @@ module Bio
172
172
  @residues.join('') + "TER\n" + @heterogens.join('')
173
173
  end
174
174
 
175
+ # returns a string containing human-readable representation
176
+ # of this object.
177
+ def inspect
178
+ "#<#{self.class.to_s} id=#{chain_id.inspect} model.serial=#{(model ? model.serial : nil).inspect} residues.size=#{residues.size} heterogens.size=#{heterogens.size} aaseq=#{aaseq.inspect}>"
179
+ end
180
+
175
181
  # gets an amino acid sequence of this chain from ATOM records
176
182
  def aaseq
177
183
  unless defined? @aaseq
@@ -6,7 +6,7 @@
6
6
  # Naohisa Goto <ng@bioruby.org>
7
7
  # License:: The Ruby License
8
8
  #
9
- # $Id: model.rb,v 1.9 2007/04/05 23:35:41 trevor Exp $
9
+ # $Id: model.rb,v 1.10 2007/12/18 13:48:42 ngoto Exp $
10
10
  #
11
11
  # = Bio::PDB::Model
12
12
  #
@@ -134,6 +134,12 @@ module Bio
134
134
  end
135
135
  return string
136
136
  end
137
+
138
+ # returns a string containing human-readable representation
139
+ # of this object.
140
+ def inspect
141
+ "#<#{self.class.to_s} serial=#{serial.inspect} chains.size=#{chains.size}>"
142
+ end
137
143
 
138
144
  end #class Model
139
145
 
@@ -6,7 +6,7 @@
6
6
  # Alex Gutteridge <alexg@ebi.ac.uk>
7
7
  # License:: The Ruby License
8
8
  #
9
- # $Id: pdb.rb,v 1.23 2007/07/10 10:44:46 ngoto Exp $
9
+ # $Id: pdb.rb,v 1.27 2007/12/28 14:43:44 ngoto Exp $
10
10
  #
11
11
  # = About Bio::PDB
12
12
  #
@@ -233,7 +233,7 @@ module Bio
233
233
  }
234
234
  klass.module_eval {
235
235
  symbolary.each do |x|
236
- define_method(x) { do_parse; super }
236
+ define_method(x) { do_parse; super() }
237
237
  end
238
238
  }
239
239
  klass
@@ -267,7 +267,7 @@ module Bio
267
267
  }
268
268
  klass.module_eval {
269
269
  define_method(:initialize_from_string) { |str|
270
- r = super
270
+ r = super(str)
271
271
  do_parse
272
272
  r
273
273
  }
@@ -437,7 +437,8 @@ module Bio
437
437
  def self.create_definition_hash
438
438
  hash = {}
439
439
  constants.each do |x|
440
- hash[x] = const_get(x) if /\A[A-Z][A-Z0-9]+\z/ =~ x
440
+ x = x.intern # keep compatibility both Ruby 1.8 and 1.9
441
+ hash[x] = const_get(x) if /\A[A-Z][A-Z0-9]+\z/ =~ x.to_s
441
442
  end
442
443
  if x = const_get(:Default) then
443
444
  hash.default = x
@@ -1380,22 +1381,27 @@ module Bio
1380
1381
  End =
1381
1382
  def_rec([ 2, 1, Pdb_Integer, :serial ]) # dummy field (always 0)
1382
1383
 
1383
- Definition['END'] = End
1384
+ Definition['END'.intern] = End
1384
1385
 
1385
1386
  # Basically just look up the class in Definition hash
1386
1387
  # do some munging for JRNL and REMARK
1387
1388
  def self.get_record_class(str)
1388
1389
  t = fetch_record_name(str)
1390
+ t = t.intern unless t.empty?
1389
1391
  if d = Definition[t] then
1390
1392
  return d
1391
1393
  end
1392
1394
  case t
1393
- when 'JRNL'
1394
- d = Jrnl::Definition[str[12..15].to_s.strip]
1395
- when 'REMARK'
1395
+ when :JRNL
1396
+ ts = str[12..15].to_s.strip
1397
+ ts = ts.intern unless ts.empty?
1398
+ d = Jrnl::Definition[ts]
1399
+ when :REMARK
1396
1400
  case str[7..9].to_i
1397
1401
  when 1
1398
- d = Remark1::Definition[str[12..15].to_s.strip]
1402
+ ts = str[12..15].to_s.strip
1403
+ ts = ts.intern unless ts.empty?
1404
+ d = Remark1::Definition[ts]
1399
1405
  when 2
1400
1406
  if str[28..37] == 'ANGSTROMS.' then
1401
1407
  d = Remark2::ANGSTROMS
@@ -1417,13 +1423,21 @@ module Bio
1417
1423
 
1418
1424
  Coordinate_fileds = {
1419
1425
  'MODEL' => true,
1426
+ :MODEL => true,
1420
1427
  'ENDMDL' => true,
1428
+ :ENDMDL => true,
1421
1429
  'ATOM' => true,
1430
+ :ATOM => true,
1422
1431
  'HETATM' => true,
1432
+ :HETATM => true,
1423
1433
  'SIGATM' => true,
1434
+ :SIGATM => true,
1424
1435
  'SIGUIJ' => true,
1436
+ :SIGUIJ => true,
1425
1437
  'ANISOU' => true,
1438
+ :ANISOU => true,
1426
1439
  'TER' => true,
1440
+ :TER => true,
1427
1441
  }
1428
1442
 
1429
1443
  # Creates a new Bio::PDB object from given <em>str</em>.
@@ -1876,6 +1890,12 @@ module Bio
1876
1890
  f ? f.modNum : nil
1877
1891
  end
1878
1892
 
1893
+ # returns a string containing human-readable representation
1894
+ # of this object.
1895
+ def inspect
1896
+ "#<#{self.class.to_s} entry_id=#{entry_id.inspect}>"
1897
+ end
1898
+
1879
1899
  end #class PDB
1880
1900
 
1881
1901
  end #module Bio
@@ -6,7 +6,7 @@
6
6
  # Naohisa Goto <ng@bioruby.org>
7
7
  # License:: The Ruby License
8
8
  #
9
- # $Id: residue.rb,v 1.13 2007/04/23 16:03:25 ngoto Exp $
9
+ # $Id: residue.rb,v 1.14 2007/12/18 13:48:42 ngoto Exp $
10
10
  #
11
11
  # = Bio::PDB::Residue
12
12
  #
@@ -129,6 +129,12 @@ module Bio
129
129
  @atoms.join('')
130
130
  end
131
131
 
132
+ # returns a string containing human-readable representation
133
+ # of this object.
134
+ def inspect
135
+ "#<#{self.class.to_s} resName=#{resName.inspect} id=#{residue_id.inspect} chain.id=#{(chain ? chain.id : nil).inspect} resSeq=#{resSeq.inspect} iCode=#{iCode.inspect} atoms.size=#{atoms.size}>"
136
+ end
137
+
132
138
  # Always returns false.
133
139
  #
134
140
  # If the residue is HETATM, returns true.
@@ -6,7 +6,7 @@
6
6
  # Ryan Raaum <ryan@raaum.org>
7
7
  # License:: The Ruby License
8
8
  #
9
- # $Id: common.rb,v 1.5 2007/12/03 06:19:12 nakao Exp $
9
+ # $Id: common.rb,v 1.6 2007/12/27 17:36:02 ngoto Exp $
10
10
  #
11
11
 
12
12
  module Bio
@@ -177,11 +177,12 @@ module Common
177
177
  # * (optional) _step_size_: Fixnum (default 1)
178
178
  # *Returns*:: new Bio::Sequence::NA/AA object
179
179
  def window_search(window_size, step_size = 1)
180
- i = 0
180
+ last_step = 0
181
181
  0.step(self.length - window_size, step_size) do |i|
182
182
  yield self[i, window_size]
183
+ last_step = i
183
184
  end
184
- return self[i + window_size .. -1]
185
+ return self[last_step + window_size .. -1]
185
186
  end
186
187
 
187
188
  # Returns a float total value for the sequence given a hash of
@@ -6,7 +6,7 @@
6
6
  # 2005 Naohisa Goto <ng@bioruby.org>
7
7
  # License:: The Ruby License
8
8
  #
9
- # $Id: test_alignment.rb,v 1.11 2007/04/05 23:35:42 trevor Exp $
9
+ # $Id: test_alignment.rb,v 1.12 2007/12/26 13:55:40 ngoto Exp $
10
10
  #
11
11
 
12
12
  require 'pathname'
@@ -426,7 +426,7 @@ module Bio
426
426
  Sequence::AA.new('MNSA'),
427
427
  Sequence::AA.new('MHTL'),
428
428
  Sequence::AA.new('MQNV'),
429
- Sequence::AA.new('MKKW'),
429
+ Sequence::AA.new('MKKW')
430
430
  ]
431
431
  assert_equal('*:. ', a.match_line)
432
432
  assert_equal('*:. ', a.match_line(:type => :aa))
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: bio
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.2.0
7
- date: 2007-12-15 00:00:00 +09:00
6
+ version: 1.2.1
7
+ date: 2007-12-30 00:00:00 +09:00
8
8
  summary: Bioinformatics library
9
9
  require_paths:
10
10
  - lib