Debian Codegraph @

weblogo/data.py

raw
1 # Copyright (c) 2006, The Regents of the University of California, through
2 # Lawrence Berkeley National Laboratory (subject to receipt of any required
3 # approvals from the U.S. Dept. of Energy). All rights reserved.
4
5 # This software is distributed under the new BSD Open Source License.
6 # <http://www.opensource.org/licenses/bsd-license.html>
7 #
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions are met:
10 #
11 # (1) Redistributions of source code must retain the above copyright notice,
12 # this list of conditions and the following disclaimer.
13 #
14 # (2) Redistributions in binary form must reproduce the above copyright
15 # notice, this list of conditions and the following disclaimer in the
16 # documentation and or other materials provided with the distribution.
17 #
18 # (3) Neither the name of the University of California, Lawrence Berkeley
19 # National Laboratory, U.S. Dept. of Energy nor the names of its contributors
20 # may be used to endorse or promote products derived from this software
21 # without specific prior written permission.
22 #
23 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 # POSSIBILITY OF SUCH DAMAGE.
34
35 """
36 Standard data used in computational biology.
37
38
39 To convert a property dictionary to a list :
40 >>> comp = [ amino_acid_composition[k] for k in amino_acid_letters]
41
42
43 Attributes:
44 - amino_acid_letters
45 -- Standard codes for the 20 canonical amino acids, in alphabetic
46 order.
47
48 - amino_acid_alternative_letters
49 -- Amino acid one letter codes, alphabetic by three letter codes.
50
51 - amino_acid_extended_letters
52
53 - dna_letters
54
55 - dna_extended_letters
56
57 - rna_letters
58
59 - rna_extended_letters
60
61 - dna_ambiguity
62
63 - rna_ambiguity
64
65 - amino_acid_ambiguity
66
67 - amino_acid_mass
68 -- Monomer isotopically averaged molecular mass
69
70 - dna_mass
71
72 - rna_mass
73
74 - one_to_three
75 -- Map from standard 1 letter amino acid codes to standard three
76 letter codes.
77 Ref: http://www.ebi.ac.uk/RESID/faq.html
78
79 - standard_three_to_one
80 -- Map from standard 3 letter amino acid codes to standard 1
81 letter codes.
82
83 - extended_three_to_one
84 -- Map between three letter amino acid codes (first letter capitalized)
85 and standard one letter codes. This map contains many nonstandard three
86 letter codes, used, for example, to specify chemically modified amino
87 acids in PDB files.
88 Ref: http://astral.berkeley.edu/
89 Ref: http://www.ebi.ac.uk/RESID/faq.html
90
91 - amino_acid_names
92
93 - amino_acid_composition
94 -- Average amino acid composition of proteins.
95 Ref: McCaldon P., Argos P. Proteins 4:99-122 (1988).
96
97 - kyte_doolittle_hydrophobicity
98 -- Kyte-Doolittle hydrophobicity scale.
99 Ref: Kyte J., Doolittle R.F. J. Mol. Biol. 157:105-132 (1982)
100
101 - nucleotide_names
102
103 Status: Beta (Data needs to be proof checked.)
104 """
105
106 # FIXME: Proof check data
107 # FIXME: Add __all__
108
109 # The ExPasy ProtScale tool is a great source of amino acid properties.
110 # http://au.expasy.org/cgi-bin/protscale.pl
111
112 from . import utils
113
114 # Explicitly list set of available data resources. We want to be able to access
115 # these resources in, for example, a webapp, without inadvertently allowing
116 # unrestricted read access to the local file system.
117
118
119 amino_acid_letters = "ACDEFGHIKLMNPQRSTVWY"
120
121 amino_acid_alternative_letters = "ARNDCQEGHILKMFPSTWYV"
122
123 amino_acid_extended_letters = "ACDEFGHIKLMNOPQRSTUVWYBJZX*-"
124
125 dna_letters = "GATC"
126 dna_extended_letters = "GATCRYWSMKHBVDN"
127
128 rna_letters = "GAUC"
129 rna_extended_letters = "GAUCRYWSMKHBVDN"
130
131 dna_ambiguity = {
132 "A": "A",
133 "C": "C",
134 "G": "G",
135 "T": "T",
136 "M": "AC",
137 "R": "AG",
138 "W": "AT",
139 "S": "CG",
140 "Y": "CT",
141 "K": "GT",
142 "V": "ACG",
143 "H": "ACT",
144 "D": "AGT",
145 "B": "CGT",
146 "X": "GATC",
147 "N": "GATC",
148 }
149
150 rna_ambiguity = {
151 "A": "A",
152 "C": "C",
153 "G": "G",
154 "U": "U",
155 "M": "AC",
156 "R": "AG",
157 "W": "AU",
158 "S": "CG",
159 "Y": "CU",
160 "K": "GU",
161 "V": "ACG",
162 "H": "ACU",
163 "D": "AGU",
164 "B": "CGU",
165 "X": "GAUC",
166 "N": "GAUC",
167 }
168
169 amino_acid_ambiguity = {
170 "A": "A",
171 "B": "ND",
172 "C": "C",
173 "D": "D",
174 "E": "E",
175 "F": "F",
176 "G": "G",
177 "H": "H",
178 "I": "I",
179 "K": "K",
180 "L": "L",
181 "M": "M",
182 "N": "N",
183 "P": "P",
184 "Q": "Q",
185 "R": "R",
186 "S": "S",
187 "T": "T",
188 "V": "V",
189 "W": "W",
190 "X": "ACDEFGHIKLMNPQRSTVWY",
191 "Y": "Y",
192 "Z": "QE",
193 "J": "IL",
194 "U": "U",
195 "O": "O",
196 }
197
198 # Monomer isotopically averaged molecular mass
199 # Data Checked GEC Nov 2006
200 amino_acid_mass = {
201 "A": 89.09,
202 "B": 132.66, # Averaged proportional to amino_acid_composition
203 "C": 121.16,
204 "D": 133.10,
205 "E": 147.13,
206 "F": 165.19,
207 "G": 75.07,
208 "H": 155.16,
209 "I": 131.18,
210 "J": 131.18,
211 "K": 146.19,
212 "L": 131.18,
213 "M": 149.21,
214 "N": 132.12,
215 # "O" : ???, # TODO
216 "P": 115.13,
217 "Q": 146.15,
218 "R": 174.20,
219 "S": 105.09,
220 "T": 119.12,
221 "U": 168.05,
222 "V": 117.15,
223 "W": 204.23,
224 "X": 129.15, # Averaged proportional to amino_acid_composition
225 "Y": 181.19,
226 "Z": 146.76, # Averaged proportional to amino_acid_composition
227 }
228
229 dna_mass = {
230 "A": 347.0,
231 "C": 323.0,
232 "G": 363.0,
233 "T": 322.0,
234 }
235
236 rna_mass = {
237 "A": 363.0,
238 "C": 319.0,
239 "G": 379.0,
240 "U": 340.0,
241 }
242
243 one_to_three = {
244 "A": "Ala",
245 "B": "Asx",
246 "C": "Cys",
247 "D": "Asp",
248 "E": "Glu",
249 "F": "Phe",
250 "G": "Gly",
251 "H": "His",
252 "I": "Ile",
253 "K": "Lys",
254 "L": "Leu",
255 "M": "Met",
256 "N": "Asn",
257 "P": "Pro",
258 "Q": "Gln",
259 "R": "Arg",
260 "S": "Ser",
261 "T": "Thr",
262 "V": "Val",
263 "W": "Trp",
264 "Y": "Tyr",
265 "Z": "Glx",
266 "X": "Xaa",
267 "U": "Sec",
268 "J": "Xle",
269 "O": "Pyl",
270 }
271
272 standard_three_to_one = utils.invert_dict(one_to_three)
273
274 extended_three_to_one = {
275 "2as": "D",
276 "3ah": "H",
277 "5hp": "E",
278 "Acl": "R",
279 "Agm": "R",
280 "Aib": "A",
281 "Ala": "A",
282 "Alm": "A",
283 "Alo": "T",
284 "Aly": "K",
285 "Arg": "R",
286 "Arm": "R",
287 "Asa": "D",
288 "Asb": "D",
289 "Ask": "D",
290 "Asl": "D",
291 "Asn": "N",
292 "Asp": "D",
293 "Asq": "D",
294 "Asx": "B",
295 "Aya": "A",
296 "Bcs": "C",
297 "Bhd": "D",
298 "Bmt": "T",
299 "Bnn": "A",
300 "Buc": "C",
301 "Bug": "L",
302 "C5c": "C",
303 "C6c": "C",
304 "Ccs": "C",
305 "Cea": "C",
306 "Cgu": "E",
307 "Chg": "A",
308 "Cle": "L",
309 "Cme": "C",
310 "Csd": "A",
311 "Cso": "C",
312 "Csp": "C",
313 "Css": "C",
314 "Csw": "C",
315 "Csx": "C",
316 "Cxm": "M",
317 "Cy1": "C",
318 "Cy3": "C",
319 "Cyg": "C",
320 "Cym": "C",
321 "Cyq": "C",
322 "Cys": "C",
323 "Dah": "F",
324 "Dal": "A",
325 "Dar": "R",
326 "Das": "D",
327 "Dcy": "C",
328 "Dgl": "E",
329 "Dgn": "Q",
330 "Dha": "A",
331 "Dhi": "H",
332 "Dil": "I",
333 "Div": "V",
334 "Dle": "L",
335 "Dly": "K",
336 "Dnp": "A",
337 "Dpn": "F",
338 "Dpr": "P",
339 "Dsn": "S",
340 "Dsp": "D",
341 "Dth": "T",
342 "Dtr": "W",
343 "Dty": "Y",
344 "Dva": "V",
345 "Efc": "C",
346 "Fla": "A",
347 "Fme": "M",
348 "Ggl": "E",
349 "Gl3": "G",
350 "Gln": "Q",
351 "Glu": "E",
352 "Glx": "Z",
353 "Gly": "G",
354 "Glz": "G",
355 "Gma": "E",
356 "Gsc": "G",
357 "Hac": "A",
358 "Har": "R",
359 "Hic": "H",
360 "Hip": "H",
361 "His": "H",
362 "Hmr": "R",
363 "Hpq": "F",
364 "Htr": "W",
365 "Hyp": "P",
366 "Iil": "I",
367 "Ile": "I",
368 "Iyr": "Y",
369 "Kcx": "K",
370 "Leu": "L",
371 "Llp": "K",
372 "Lly": "K",
373 "Ltr": "W",
374 "Lym": "K",
375 "Lys": "K",
376 "Lyz": "K",
377 "Maa": "A",
378 "Men": "N",
379 "Met": "M",
380 "Mhs": "H",
381 "Mis": "S",
382 "Mle": "L",
383 "Mpq": "G",
384 "Msa": "G",
385 "Mse": "M",
386 "Mva": "V",
387 "Nem": "H",
388 "Nep": "H",
389 "Nle": "L",
390 "Nln": "L",
391 "Nlp": "L",
392 "Nmc": "G",
393 "Oas": "S",
394 "Ocs": "C",
395 "Omt": "M",
396 "Paq": "Y",
397 "Pca": "E",
398 "Pec": "C",
399 "Phe": "F",
400 "Phi": "F",
401 "Phl": "F",
402 "Pr3": "C",
403 "Pro": "P",
404 "Prr": "A",
405 "Ptr": "Y",
406 "Pyl": "O",
407 "Sac": "S",
408 "Sar": "G",
409 "Sch": "C",
410 "Scs": "C",
411 "Scy": "C",
412 "Sec": "U",
413 "Sel": "U",
414 "Sep": "S",
415 "Ser": "S",
416 "Set": "S",
417 "Shc": "C",
418 "Shr": "K",
419 "Smc": "C",
420 "Soc": "C",
421 "Sty": "Y",
422 "Sva": "S",
423 "Ter": "*",
424 "Thr": "T",
425 "Tih": "A",
426 "Tpl": "W",
427 "Tpo": "T",
428 "Tpq": "A",
429 "Trg": "K",
430 "Tro": "W",
431 "Trp": "W",
432 "Tyb": "Y",
433 "Tyq": "Y",
434 "Tyr": "Y",
435 "Tys": "Y",
436 "Tyy": "Y",
437 "Unk": "X",
438 "Val": "V",
439 "Xaa": "X",
440 "Xer": "X",
441 "Xle": "J",
442 }
443 # Initial table is from the ASTRAL RAF release notes.
444 # added UNK
445 # Extra IUPAC: Xle, Xaa, Sec, Pyl
446 # The following have been seen in biopython code.
447 # Ter : '*' Termination
448 # Sel : 'U' A typo for Sec, selenocysteine?
449 # Xer : 'X' Another alternative for unknown?
450
451
452 amino_acid_names = {
453 "A": "alanine",
454 "M": "methionine",
455 "C": "cysteine",
456 "N": "asparagine",
457 "D": "aspartic acid",
458 "P": "proline",
459 "E": "glutamic acid",
460 "Q": "glutamine",
461 "F": "phenylalanine",
462 "R": "arginine",
463 "G": "glycine",
464 "S": "serine",
465 "H": "histidine",
466 "T": "threonine",
467 "I": "isoleucine",
468 "V": "valine",
469 "K": "lysine",
470 "W": "tryptophan",
471 "L": "leucine",
472 "Y": "tyrosine",
473 "B": "aspartic acid or asparagine",
474 "J": "leucine or isoleucine",
475 "X": "unknown",
476 "Z": "glutamic acid or glutamine",
477 "U": "selenocysteine",
478 "O": "pyrrolysine",
479 "*": "translation stop",
480 "-": "gap",
481 }
482
483 amino_acid_composition = dict(
484 A=0.082,
485 R=0.057,
486 N=0.044,
487 D=0.053,
488 C=0.017,
489 Q=0.040,
490 E=0.062,
491 G=0.072,
492 H=0.022,
493 I=0.052, # noqa: E741
494 L=0.090,
495 K=0.057,
496 M=0.024,
497 F=0.039,
498 P=0.051,
499 S=0.069,
500 T=0.058,
501 W=0.013,
502 Y=0.032,
503 V=0.066,
504 )
505
506 kyte_doolittle_hydrophobicity = dict(
507 A=1.8,
508 R=-4.5,
509 N=-3.5,
510 D=-3.5,
511 C=2.5,
512 Q=-3.5,
513 E=-3.5,
514 G=-0.4,
515 H=-3.2,
516 I=4.5, # noqa: E741
517 L=3.8,
518 K=-3.9,
519 M=1.9,
520 F=2.8,
521 P=-1.6,
522 S=-0.8,
523 T=-0.7,
524 W=-0.9,
525 Y=-1.3,
526 V=4.2,
527 )
528
529 nucleotide_names = {
530 "A": "Adenosine",
531 "C": "Cytidine",
532 "G": "Guanine",
533 "T": "Thymidine",
534 "U": "Uracil",
535 "R": "G A (puRine)",
536 "Y": "T C (pYrimidine)",
537 "K": "G T (Ketone)",
538 "M": "A C (aMino group)",
539 "S": "G C (Strong interaction)",
540 "W": "A T (Weak interaction)",
541 "B": "G T C (not A) (B comes after A)",
542 "D": "G A T (not C) (D comes after C)",
543 "H": "A C T (not G) (H comes after G)",
544 "V": "G C A (not T, not U) (V comes after U)",
545 "N": "A G C T (aNy)",
546 "-": "gap",
547 }