bio 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (201) hide show
  1. data/bin/bioruby +107 -0
  2. data/bin/br_biofetch.rb +59 -0
  3. data/bin/br_bioflat.rb +294 -0
  4. data/bin/br_biogetseq.rb +57 -0
  5. data/bin/br_pmfetch.rb +431 -0
  6. data/doc/BioRuby.rd.ja +225 -0
  7. data/doc/Changes-0.7.rd +236 -0
  8. data/doc/Design.rd.ja +341 -0
  9. data/doc/KEGG_API.rd +1437 -0
  10. data/doc/KEGG_API.rd.ja +1399 -0
  11. data/doc/TODO.rd.ja +138 -0
  12. data/doc/Tutorial.rd +1138 -0
  13. data/doc/Tutorial.rd.ja +2110 -0
  14. data/etc/bioinformatics/seqdatabase.ini +210 -0
  15. data/lib/bio.rb +256 -0
  16. data/lib/bio/alignment.rb +1906 -0
  17. data/lib/bio/appl/bl2seq/report.rb +350 -0
  18. data/lib/bio/appl/blast.rb +269 -0
  19. data/lib/bio/appl/blast/format0.rb +1402 -0
  20. data/lib/bio/appl/blast/format8.rb +95 -0
  21. data/lib/bio/appl/blast/report.rb +652 -0
  22. data/lib/bio/appl/blast/rexml.rb +151 -0
  23. data/lib/bio/appl/blast/wublast.rb +553 -0
  24. data/lib/bio/appl/blast/xmlparser.rb +222 -0
  25. data/lib/bio/appl/blat/report.rb +392 -0
  26. data/lib/bio/appl/clustalw.rb +191 -0
  27. data/lib/bio/appl/clustalw/report.rb +154 -0
  28. data/lib/bio/appl/emboss.rb +68 -0
  29. data/lib/bio/appl/fasta.rb +262 -0
  30. data/lib/bio/appl/fasta/format10.rb +428 -0
  31. data/lib/bio/appl/fasta/format6.rb +37 -0
  32. data/lib/bio/appl/genscan/report.rb +570 -0
  33. data/lib/bio/appl/hmmer.rb +129 -0
  34. data/lib/bio/appl/hmmer/report.rb +556 -0
  35. data/lib/bio/appl/mafft.rb +222 -0
  36. data/lib/bio/appl/mafft/report.rb +119 -0
  37. data/lib/bio/appl/psort.rb +555 -0
  38. data/lib/bio/appl/psort/report.rb +473 -0
  39. data/lib/bio/appl/sim4.rb +134 -0
  40. data/lib/bio/appl/sim4/report.rb +501 -0
  41. data/lib/bio/appl/sosui/report.rb +166 -0
  42. data/lib/bio/appl/spidey/report.rb +604 -0
  43. data/lib/bio/appl/targetp/report.rb +283 -0
  44. data/lib/bio/appl/tmhmm/report.rb +238 -0
  45. data/lib/bio/command.rb +166 -0
  46. data/lib/bio/data/aa.rb +354 -0
  47. data/lib/bio/data/codontable.rb +740 -0
  48. data/lib/bio/data/na.rb +226 -0
  49. data/lib/bio/db.rb +340 -0
  50. data/lib/bio/db/aaindex.rb +280 -0
  51. data/lib/bio/db/embl/common.rb +332 -0
  52. data/lib/bio/db/embl/embl.rb +446 -0
  53. data/lib/bio/db/embl/sptr.rb +954 -0
  54. data/lib/bio/db/embl/swissprot.rb +32 -0
  55. data/lib/bio/db/embl/trembl.rb +31 -0
  56. data/lib/bio/db/embl/uniprot.rb +32 -0
  57. data/lib/bio/db/fantom.rb +604 -0
  58. data/lib/bio/db/fasta.rb +869 -0
  59. data/lib/bio/db/genbank/common.rb +299 -0
  60. data/lib/bio/db/genbank/ddbj.rb +34 -0
  61. data/lib/bio/db/genbank/genbank.rb +354 -0
  62. data/lib/bio/db/genbank/genpept.rb +73 -0
  63. data/lib/bio/db/genbank/refseq.rb +31 -0
  64. data/lib/bio/db/gff.rb +106 -0
  65. data/lib/bio/db/go.rb +497 -0
  66. data/lib/bio/db/kegg/brite.rb +51 -0
  67. data/lib/bio/db/kegg/cell.rb +88 -0
  68. data/lib/bio/db/kegg/compound.rb +130 -0
  69. data/lib/bio/db/kegg/enzyme.rb +125 -0
  70. data/lib/bio/db/kegg/expression.rb +173 -0
  71. data/lib/bio/db/kegg/genes.rb +293 -0
  72. data/lib/bio/db/kegg/genome.rb +362 -0
  73. data/lib/bio/db/kegg/glycan.rb +213 -0
  74. data/lib/bio/db/kegg/keggtab.rb +418 -0
  75. data/lib/bio/db/kegg/kgml.rb +299 -0
  76. data/lib/bio/db/kegg/ko.rb +178 -0
  77. data/lib/bio/db/kegg/reaction.rb +97 -0
  78. data/lib/bio/db/litdb.rb +131 -0
  79. data/lib/bio/db/medline.rb +317 -0
  80. data/lib/bio/db/nbrf.rb +199 -0
  81. data/lib/bio/db/pdb.rb +38 -0
  82. data/lib/bio/db/pdb/atom.rb +60 -0
  83. data/lib/bio/db/pdb/chain.rb +117 -0
  84. data/lib/bio/db/pdb/model.rb +106 -0
  85. data/lib/bio/db/pdb/pdb.rb +1682 -0
  86. data/lib/bio/db/pdb/residue.rb +122 -0
  87. data/lib/bio/db/pdb/utils.rb +234 -0
  88. data/lib/bio/db/prosite.rb +616 -0
  89. data/lib/bio/db/rebase.rb +417 -0
  90. data/lib/bio/db/transfac.rb +387 -0
  91. data/lib/bio/feature.rb +201 -0
  92. data/lib/bio/io/brdb.rb +103 -0
  93. data/lib/bio/io/das.rb +471 -0
  94. data/lib/bio/io/dbget.rb +212 -0
  95. data/lib/bio/io/ddbjxml.rb +614 -0
  96. data/lib/bio/io/fastacmd.rb +123 -0
  97. data/lib/bio/io/fetch.rb +114 -0
  98. data/lib/bio/io/flatfile.rb +496 -0
  99. data/lib/bio/io/flatfile/bdb.rb +266 -0
  100. data/lib/bio/io/flatfile/index.rb +1308 -0
  101. data/lib/bio/io/flatfile/indexer.rb +778 -0
  102. data/lib/bio/io/higet.rb +92 -0
  103. data/lib/bio/io/keggapi.rb +863 -0
  104. data/lib/bio/io/pubmed.rb +189 -0
  105. data/lib/bio/io/registry.rb +308 -0
  106. data/lib/bio/io/soapwsdl.rb +114 -0
  107. data/lib/bio/io/sql.rb +428 -0
  108. data/lib/bio/location.rb +650 -0
  109. data/lib/bio/pathway.rb +991 -0
  110. data/lib/bio/reference.rb +308 -0
  111. data/lib/bio/sequence.rb +593 -0
  112. data/lib/bio/shell.rb +51 -0
  113. data/lib/bio/shell/core.rb +512 -0
  114. data/lib/bio/shell/plugin/codon.rb +228 -0
  115. data/lib/bio/shell/plugin/entry.rb +85 -0
  116. data/lib/bio/shell/plugin/flatfile.rb +119 -0
  117. data/lib/bio/shell/plugin/keggapi.rb +187 -0
  118. data/lib/bio/shell/plugin/midi.rb +448 -0
  119. data/lib/bio/shell/plugin/obda.rb +63 -0
  120. data/lib/bio/shell/plugin/seq.rb +238 -0
  121. data/lib/bio/shell/session.rb +214 -0
  122. data/lib/bio/util/color_scheme.rb +214 -0
  123. data/lib/bio/util/color_scheme/buried.rb +78 -0
  124. data/lib/bio/util/color_scheme/helix.rb +78 -0
  125. data/lib/bio/util/color_scheme/hydropathy.rb +83 -0
  126. data/lib/bio/util/color_scheme/nucleotide.rb +50 -0
  127. data/lib/bio/util/color_scheme/strand.rb +78 -0
  128. data/lib/bio/util/color_scheme/taylor.rb +69 -0
  129. data/lib/bio/util/color_scheme/turn.rb +78 -0
  130. data/lib/bio/util/color_scheme/zappo.rb +69 -0
  131. data/lib/bio/util/contingency_table.rb +337 -0
  132. data/lib/bio/util/sirna.rb +306 -0
  133. data/lib/bioruby.rb +34 -0
  134. data/sample/biofetch.rb +475 -0
  135. data/sample/color_scheme_na.rb +99 -0
  136. data/sample/dbget +37 -0
  137. data/sample/fasta2tab.rb +99 -0
  138. data/sample/fsplit.rb +51 -0
  139. data/sample/gb2fasta.rb +31 -0
  140. data/sample/gb2tab.rb +325 -0
  141. data/sample/gbtab2mysql.rb +161 -0
  142. data/sample/genes2nuc.rb +33 -0
  143. data/sample/genes2pep.rb +33 -0
  144. data/sample/genes2tab.rb +81 -0
  145. data/sample/genome2rb.rb +29 -0
  146. data/sample/genome2tab.rb +76 -0
  147. data/sample/goslim.rb +311 -0
  148. data/sample/gt2fasta.rb +47 -0
  149. data/sample/pmfetch.rb +42 -0
  150. data/sample/pmsearch.rb +42 -0
  151. data/sample/psortplot_html.rb +222 -0
  152. data/sample/ssearch2tab.rb +96 -0
  153. data/sample/tdiary.rb +158 -0
  154. data/sample/tfastx2tab.rb +100 -0
  155. data/sample/vs-genes.rb +212 -0
  156. data/test/data/SOSUI/sample.report +11 -0
  157. data/test/data/TMHMM/sample.report +21 -0
  158. data/test/data/blast/eco:b0002.faa +15 -0
  159. data/test/data/blast/eco:b0002.faa.m0 +128 -0
  160. data/test/data/blast/eco:b0002.faa.m7 +65 -0
  161. data/test/data/blast/eco:b0002.faa.m8 +1 -0
  162. data/test/data/embl/AB090716.embl +65 -0
  163. data/test/data/genscan/sample.report +63 -0
  164. data/test/data/prosite/prosite.dat +2233 -0
  165. data/test/data/refseq/nm_126355.entret +64 -0
  166. data/test/data/uniprot/p53_human.uniprot +1456 -0
  167. data/test/runner.rb +10 -0
  168. data/test/unit/bio/appl/blast/test_report.rb +427 -0
  169. data/test/unit/bio/appl/blast/test_xmlparser.rb +400 -0
  170. data/test/unit/bio/appl/genscan/test_report.rb +195 -0
  171. data/test/unit/bio/appl/sosui/test_report.rb +94 -0
  172. data/test/unit/bio/appl/targetp/test_report.rb +159 -0
  173. data/test/unit/bio/appl/test_blast.rb +159 -0
  174. data/test/unit/bio/appl/test_fasta.rb +142 -0
  175. data/test/unit/bio/appl/tmhmm/test_report.rb +139 -0
  176. data/test/unit/bio/data/test_aa.rb +103 -0
  177. data/test/unit/bio/data/test_codontable.rb +120 -0
  178. data/test/unit/bio/data/test_na.rb +89 -0
  179. data/test/unit/bio/db/embl/test_common.rb +130 -0
  180. data/test/unit/bio/db/embl/test_embl.rb +227 -0
  181. data/test/unit/bio/db/embl/test_sptr.rb +268 -0
  182. data/test/unit/bio/db/embl/test_uniprot.rb +44 -0
  183. data/test/unit/bio/db/kegg/test_genes.rb +58 -0
  184. data/test/unit/bio/db/test_fasta.rb +263 -0
  185. data/test/unit/bio/db/test_gff.rb +140 -0
  186. data/test/unit/bio/db/test_prosite.rb +1450 -0
  187. data/test/unit/bio/io/test_ddbjxml.rb +87 -0
  188. data/test/unit/bio/io/test_soapwsdl.rb +45 -0
  189. data/test/unit/bio/shell/plugin/test_seq.rb +175 -0
  190. data/test/unit/bio/test_alignment.rb +1028 -0
  191. data/test/unit/bio/test_command.rb +71 -0
  192. data/test/unit/bio/test_db.rb +109 -0
  193. data/test/unit/bio/test_feature.rb +128 -0
  194. data/test/unit/bio/test_location.rb +51 -0
  195. data/test/unit/bio/test_pathway.rb +485 -0
  196. data/test/unit/bio/test_sequence.rb +386 -0
  197. data/test/unit/bio/test_shell.rb +31 -0
  198. data/test/unit/bio/util/test_color_scheme.rb +45 -0
  199. data/test/unit/bio/util/test_contingency_table.rb +106 -0
  200. data/test/unit/bio/util/test_sirna.rb +258 -0
  201. metadata +295 -0
@@ -0,0 +1,199 @@
1
+ #
2
+ # = bio/db/nbrf.rb - NBRF/PIR format sequence data class
3
+ #
4
+ # Copyright:: Copyright (C) 2001-2003 GOTO Naohisa <ngoto@gen-info.osaka-u.ac.jp>
5
+ # Copyright (C) 2001-2002 KATAYAMA Toshiaki <k@bioruby.org>
6
+ # License:: LGPL
7
+ #
8
+ #--
9
+ # This library is free software; you can redistribute it and/or
10
+ # modify it under the terms of the GNU Lesser General Public
11
+ # License as published by the Free Software Foundation; either
12
+ # version 2 of the License, or (at your option) any later version.
13
+ #
14
+ # This library is distributed in the hope that it will be useful,
15
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
+ # Lesser General Public License for more details.
18
+ #
19
+ # You should have received a copy of the GNU Lesser General Public
20
+ # License along with this library; if not, write to the Free Software
21
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
+ #++
23
+ #
24
+ # $Id: nbrf.rb,v 1.7 2005/12/18 15:58:41 k Exp $
25
+ #
26
+ # Sequence data class for NBRF/PIR flatfile format.
27
+ #
28
+ # = References
29
+ #
30
+ # * http://pir.georgetown.edu/pirwww/otherinfo/doc/techbulletin.html
31
+ # * http://www.sander.embl-ebi.ac.uk/Services/webin/help/webin-align/align_format_help.html#pir
32
+ # * http://www.cmbi.kun.nl/bioinf/tools/crab_pir.html
33
+ #
34
+
35
+ require 'bio/db'
36
+ require 'bio/sequence'
37
+
38
+ module Bio
39
+
40
+ # Sequence data class for NBRF/PIR flatfile format.
41
+ class NBRF < DB
42
+ #--
43
+ # based on Bio::FastaFormat class
44
+ #++
45
+
46
+ # Delimiter of each entry. Bio::FlatFile uses it.
47
+ DELIMITER = RS = "*\n"
48
+
49
+ # Creates a new NBRF object. It stores the comment and sequence
50
+ # information from one entry of the NBRF/PIR format string.
51
+ # If the argument contains more than one
52
+ # entry, only the first entry is used.
53
+ def initialize(str)
54
+ str = str.sub(/\A[\r\n]+/, '') # remove first void lines
55
+ line1, line2, rest = str.split(/^/, 3)
56
+
57
+ rest = rest.to_s
58
+ rest.sub!(/^>.*/m, '') # remove trailing entries for sure
59
+ @entry_overrun = $&
60
+ rest.sub!(/\*\s*\z/, '') # remove last '*' and "\n"
61
+ @data = rest
62
+
63
+ @definition = line2.to_s.chomp
64
+ if /^>?([A-Za-z0-9]{2})\;(.*)/ =~ line1.to_s then
65
+ @seq_type = $1
66
+ @entry_id = $2
67
+ end
68
+ end
69
+
70
+ # Returns sequence type described in the entry.
71
+ # P1 (protein), F1 (protein fragment)
72
+ # DL (DNA linear), DC (DNA circular)
73
+ # RL (DNA linear), RC (DNA circular)
74
+ # N3 (tRNA), N1 (other functional RNA)
75
+ attr_accessor :seq_type
76
+
77
+ # Returns ID described in the entry.
78
+ attr_accessor :entry_id
79
+ alias accession entry_id
80
+
81
+ # Returns the description line of the NBRF/PIR formatted data.
82
+ attr_accessor :definition
83
+
84
+ # sequence data of the entry (???)
85
+ attr_accessor :data
86
+
87
+ # piece of next entry. Bio::FlatFile uses it.
88
+ attr_reader :entry_overrun
89
+
90
+
91
+ # Returns the stored one entry as a NBRF/PIR format. (same as to_s)
92
+ def entry
93
+ @entry = ">#{@seq_type or 'XX'};#{@entry_id}\n#{definition}\n#{@data}*\n"
94
+ end
95
+ alias to_s entry
96
+
97
+ # Returns Bio::Sequence::AA, Bio::Sequence::NA, or Bio::Sequence,
98
+ # depending on sequence type.
99
+ def seq_class
100
+ case @seq_type
101
+ when /[PF]1/
102
+ # protein
103
+ Sequence::AA
104
+ when /[DR][LC]/, /N[13]/
105
+ # nucleic
106
+ Sequence::NA
107
+ else
108
+ Sequence
109
+ end
110
+ end
111
+
112
+ # Returns sequence data.
113
+ # Returns Bio::Sequence::NA, Bio::Sequence::AA or Bio::Sequence,
114
+ # according to the sequence type.
115
+ def seq
116
+ unless defined?(@seq)
117
+ @seq = seq_class.new(@data.tr(" \t\r\n0-9", '')) # lazy clean up
118
+ end
119
+ @seq
120
+ end
121
+
122
+ # Returns sequence length.
123
+ def length
124
+ seq.length
125
+ end
126
+
127
+ # Returens the nucleic acid sequence.
128
+ # If you call naseq for protein sequence, RuntimeError will be occurred.
129
+ # Use the method if you know whether the sequence is NA or AA.
130
+ def naseq
131
+ if seq.is_a?(Bio::Sequence::AA) then
132
+ raise 'not nucleic but protein sequence'
133
+ elsif seq.is_a?(Bio::Sequence::NA) then
134
+ seq
135
+ else
136
+ Bio::Sequence::NA.new(seq)
137
+ end
138
+ end
139
+
140
+ # Returens the length of sequence.
141
+ # If you call nalen for protein sequence, RuntimeError will be occurred.
142
+ # Use the method if you know whether the sequence is NA or AA.
143
+ def nalen
144
+ naseq.length
145
+ end
146
+
147
+ # Returens the protein (amino acids) sequence.
148
+ # If you call aaseq for nucleic acids sequence,
149
+ # RuntimeError will be occurred.
150
+ # Use the method if you know whether the sequence is NA or AA.
151
+ def aaseq
152
+ if seq.is_a?(Bio::Sequence::NA) then
153
+ raise 'not nucleic but protein sequence'
154
+ elsif seq.is_a?(Bio::Sequence::AA) then
155
+ seq
156
+ else
157
+ Bio::Sequence::AA.new(seq)
158
+ end
159
+ end
160
+
161
+ # Returens the length of protein (amino acids) sequence.
162
+ # If you call aaseq for nucleic acids sequence,
163
+ # RuntimeError will be occurred.
164
+ # Use the method if you know whether the sequence is NA or AA.
165
+ def aalen
166
+ aaseq.length
167
+ end
168
+
169
+ #--
170
+ #class method
171
+ #++
172
+
173
+ # Creates a NBRF/PIR formatted text.
174
+ # Parameters can be omitted.
175
+ def self.to_nbrf(hash)
176
+ seq_type = hash[:seq_type]
177
+ seq = hash[:seq]
178
+ unless seq_type
179
+ if seq.is_a?(Bio::Sequence::AA) then
180
+ seq_type = 'P1'
181
+ elsif seq.is_a?(Bio::Sequence::NA) then
182
+ seq_type = /u/i =~ seq ? 'RL' : 'DL'
183
+ else
184
+ seq_type = 'XX'
185
+ end
186
+ end
187
+ width = hash.has_key?(:width) ? hash[:width] : 70
188
+ if width then
189
+ seq = seq.to_s + "*"
190
+ seq.gsub!(Regexp.new(".{1,#{width}}"), "\\0\n")
191
+ else
192
+ seq = seq.to_s + "*\n"
193
+ end
194
+ ">#{seq_type};#{hash[:entry_id]}\n#{hash[:definition]}\n#{seq}"
195
+ end
196
+
197
+ end #class NBRF
198
+ end #module Bio
199
+
data/lib/bio/db/pdb.rb ADDED
@@ -0,0 +1,38 @@
1
+ #
2
+ # bio/db/pdb.rb - PDB database classes
3
+ #
4
+ # Copyright (C) 2004 GOTO Naohisa <ngoto@gen-info.osaka-u.ac.jp>
5
+ #
6
+ # This library is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU Lesser General Public
8
+ # License as published by the Free Software Foundation; either
9
+ # version 2 of the License, or (at your option) any later version.
10
+ #
11
+ # This library is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ # Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public
17
+ # License along with this library; if not, write to the Free Software
18
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
+ #
20
+ # $Id: pdb.rb,v 1.5 2005/12/16 19:23:03 ngoto Exp $
21
+ #
22
+
23
+ require 'bio/db'
24
+
25
+ # definition of the PDB class
26
+ module Bio
27
+ class PDB #< DB
28
+ end #class PDB
29
+ end #module Bio
30
+
31
+ # require other files under pdb directory
32
+ require 'bio/db/pdb/utils'
33
+ require 'bio/db/pdb/atom'
34
+ require 'bio/db/pdb/residue'
35
+ require 'bio/db/pdb/chain'
36
+ require 'bio/db/pdb/model'
37
+ require 'bio/db/pdb/pdb'
38
+
@@ -0,0 +1,60 @@
1
+ #
2
+ # bio/db/pdb/atom.rb - Coordinate and atom class for PDB
3
+ #
4
+ # Copyright (C) 2004 Alex Gutteridge <alexg@ebi.ac.uk>
5
+ # Copyright (C) 2004 GOTO Naohisa <ngoto@gen-info.osaka-u.ac.jp>
6
+ #
7
+ # This library is free software; you can redistribute it and/or
8
+ # modify it under the terms of the GNU Lesser General Public
9
+ # License as published by the Free Software Foundation; either
10
+ # version 2 of the License, or (at your option) any later version.
11
+ #
12
+ # This library is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ # Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public
18
+ # License along with this library; if not, write to the Free Software
19
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
+ #
21
+ # $Id: atom.rb,v 1.5 2005/12/18 17:33:32 ngoto Exp $
22
+
23
+ require 'matrix'
24
+ require 'bio/db/pdb'
25
+
26
+ module Bio
27
+ class PDB
28
+
29
+ class Coordinate < Vector
30
+ def self.[](x,y,z)
31
+ super
32
+ end
33
+
34
+ def self.elements(array, *a)
35
+ raise 'Size of given array must be 3' if array.size != 3
36
+ super
37
+ end
38
+
39
+ def x; self[0]; end
40
+ def y; self[1]; end
41
+ def z; self[2]; end
42
+ def x=(n); self[0]=n; end
43
+ def y=(n); self[1]=n; end
44
+ def z=(n); self[2]=n; end
45
+
46
+ # Definition of 'to_ary' means objects of the class is
47
+ # implicitly regarded as an array.
48
+ def to_ary; self.to_a; end
49
+
50
+ def xyz; self; end
51
+
52
+ def distance(object2)
53
+ Utils::to_xyz(object2)
54
+ (self - object2).r
55
+ end
56
+ end #class Coordinate
57
+
58
+ end #class PDB
59
+ end #class Bio
60
+
@@ -0,0 +1,117 @@
1
+ #
2
+ # bio/db/pdb/chain.rb - chain class for PDB
3
+ #
4
+ # Copyright (C) 2004 Alex Gutteridge <alexg@ebi.ac.uk>
5
+ #
6
+ # This library is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU Lesser General Public
8
+ # License as published by the Free Software Foundation; either
9
+ # version 2 of the License, or (at your option) any later version.
10
+ #
11
+ # This library is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ # Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public
17
+ # License along with this library; if not, write to the Free Software
18
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
+ #
20
+ # $Id: chain.rb,v 1.2 2005/09/26 13:00:08 k Exp $
21
+
22
+ require 'bio/db/pdb'
23
+
24
+ module Bio
25
+
26
+ class PDB
27
+
28
+ class Chain
29
+
30
+ include Utils
31
+ include AtomFinder
32
+ include ResidueFinder
33
+ include Enumerable
34
+ include Comparable
35
+
36
+ attr_reader :id, :model
37
+ attr_writer :id
38
+
39
+ def initialize(id = nil, model = nil)
40
+
41
+ @id = id
42
+
43
+ @model = model
44
+
45
+ @residues = Array.new
46
+ @ligands = Array.new
47
+
48
+ end
49
+
50
+ #Keyed access to residues based on ids
51
+ def [](key)
52
+ #If you want to find HETATMS you need to add LIGAND to the id
53
+ if key.to_s[0,6] == 'LIGAND'
54
+ residue = @ligands.find{ |residue| key.to_s == residue.id }
55
+ else
56
+ residue = @residues.find{ |residue| key.to_s == residue.id }
57
+ end
58
+ end
59
+
60
+ #Add a residue to this chain
61
+ def addResidue(residue)
62
+ raise "Expecting a Bio::PDB::Residue" if not residue.is_a? Bio::PDB::Residue
63
+ @residues.push(residue)
64
+ self
65
+ end
66
+
67
+ #Add a ligand to this chain
68
+ def addLigand(residue)
69
+ raise "Expecting a Bio::PDB::Residue" if not residue.is_a? Bio::PDB::Residue
70
+ @ligands.push(residue)
71
+ self
72
+ end
73
+
74
+ #Residue iterator
75
+ def each
76
+ @residues.each{ |residue| yield residue }
77
+ end
78
+ #Alias to override ResidueFinder#each_residue
79
+ alias each_residue each
80
+
81
+ #Sort based on chain id
82
+ def <=>(other)
83
+ return @id <=> other.id
84
+ end
85
+
86
+ #Stringifies each residue
87
+ def to_s
88
+ string = ""
89
+ @residues.each{ |residue| string << residue.to_s }
90
+ string = string << "TER\n"
91
+ return string
92
+ end
93
+
94
+ def atom_seq
95
+ string = ""
96
+ last_residue_num = nil
97
+ @residues.each{ |residue|
98
+ if last_residue_num and
99
+ (residue.resSeq.to_i - last_residue_num).abs > 1
100
+ (residue.resSeq.to_i - last_residue_num).abs.times{ string << 'X' }
101
+ end
102
+ tlc = residue.resName.capitalize
103
+ olc = AminoAcid.names.invert[tlc]
104
+ if !olc
105
+ olc = 'X'
106
+ end
107
+ string << olc
108
+ }
109
+ Bio::Sequence::AA.new(string)
110
+
111
+ end
112
+
113
+ end
114
+
115
+ end
116
+
117
+ end
@@ -0,0 +1,106 @@
1
+ #
2
+ # bio/db/pdb/model.rb - model class for PDB
3
+ #
4
+ # Copyright (C) 2004 Alex Gutteridge <alexg@ebi.ac.uk>
5
+ #
6
+ # This library is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU Lesser General Public
8
+ # License as published by the Free Software Foundation; either
9
+ # version 2 of the License, or (at your option) any later version.
10
+ #
11
+ # This library is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ # Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public
17
+ # License along with this library; if not, write to the Free Software
18
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
+ #
20
+ # $Id: model.rb,v 1.2 2005/09/26 13:00:08 k Exp $
21
+
22
+ require 'bio/db/pdb'
23
+
24
+ module Bio
25
+
26
+ class PDB
27
+
28
+ #Model class
29
+ class Model
30
+
31
+ include Utils
32
+ include AtomFinder
33
+ include ResidueFinder
34
+ include ChainFinder
35
+ include Enumerable
36
+ include Comparable
37
+
38
+ attr_reader :model_serial, :structure, :solvent
39
+ attr_writer :model_serial
40
+
41
+ def initialize(model_serial = nil, structure = nil)
42
+
43
+ @model_serial = model_serial
44
+
45
+ @structure = structure
46
+
47
+ @chains = Array.new
48
+ @solvent = Chain.new('',self)
49
+
50
+ end
51
+
52
+ #Adds a chain
53
+ def addChain(chain)
54
+ raise "Expecting a Bio::PDB::Chain" if not chain.is_a? Bio::PDB::Chain
55
+ @chains.push(chain)
56
+ self
57
+ end
58
+
59
+ #adds a solvent molecule
60
+ def addSolvent(solvent)
61
+ raise "Expecting a Bio::PDB::Residue" if not solvent.is_a? Bio::PDB::Residue
62
+ @solvent.addResidue(solvent)
63
+ end
64
+
65
+ def removeSolvent
66
+ @solvent = nil
67
+ end
68
+
69
+ #Chain iterator
70
+ def each
71
+ @chains.each{ |chain| yield chain }
72
+ end
73
+ #Alias to override ChainFinder#each_chain
74
+ alias each_chain each
75
+
76
+ #Sorts models based on serial number
77
+ def <=>(other)
78
+ return @mode_serial <=> other.model_serial
79
+ end
80
+
81
+ #Keyed access to chains
82
+ def [](key)
83
+ chain = @chains.find{ |chain| key == chain.id }
84
+ end
85
+
86
+ #stringifies to chains
87
+ def to_s
88
+ string = ""
89
+ if model_serial
90
+ string = "MODEL #{model_serial}" #Should use proper formatting
91
+ end
92
+ @chains.each{ |chain| string << chain.to_s }
93
+ if solvent
94
+ string << @solvent.to_s
95
+ end
96
+ if model_serial
97
+ string << "ENDMDL"
98
+ end
99
+ return string
100
+ end
101
+
102
+ end #class Model
103
+
104
+ end
105
+
106
+ end