Package prompt :: Module sequence
[hide private]
[frames] | no frames]

Source Code for Module prompt.sequence

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2003, 2004 Edward d'Auvergne                                  # 
  4  #                                                                             # 
  5  # This file is part of the program relax.                                     # 
  6  #                                                                             # 
  7  # relax is free software; you can redistribute it and/or modify               # 
  8  # it under the terms of the GNU General Public License as published by        # 
  9  # the Free Software Foundation; either version 2 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # relax 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               # 
 15  # GNU General Public License for more details.                                # 
 16  #                                                                             # 
 17  # You should have received a copy of the GNU General Public License           # 
 18  # along with relax; if not, write to the Free Software                        # 
 19  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   # 
 20  #                                                                             # 
 21  ############################################################################### 
 22   
 23  import sys 
 24   
 25  import help 
 26   
 27   
28 -class Sequence:
29 - def __init__(self, relax):
30 # Help. 31 self.__relax_help__ = \ 32 """Class for manipulating sequence data.""" 33 34 # Add the generic help string. 35 self.__relax_help__ = self.__relax_help__ + "\n" + help.relax_class_help 36 37 # Place relax in the class namespace. 38 self.__relax__ = relax
39 40
41 - def add(self, run=None, res_num=None, res_name=None, select=1):
42 """Function for adding a residue onto the sequence. 43 44 Keyword Arguments 45 ~~~~~~~~~~~~~~~~~ 46 47 run: The name of the run. 48 49 res_num: The residue number. 50 51 res_name: The name of the residue. 52 53 select: A flag specifying if the residue should be selected. 54 55 56 Description 57 ~~~~~~~~~~~ 58 59 Using this function a new sequence can be generated without having to load the sequence from 60 a file. However if the sequence already exists, the new residue will be added to the end. 61 The same residue number cannot be used more than once. 62 63 64 Examples 65 ~~~~~~~~ 66 67 The following sequence of commands will generate the sequence 1 ALA, 2 GLY, 3 LYS and assign 68 it to the run 'm3': 69 70 relax> run = 'm3' 71 relax> sequence.add(run, 1, 'ALA') 72 relax> sequence.add(run, 2, 'GLY') 73 relax> sequence.add(run, 3, 'LYS') 74 """ 75 76 # Function intro text. 77 if self.__relax__.interpreter.intro: 78 text = sys.ps3 + "sequence.add(" 79 text = text + "run=" + `run` 80 text = text + ", res_num=" + `res_num` 81 text = text + ", res_name=" + `res_name` 82 text = text + ", select=" + `select` + ")" 83 print text 84 85 # The run argument. 86 if type(run) != str: 87 raise RelaxStrError, ('run', run) 88 89 # Residue number. 90 if type(res_num) != int: 91 raise RelaxIntError, ('residue number', res_num) 92 93 # Residue name. 94 if type(res_name) != str: 95 raise RelaxStrError, ('residue name', res_name) 96 97 # Select flag. 98 if type(select) != int or (select != 0 and select != 1): 99 raise RelaxBinError, ('select', select) 100 101 # Execute the functional code. 102 self.__relax__.generic.sequence.add(run=run, res_num=res_num, res_name=res_name, select=select)
103 104
105 - def copy(self, run1=None, run2=None):
106 """Function for copying the sequence from run1 to run2. 107 108 Keyword Arguments 109 ~~~~~~~~~~~~~~~~~ 110 111 run1: The name of the run to copy the sequence from. 112 113 run2: The name of the run to copy the sequence to. 114 115 116 Description 117 ~~~~~~~~~~~ 118 119 This function will copy the sequence from 'run1' to 'run2'. 'run1' must contain sequence 120 information, while 'run2' must have no sequence loaded. 121 122 123 Examples 124 ~~~~~~~~ 125 126 To copy the sequence from the run 'm1' to the run 'm2', type: 127 128 relax> sequence.copy('m1', 'm2') 129 relax> sequence.copy(run1='m1', run2='m2') 130 """ 131 132 # Function intro text. 133 if self.__relax__.interpreter.intro: 134 text = sys.ps3 + "sequence.copy(" 135 text = text + "run1=" + `run1` 136 text = text + ", run2=" + `run2` + ")" 137 print text 138 139 # The run1 argument. 140 if type(run1) != str: 141 raise RelaxStrError, ('run1', run1) 142 143 # The run2 argument. 144 if type(run2) != str: 145 raise RelaxStrError, ('run2', run2) 146 147 # Execute the functional code. 148 self.__relax__.generic.sequence.copy(run1=run1, run2=run2)
149 150
151 - def delete(self, run=None):
152 """Function for deleting the sequence. 153 154 Keyword Arguments 155 ~~~~~~~~~~~~~~~~~ 156 157 run: The name of the run. 158 159 160 Description 161 ~~~~~~~~~~~ 162 163 This function has the same effect as using the 'delete' function to delete all residue 164 specific data. 165 """ 166 167 # Function intro text. 168 if self.__relax__.interpreter.intro: 169 text = sys.ps3 + "sequence.delete(" 170 text = text + "run=" + `run` + ")" 171 print text 172 173 # The run argument. 174 if type(run) != str: 175 raise RelaxStrError, ('run', run) 176 177 # Execute the functional code. 178 self.__relax__.generic.sequence.delete(run=run)
179 180
181 - def display(self, run=None):
182 """Function for displaying the sequence. 183 184 Keyword Arguments 185 ~~~~~~~~~~~~~~~~~ 186 187 run: The name of the run. 188 """ 189 190 # Function intro text. 191 if self.__relax__.interpreter.intro: 192 text = sys.ps3 + "sequence.display(" 193 text = text + "run=" + `run` + ")" 194 print text 195 196 # The run argument. 197 if type(run) != str: 198 raise RelaxStrError, ('run', run) 199 200 # Execute the functional code. 201 self.__relax__.generic.sequence.display(run=run)
202 203
204 - def read(self, run=None, file=None, dir=None, num_col=0, name_col=1, sep=None):
205 """Function for reading sequence data. 206 207 Keyword Arguments 208 ~~~~~~~~~~~~~~~~~ 209 210 run: The name of the run. 211 212 file: The name of the file containing the sequence data. 213 214 dir: The directory where the file is located. 215 216 num_col: The residue number column (the default is 0, ie the first column). 217 218 name_col: The residue name column (the default is 1). 219 220 sep: The column separator (the default is white space). 221 222 223 Description 224 ~~~~~~~~~~~ 225 226 If no directory is given, the file will be assumed to be in the current working directory. 227 228 229 Examples 230 ~~~~~~~~ 231 232 The following commands will read the sequence data out of a file called 'seq' where the 233 residue numbers and names are in the first and second columns respectively and assign it to 234 the run 'm1'. 235 236 relax> sequence.read('m1', 'seq') 237 relax> sequence.read('m1', 'seq', num_col=0, name_col=1) 238 relax> sequence.read(run='m1', file='seq', num_col=0, name_col=1, sep=None) 239 240 241 The following commands will read the sequence out of the file 'noe.out' which also contains 242 the NOE values. 243 244 relax> sequence.read('m1', 'noe.out') 245 relax> sequence.read('m1', 'noe.out', num_col=0, name_col=1) 246 relax> sequence.read(run='m1', file='noe.out', num_col=0, name_col=1) 247 248 249 The following commands will read the sequence out of the file 'noe.600.out' where the 250 residue numbers are in the second column, the names are in the sixth column and the columns 251 are separated by commas and assign it to the run 'm5'. 252 253 relax> sequence.read('m5', 'noe.600.out', num_col=1, name_col=5, sep=',') 254 relax> sequence.read(run='m5', file='noe.600.out', num_col=1, name_col=5, sep=',') 255 """ 256 257 # Function intro text. 258 if self.__relax__.interpreter.intro: 259 text = sys.ps3 + "sequence.read(" 260 text = text + "run=" + `run` 261 text = text + ", file=" + `file` 262 text = text + ", dir=" + `dir` 263 text = text + ", num_col=" + `num_col` 264 text = text + ", name_col=" + `name_col` 265 text = text + ", sep=" + `sep` + ")" 266 print text 267 268 # The run argument. 269 if type(run) != str: 270 raise RelaxStrError, ('run', run) 271 272 # The file name. 273 if type(file) != str: 274 raise RelaxStrError, ('file name', file) 275 276 # Directory. 277 if dir != None and type(dir) != str: 278 raise RelaxNoneStrError, ('directory name', dir) 279 280 # Number column. 281 if type(num_col) != int: 282 raise RelaxIntError, ('residue number column', num_col) 283 284 # Name column. 285 if type(name_col) != int: 286 raise RelaxIntError, ('residue name column', name_col) 287 288 # Column separator. 289 if sep != None and type(sep) != str: 290 raise RelaxNoneStrError, ('column separator', sep) 291 292 # Execute the functional code. 293 self.__relax__.generic.sequence.read(run=run, file=file, dir=dir, num_col=num_col, name_col=name_col, sep=sep)
294 295
296 - def sort(self, run=None):
297 """Function for numerically sorting the sequence by residue number. 298 299 Keyword Arguments 300 ~~~~~~~~~~~~~~~~~ 301 302 run: The name of the run. 303 """ 304 305 # Function intro text. 306 if self.__relax__.interpreter.intro: 307 text = sys.ps3 + "sequence.sort(" 308 text = text + "run=" + `run` + ")" 309 print text 310 311 # The run argument. 312 if type(run) != str: 313 raise RelaxStrError, ('run', run) 314 315 # Execute the functional code. 316 self.__relax__.generic.sequence.sort(run=run)
317 318
319 - def write(self, run=None, file=None, dir=None, force=0):
320 """Function for writing the sequence to a file. 321 322 Keyword Arguments 323 ~~~~~~~~~~~~~~~~~ 324 325 run: The name of the run. 326 327 file: The name of the file. 328 329 dir: The directory name. 330 331 force: A flag which, if set to 1, will cause the file to be overwritten. 332 333 334 Description 335 ~~~~~~~~~~~ 336 337 If no directory name is given, the file will be placed in the current working directory. 338 """ 339 340 # Function intro text. 341 if self.__relax__.interpreter.intro: 342 text = sys.ps3 + "sequence.write(" 343 text = text + "run=" + `run` 344 text = text + ", file=" + `file` 345 text = text + ", dir=" + `dir` 346 text = text + ", force=" + `force` + ")" 347 print text 348 349 # The run argument. 350 if type(run) != str: 351 raise RelaxStrError, ('run', run) 352 353 # File. 354 if type(file) != str: 355 raise RelaxStrError, ('file name', file) 356 357 # Directory. 358 if dir != None and type(dir) != str: 359 raise RelaxNoneStrError, ('directory name', dir) 360 361 # The force flag. 362 if type(force) != int or (force != 0 and force != 1): 363 raise RelaxBinError, ('force flag', force) 364 365 # Execute the functional code. 366 self.__relax__.generic.sequence.write(run=run, file=file, dir=dir, force=force)
367