| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#include <esl_config.h> |
| 21 |
|
| 22 |
#include <stdlib.h> |
| 23 |
#include <stdio.h> |
| 24 |
#include <string.h> |
| 25 |
|
| 26 |
#include "easel.h" |
| 27 |
#include "esl_alphabet.h" |
| 28 |
#include "esl_fileparser.h" |
| 29 |
#include "esl_getopts.h" |
| 30 |
#include "esl_regexp.h" |
| 31 |
#include "esl_sq.h" |
| 32 |
#include "esl_sqio.h" |
| 33 |
|
| 34 |
#include "esl_gencode.h" |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
static const ESL_GENCODE esl_transl_tables[] = { |
| 51 |
{ 1, "Standard", |
| 52 |
|
| 53 |
{ 8, 11, 8, 11, 16, 16, 16, 16, 14, 15, 14, 15, 7, 7, 10, 7, 13, 6, 13, 6, 12, 12, 12, 12, 14, 14, 14, 14, 9, 9, 9, 9, 3, 2, 3, 2, 0, 0, 0, 0, 5, 5, 5, 5, 17, 17, 17, 17, 27, 19, 27, 19, 15, 15, 15, 15, 27, 1, 18, 1, 9, 4, 9, 4 }, |
| 54 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 }, |
| 55 |
|
| 56 |
NULL, NULL }, |
| 57 |
|
| 58 |
{ 2, "Vertebrate mitochondrial", |
| 59 |
|
| 60 |
{ 8, 11, 8, 11, 16, 16, 16, 16, 27, 15, 27, 15, 10, 7, 10, 7, 13, 6, 13, 6, 12, 12, 12, 12, 14, 14, 14, 14, 9, 9, 9, 9, 3, 2, 3, 2, 0, 0, 0, 0, 5, 5, 5, 5, 17, 17, 17, 17, 27, 19, 27, 19, 15, 15, 15, 15, 18, 1, 18, 1, 9, 4, 9, 4 }, |
| 61 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 62 |
|
| 63 |
NULL, NULL }, |
| 64 |
|
| 65 |
{ 3, "Yeast mitochondrial", |
| 66 |
|
| 67 |
{ 8, 11, 8, 11, 16, 16, 16, 16, 14, 15, 14, 15, 10, 7, 10, 7, 13, 6, 13, 6, 12, 12, 12, 12, 14, 14, 14, 14, 16, 16, 16, 16, 3, 2, 3, 2, 0, 0, 0, 0, 5, 5, 5, 5, 17, 17, 17, 17, 27, 19, 27, 19, 15, 15, 15, 15, 18, 1, 18, 1, 9, 4, 9, 4 }, |
| 68 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 69 |
|
| 70 |
NULL, NULL }, |
| 71 |
|
| 72 |
{ 4, "Mold, protozoan, coelenterate mitochondrial; Mycoplasma/Spiroplasma", |
| 73 |
|
| 74 |
{ 8, 11, 8, 11, 16, 16, 16, 16, 14, 15, 14, 15, 7, 7, 10, 7, 13, 6, 13, 6, 12, 12, 12, 12, 14, 14, 14, 14, 9, 9, 9, 9, 3, 2, 3, 2, 0, 0, 0, 0, 5, 5, 5, 5, 17, 17, 17, 17, 27, 19, 27, 19, 15, 15, 15, 15, 18, 1, 18, 1, 9, 4, 9, 4 }, |
| 75 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0 }, |
| 76 |
|
| 77 |
NULL, NULL }, |
| 78 |
|
| 79 |
{ 5, "Invertebrate mitochondrial", |
| 80 |
|
| 81 |
{ 8, 11, 8, 11, 16, 16, 16, 16, 15, 15, 15, 15, 10, 7, 10, 7, 13, 6, 13, 6, 12, 12, 12, 12, 14, 14, 14, 14, 9, 9, 9, 9, 3, 2, 3, 2, 0, 0, 0, 0, 5, 5, 5, 5, 17, 17, 17, 17, 27, 19, 27, 19, 15, 15, 15, 15, 18, 1, 18, 1, 9, 4, 9, 4 }, |
| 82 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 }, |
| 83 |
|
| 84 |
NULL, NULL }, |
| 85 |
|
| 86 |
{ 6, "Ciliate, dasycladacean, Hexamita nuclear", |
| 87 |
|
| 88 |
{ 8, 11, 8, 11, 16, 16, 16, 16, 14, 15, 14, 15, 7, 7, 10, 7, 13, 6, 13, 6, 12, 12, 12, 12, 14, 14, 14, 14, 9, 9, 9, 9, 3, 2, 3, 2, 0, 0, 0, 0, 5, 5, 5, 5, 17, 17, 17, 17, 13, 19, 13, 19, 15, 15, 15, 15, 27, 1, 18, 1, 9, 4, 9, 4 }, |
| 89 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 90 |
|
| 91 |
NULL, NULL }, |
| 92 |
|
| 93 |
{ 9, "Echinoderm and flatworm mitochondrial", |
| 94 |
|
| 95 |
{ 11, 11, 8, 11, 16, 16, 16, 16, 15, 15, 15, 15, 7, 7, 10, 7, 13, 6, 13, 6, 12, 12, 12, 12, 14, 14, 14, 14, 9, 9, 9, 9, 3, 2, 3, 2, 0, 0, 0, 0, 5, 5, 5, 5, 17, 17, 17, 17, 27, 19, 27, 19, 15, 15, 15, 15, 18, 1, 18, 1, 9, 4, 9, 4 }, |
| 96 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 97 |
|
| 98 |
NULL, NULL }, |
| 99 |
|
| 100 |
{ 10, "Euplotid nuclear", |
| 101 |
|
| 102 |
{ 8, 11, 8, 11, 16, 16, 16, 16, 14, 15, 14, 15, 7, 7, 10, 7, 13, 6, 13, 6, 12, 12, 12, 12, 14, 14, 14, 14, 9, 9, 9, 9, 3, 2, 3, 2, 0, 0, 0, 0, 5, 5, 5, 5, 17, 17, 17, 17, 27, 19, 27, 19, 15, 15, 15, 15, 1, 1, 18, 1, 9, 4, 9, 4 }, |
| 103 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 104 |
|
| 105 |
NULL, NULL }, |
| 106 |
|
| 107 |
{ 11, "Bacterial, archaeal; and plant plastid", |
| 108 |
|
| 109 |
{ 8, 11, 8, 11, 16, 16, 16, 16, 14, 15, 14, 15, 7, 7, 10, 7, 13, 6, 13, 6, 12, 12, 12, 12, 14, 14, 14, 14, 9, 9, 9, 9, 3, 2, 3, 2, 0, 0, 0, 0, 5, 5, 5, 5, 17, 17, 17, 17, 27, 19, 27, 19, 15, 15, 15, 15, 27, 1, 18, 1, 9, 4, 9, 4 }, |
| 110 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 }, |
| 111 |
|
| 112 |
NULL, NULL }, |
| 113 |
|
| 114 |
{ 12, "Alternative yeast", |
| 115 |
|
| 116 |
{ 8, 11, 8, 11, 16, 16, 16, 16, 14, 15, 14, 15, 7, 7, 10, 7, 13, 6, 13, 6, 12, 12, 12, 12, 14, 14, 14, 14, 9, 9, 15, 9, 3, 2, 3, 2, 0, 0, 0, 0, 5, 5, 5, 5, 17, 17, 17, 17, 27, 19, 27, 19, 15, 15, 15, 15, 27, 1, 18, 1, 9, 4, 9, 4 }, |
| 117 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 118 |
|
| 119 |
NULL, NULL }, |
| 120 |
|
| 121 |
{ 13, "Ascidian mitochondrial", |
| 122 |
|
| 123 |
{ 8, 11, 8, 11, 16, 16, 16, 16, 5, 15, 5, 15, 10, 7, 10, 7, 13, 6, 13, 6, 12, 12, 12, 12, 14, 14, 14, 14, 9, 9, 9, 9, 3, 2, 3, 2, 0, 0, 0, 0, 5, 5, 5, 5, 17, 17, 17, 17, 27, 19, 27, 19, 15, 15, 15, 15, 18, 1, 18, 1, 9, 4, 9, 4 }, |
| 124 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 }, |
| 125 |
|
| 126 |
NULL, NULL }, |
| 127 |
|
| 128 |
{ 14, "Alternative flatworm mitochondrial", |
| 129 |
|
| 130 |
{ 11, 11, 8, 11, 16, 16, 16, 16, 15, 15, 15, 15, 7, 7, 10, 7, 13, 6, 13, 6, 12, 12, 12, 12, 14, 14, 14, 14, 9, 9, 9, 9, 3, 2, 3, 2, 0, 0, 0, 0, 5, 5, 5, 5, 17, 17, 17, 17, 19, 19, 27, 19, 15, 15, 15, 15, 18, 1, 18, 1, 9, 4, 9, 4 }, |
| 131 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 132 |
|
| 133 |
NULL, NULL }, |
| 134 |
|
| 135 |
{ 16, "Chlorophycean mitochondrial", |
| 136 |
|
| 137 |
{ 8, 11, 8, 11, 16, 16, 16, 16, 14, 15, 14, 15, 7, 7, 10, 7, 13, 6, 13, 6, 12, 12, 12, 12, 14, 14, 14, 14, 9, 9, 9, 9, 3, 2, 3, 2, 0, 0, 0, 0, 5, 5, 5, 5, 17, 17, 17, 17, 27, 19, 9, 19, 15, 15, 15, 15, 27, 1, 18, 1, 9, 4, 9, 4 }, |
| 138 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 139 |
|
| 140 |
NULL, NULL }, |
| 141 |
|
| 142 |
{ 21, "Trematode mitochondrial", |
| 143 |
|
| 144 |
{ 11, 11, 8, 11, 16, 16, 16, 16, 15, 15, 15, 15, 10, 7, 10, 7, 13, 6, 13, 6, 12, 12, 12, 12, 14, 14, 14, 14, 9, 9, 9, 9, 3, 2, 3, 2, 0, 0, 0, 0, 5, 5, 5, 5, 17, 17, 17, 17, 27, 19, 27, 19, 15, 15, 15, 15, 18, 1, 18, 1, 9, 4, 9, 4 }, |
| 145 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 146 |
|
| 147 |
NULL, NULL }, |
| 148 |
|
| 149 |
{ 22, "Scenedesmus obliquus mitochondrial", |
| 150 |
|
| 151 |
{ 8, 11, 8, 11, 16, 16, 16, 16, 14, 15, 14, 15, 7, 7, 10, 7, 13, 6, 13, 6, 12, 12, 12, 12, 14, 14, 14, 14, 9, 9, 9, 9, 3, 2, 3, 2, 0, 0, 0, 0, 5, 5, 5, 5, 17, 17, 17, 17, 27, 19, 9, 19, 27, 15, 15, 15, 27, 1, 18, 1, 9, 4, 9, 4 }, |
| 152 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 153 |
|
| 154 |
NULL, NULL }, |
| 155 |
|
| 156 |
{ 23, "Thraustochytrium mitochondrial", |
| 157 |
|
| 158 |
{ 8, 11, 8, 11, 16, 16, 16, 16, 14, 15, 14, 15, 7, 7, 10, 7, 13, 6, 13, 6, 12, 12, 12, 12, 14, 14, 14, 14, 9, 9, 9, 9, 3, 2, 3, 2, 0, 0, 0, 0, 5, 5, 5, 5, 17, 17, 17, 17, 27, 19, 27, 19, 15, 15, 15, 15, 27, 1, 18, 1, 27, 4, 9, 4 }, |
| 159 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 160 |
|
| 161 |
NULL, NULL }, |
| 162 |
|
| 163 |
{ 24, "Pterobranchia mitochondrial", |
| 164 |
|
| 165 |
{ 8, 11, 8, 11, 16, 16, 16, 16, 15, 15, 8, 15, 7, 7, 10, 7, 13, 6, 13, 6, 12, 12, 12, 12, 14, 14, 14, 14, 9, 9, 9, 9, 3, 2, 3, 2, 0, 0, 0, 0, 5, 5, 5, 5, 17, 17, 17, 17, 27, 19, 27, 19, 15, 15, 15, 15, 18, 1, 18, 1, 9, 4, 9, 4 }, |
| 166 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 }, |
| 167 |
|
| 168 |
NULL, NULL }, |
| 169 |
|
| 170 |
{ 25, "Candidate Division SR1 and Gracilibacteria", |
| 171 |
|
| 172 |
{ 8, 11, 8, 11, 16, 16, 16, 16, 14, 15, 14, 15, 7, 7, 10, 7, 13, 6, 13, 6, 12, 12, 12, 12, 14, 14, 14, 14, 9, 9, 9, 9, 3, 2, 3, 2, 0, 0, 0, 0, 5, 5, 5, 5, 17, 17, 17, 17, 27, 19, 27, 19, 15, 15, 15, 15, 5, 1, 18, 1, 9, 4, 9, 4 }, |
| 173 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 }, |
| 174 |
|
| 175 |
NULL, NULL }, |
| 176 |
}; |
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
ESL_GENCODE * |
| 217 |
esl_gencode_Create(const ESL_ALPHABET *nt_abc, const ESL_ALPHABET *aa_abc) |
| 218 |
{ |
| 219 |
ESL_GENCODE *gcode = NULL; |
| 220 |
int status; |
| 221 |
|
| 222 |
ESL_ALLOC(gcode, sizeof(ESL_GENCODE)); |
| 223 |
|
| 224 |
gcode->nt_abc = nt_abc; |
| 225 |
gcode->aa_abc = aa_abc; |
| 226 |
|
| 227 |
if ( (nt_abc->type == eslDNA || nt_abc->type == eslRNA) && aa_abc->type == eslAMINO) |
| 228 |
esl_gencode_Set(gcode, 1); |
| 229 |
return gcode; |
| 230 |
|
| 231 |
ERROR: |
| 232 |
esl_gencode_Destroy(gcode); |
| 233 |
return NULL; |
| 234 |
} |
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
void |
| 241 |
esl_gencode_Destroy(ESL_GENCODE *gcode) |
| 242 |
{ |
| 243 |
if (gcode) free(gcode); |
| 244 |
} |
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
int |
| 277 |
esl_gencode_Set(ESL_GENCODE *gcode, int ncbi_transl_table) |
| 278 |
{ |
| 279 |
int ntables = sizeof(esl_transl_tables) / sizeof(ESL_GENCODE); |
| 280 |
int t, c; |
| 281 |
|
| 282 |
if (gcode->nt_abc && (gcode->nt_abc->type != eslDNA && gcode->nt_abc->type != eslRNA)) |
| 283 |
ESL_EXCEPTION(eslEINVAL, "NCBI translation tables are precomputed using Easel standard alphabets; your nucleic alphabet is nonstandard"); |
| 284 |
if (gcode->aa_abc && gcode->aa_abc->type != eslAMINO) |
| 285 |
ESL_EXCEPTION(eslEINVAL, "NCBI translation tables are precomputed using Easel standard alphabets; your amino alphabet is nonstandard"); |
| 286 |
|
| 287 |
for (t = 0; t < ntables; t++) |
| 288 |
if ( esl_transl_tables[t].transl_table == ncbi_transl_table) break; |
| 289 |
if (t == ntables) return eslENOTFOUND; |
| 290 |
|
| 291 |
gcode->transl_table = esl_transl_tables[t].transl_table; |
| 292 |
strcpy(gcode->desc, esl_transl_tables[t].desc); |
| 293 |
for (c = 0; c < 64; c++) |
| 294 |
{ |
| 295 |
gcode->basic[c] = esl_transl_tables[t].basic[c]; |
| 296 |
gcode->is_initiator[c] = esl_transl_tables[t].is_initiator[c]; |
| 297 |
} |
| 298 |
return eslOK; |
| 299 |
} |
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
int |
| 317 |
esl_gencode_SetInitiatorAny(ESL_GENCODE *gcode) |
| 318 |
{ |
| 319 |
int c; |
| 320 |
for (c = 0; c < 64; c++) |
| 321 |
gcode->is_initiator[c] = (esl_abc_XIsCanonical(gcode->aa_abc, gcode->basic[c]) ? TRUE : FALSE); |
| 322 |
return eslOK; |
| 323 |
} |
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
int |
| 340 |
esl_gencode_SetInitiatorOnlyAUG(ESL_GENCODE *gcode) |
| 341 |
{ |
| 342 |
int c; |
| 343 |
int atgcodon = 16 * esl_abc_DigitizeSymbol(gcode->nt_abc, 'A') + |
| 344 |
4 * esl_abc_DigitizeSymbol(gcode->nt_abc, 'T') + |
| 345 |
esl_abc_DigitizeSymbol(gcode->nt_abc, 'G'); |
| 346 |
|
| 347 |
for (c = 0; c < 64; c++) gcode->is_initiator[c] = FALSE; |
| 348 |
gcode->is_initiator[atgcodon] = TRUE; |
| 349 |
return eslOK; |
| 350 |
} |
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
int |
| 412 |
esl_gencode_Read(ESL_FILEPARSER *efp, const ESL_ALPHABET *nt_abc, const ESL_ALPHABET *aa_abc, ESL_GENCODE **ret_gcode) |
| 413 |
{ |
| 414 |
ESL_GENCODE *gcode = esl_gencode_Create(nt_abc, aa_abc); |
| 415 |
ESL_REGEXP *mach = esl_regexp_Create(); |
| 416 |
int start, end, s, e; |
| 417 |
char aas[65]; |
| 418 |
char mline[65]; |
| 419 |
char base1[65]; |
| 420 |
char base2[65]; |
| 421 |
char base3[65]; |
| 422 |
int aa_seen[20]; |
| 423 |
int stop_seen; |
| 424 |
int codon_seen[64]; |
| 425 |
int x, codon, pos; |
| 426 |
int status; |
| 427 |
|
| 428 |
ESL_DASSERT1(( nt_abc->K == 4 )); |
| 429 |
ESL_DASSERT1(( aa_abc->K == 20 )); |
| 430 |
|
| 431 |
if (( status = esl_fileparser_SetCommentChar(efp, '#') != eslOK)) goto ERROR; |
| 432 |
|
| 433 |
if ((status = esl_fileparser_NextLine(efp)) != eslOK) { if (status == eslEOF) ESL_XFAIL(eslEFORMAT, efp->errbuf, "File empty or truncated? No AAs line found"); else goto ERROR; } |
| 434 |
if ((status = esl_regexp_Match(mach, "^\\s*[Aa][Aa]s\\s*=\\s*(\\S+)\\s*$", efp->buf)) != eslOK) { if (status == eslEOD) ESL_XFAIL(eslEFORMAT, efp->errbuf, "First data line doesn't start with 'AAs ='"); else goto ERROR; } |
| 435 |
if ((status = esl_regexp_SubmatchCoords(mach, efp->buf, 1, &start, &end)) != eslOK) goto ERROR; |
| 436 |
if (end - start + 1 != 64) ESL_XFAIL(eslEFORMAT, efp->errbuf, "Expected 64 char of AAs data"); |
| 437 |
strncpy(aas, efp->buf+start, 64); |
| 438 |
aas[64] = '\0'; |
| 439 |
|
| 440 |
if ((status = esl_fileparser_NextLine(efp)) != eslOK) { if (status == eslEOF) ESL_XFAIL(eslEFORMAT, efp->errbuf, "File empty or truncated? No Starts line found"); else goto ERROR; } |
| 441 |
if ((status = esl_regexp_Match(mach, "^\\s*[Ss]tarts\\s*=\\s*(\\S+)\\s*$", efp->buf)) != eslOK) { if (status == eslEOD) ESL_XFAIL(eslEFORMAT, efp->errbuf, "Second data line doesn't start with 'Starts ='"); else goto ERROR; } |
| 442 |
if ((status = esl_regexp_SubmatchCoords(mach, efp->buf, 1, &s, &e)) != eslOK) goto ERROR; |
| 443 |
if (e - s + 1 != 64) ESL_XFAIL(eslEFORMAT, efp->errbuf, "Expected 64 char of Starts data"); |
| 444 |
if (s != start) ESL_XFAIL(eslEFORMAT, efp->errbuf, "Starts data is not aligned with AAs data above it"); |
| 445 |
strncpy(mline, efp->buf+start, 64); |
| 446 |
mline[64] = '\0'; |
| 447 |
|
| 448 |
if ((status = esl_fileparser_NextLine(efp)) != eslOK) { if (status == eslEOF) ESL_XFAIL(eslEFORMAT, efp->errbuf, "File empty or truncated? No Base1 line found"); else goto ERROR; } |
| 449 |
if ((status = esl_regexp_Match(mach, "^\\s*[Bb]ase1\\s*=\\s*(\\S+)\\s*$", efp->buf)) != eslOK) { if (status == eslEOD) ESL_XFAIL(eslEFORMAT, efp->errbuf, "Third data line doesn't start with 'Base1 ='"); else goto ERROR; } |
| 450 |
if ((status = esl_regexp_SubmatchCoords(mach, efp->buf, 1, &s, &e)) != eslOK) goto ERROR; |
| 451 |
if (e - s + 1 != 64) ESL_XFAIL(eslEFORMAT, efp->errbuf, "Expected 64 char of Base1 data"); |
| 452 |
if (s != start) ESL_XFAIL(eslEFORMAT, efp->errbuf, "Base1 data is not aligned with data above it"); |
| 453 |
strncpy(base1, efp->buf+start, 64); |
| 454 |
base1[64] = '\0'; |
| 455 |
|
| 456 |
if ((status = esl_fileparser_NextLine(efp)) != eslOK) { if (status == eslEOF) ESL_XFAIL(eslEFORMAT, efp->errbuf, "File empty or truncated? No Base2 line found"); else goto ERROR; } |
| 457 |
if ((status = esl_regexp_Match(mach, "^\\s*[Bb]ase2\\s*=\\s*(\\S+)\\s*$", efp->buf)) != eslOK) { if (status == eslEOD) ESL_XFAIL(eslEFORMAT, efp->errbuf, "Fourth data line doesn't start with 'Base2 ='"); else goto ERROR; } |
| 458 |
if ((status = esl_regexp_SubmatchCoords(mach, efp->buf, 1, &s, &e)) != eslOK) goto ERROR; |
| 459 |
if (e - s + 1 != 64) ESL_XFAIL(eslEFORMAT, efp->errbuf, "Expected 64 char of Base2 data"); |
| 460 |
if (s != start) ESL_XFAIL(eslEFORMAT, efp->errbuf, "Base2 data is not aligned with data above it"); |
| 461 |
strncpy(base2, efp->buf+start, 64); |
| 462 |
base2[64] = '\0'; |
| 463 |
|
| 464 |
if ((status = esl_fileparser_NextLine(efp)) != eslOK) { if (status == eslEOF) ESL_XFAIL(eslEFORMAT, efp->errbuf, "File empty or truncated? No Base3 line found"); else goto ERROR; } |
| 465 |
if ((status = esl_regexp_Match(mach, "^\\s*[Bb]ase3\\s*=\\s*(\\S+)\\s*$", efp->buf)) != eslOK) { if (status == eslEOD) ESL_XFAIL(eslEFORMAT, efp->errbuf, "Fifth data line doesn't start with 'Base3 ='"); else goto ERROR; } |
| 466 |
if ((status = esl_regexp_SubmatchCoords(mach, efp->buf, 1, &s, &e)) != eslOK) goto ERROR; |
| 467 |
if (e - s + 1 != 64) ESL_XFAIL(eslEFORMAT, efp->errbuf, "Expected 64 char of Base3 data"); |
| 468 |
if (s != start) ESL_XFAIL(eslEFORMAT, efp->errbuf, "Base3 data is not aligned with data above it"); |
| 469 |
strncpy(base3, efp->buf+start, 64); |
| 470 |
base3[64] = '\0'; |
| 471 |
|
| 472 |
stop_seen = FALSE; |
| 473 |
for ( x = 0; x < 20; x++) aa_seen[x] = FALSE; |
| 474 |
for (codon = 0; codon < 64; codon++) codon_seen[codon] = FALSE; |
| 475 |
|
| 476 |
for (pos = 0; pos < 64; pos++) |
| 477 |
{ |
| 478 |
if (! esl_abc_CIsValid(aa_abc, aas[pos]) || ! (esl_abc_CIsCanonical(aa_abc, aas[pos]) || esl_abc_CIsNonresidue(aa_abc, aas[pos]))) ESL_XFAIL(eslEFORMAT, efp->errbuf, "Character %c on AAs line is not an amino acid or a * (stop)", aas[pos]); |
| 479 |
if (! esl_abc_CIsValid(nt_abc, base1[pos]) || ! esl_abc_CIsCanonical(nt_abc, base1[pos])) ESL_XFAIL(eslEFORMAT, efp->errbuf, "Character %c on Base1 line is not a nucleotide", base1[pos]); |
| 480 |
if (! esl_abc_CIsValid(nt_abc, base2[pos]) || ! esl_abc_CIsCanonical(nt_abc, base2[pos])) ESL_XFAIL(eslEFORMAT, efp->errbuf, "Character %c on Base2 line is not a nucleotide", base2[pos]); |
| 481 |
if (! esl_abc_CIsValid(nt_abc, base3[pos]) || ! esl_abc_CIsCanonical(nt_abc, base3[pos])) ESL_XFAIL(eslEFORMAT, efp->errbuf, "Character %c on Base3 line is not a nucleotide", base3[pos]); |
| 482 |
if ( mline[pos] != '-' && mline[pos] != 'm' && mline[pos] != 'M') ESL_XFAIL(eslEFORMAT, efp->errbuf, "Character %c on Starts line is neither a - or an M", mline[pos]); |
| 483 |
|
| 484 |
codon = 16 * esl_abc_DigitizeSymbol(nt_abc, base1[pos]) + |
| 485 |
4 * esl_abc_DigitizeSymbol(nt_abc, base2[pos]) + |
| 486 |
esl_abc_DigitizeSymbol(nt_abc, base3[pos]); |
| 487 |
x = esl_abc_DigitizeSymbol(aa_abc, aas[pos]); |
| 488 |
|
| 489 |
ESL_DASSERT1(( codon >= 0 && codon < 64 )); |
| 490 |
ESL_DASSERT1(( x >= 0 && (x < 20 || x == esl_abc_XGetNonresidue(aa_abc)))); |
| 491 |
|
| 492 |
if (x < 20) aa_seen[x]++; else stop_seen++; |
| 493 |
codon_seen[codon]++; |
| 494 |
|
| 495 |
gcode->basic[codon] = x; |
| 496 |
gcode->is_initiator[codon] = ( mline[pos] == '-' ? FALSE : TRUE ); |
| 497 |
} |
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
if (! stop_seen) ESL_XFAIL(eslEFORMAT, efp->errbuf, "No stop codon found in that genetic code"); |
| 505 |
for (codon = 0; codon < 64; codon++) |
| 506 |
if (! codon_seen[codon]) ESL_XFAIL(eslEFORMAT, efp->errbuf, "Data for fewer than 64 codons was found"); |
| 507 |
for (x = 0; x < 20; x++) |
| 508 |
if (aa_seen[x] == 0) ESL_XFAIL(eslEFORMAT, efp->errbuf, "No codon for residue %c found", aa_abc->sym[x]); |
| 509 |
|
| 510 |
|
| 511 |
esl_regexp_Destroy(mach); |
| 512 |
gcode->transl_table = -1; |
| 513 |
gcode->desc[0] = '\0'; |
| 514 |
gcode->nt_abc = nt_abc; |
| 515 |
gcode->aa_abc = aa_abc; |
| 516 |
*ret_gcode = gcode; |
| 517 |
return eslOK; |
| 518 |
|
| 519 |
ERROR: |
| 520 |
if (gcode) esl_gencode_Destroy(gcode); |
| 521 |
if (mach) esl_regexp_Destroy(mach); |
| 522 |
*ret_gcode = NULL; |
| 523 |
return status; |
| 524 |
} |
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
int |
| 545 |
esl_gencode_Write(FILE *ofp, const ESL_GENCODE *gcode, int add_comment) |
| 546 |
{ |
| 547 |
char order[] = "TCAG"; |
| 548 |
int x,c; |
| 549 |
|
| 550 |
if (add_comment && gcode->transl_table > 0) |
| 551 |
if ( fprintf(ofp, "# %d %s\n", |
| 552 |
gcode->transl_table, gcode->desc) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "genetic code write failed"); |
| 553 |
|
| 554 |
|
| 555 |
if ( fprintf(ofp, " AAs = ") < 0) ESL_EXCEPTION_SYS(eslEWRITE, "genetic code write failed"); |
| 556 |
for (x = 0; x < 64; x++) { |
| 557 |
c = 16 * esl_abc_DigitizeSymbol(gcode->nt_abc, order[ x/16 ]) |
| 558 |
+ 4 * esl_abc_DigitizeSymbol(gcode->nt_abc, order[ (x%16)/4 ]) |
| 559 |
+ esl_abc_DigitizeSymbol(gcode->nt_abc, order[ x%4]); |
| 560 |
if (fputc( gcode->aa_abc->sym[gcode->basic[c]], ofp) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "genetic code write failed"); |
| 561 |
} |
| 562 |
if ( fputc('\n', ofp) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "genetic code write failed"); |
| 563 |
|
| 564 |
if ( fprintf(ofp, " Starts = ") < 0) ESL_EXCEPTION_SYS(eslEWRITE, "genetic code write failed"); |
| 565 |
for (x = 0; x < 64; x++) { |
| 566 |
c = 16 * esl_abc_DigitizeSymbol(gcode->nt_abc, order[ x/16 ]) |
| 567 |
+ 4 * esl_abc_DigitizeSymbol(gcode->nt_abc, order[ (x%16)/4 ]) |
| 568 |
+ esl_abc_DigitizeSymbol(gcode->nt_abc, order[ x%4]); |
| 569 |
if (fputc( (gcode->is_initiator[c] ? 'M' : '-'), ofp) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "genetic code write failed"); |
| 570 |
} |
| 571 |
if ( fputc('\n', ofp) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "genetic code write failed"); |
| 572 |
|
| 573 |
if ( fprintf(ofp, " Base1 = ") < 0) ESL_EXCEPTION_SYS(eslEWRITE, "genetic code write failed"); |
| 574 |
for (x = 0; x < 64; x++) if ( fputc( order[ x/16 ], ofp) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "genetic code write failed"); |
| 575 |
if ( fputc('\n', ofp) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "genetic code write failed"); |
| 576 |
|
| 577 |
if ( fprintf(ofp, " Base2 = ") < 0) ESL_EXCEPTION_SYS(eslEWRITE, "genetic code write failed"); |
| 578 |
for (x = 0; x < 64; x++) if ( fputc( order[ (x%16)/4 ], ofp) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "genetic code write failed"); |
| 579 |
if ( fputc('\n', ofp) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "genetic code write failed"); |
| 580 |
|
| 581 |
if ( fprintf(ofp, " Base3 = ") < 0) ESL_EXCEPTION_SYS(eslEWRITE, "genetic code write failed"); |
| 582 |
for (x = 0; x < 64; x++) if ( fputc( order[ x%4 ], ofp) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "genetic code write failed"); |
| 583 |
if ( fputc('\n', ofp) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "genetic code write failed"); |
| 584 |
|
| 585 |
return eslOK; |
| 586 |
} |
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
int |
| 625 |
esl_gencode_GetTranslation(const ESL_GENCODE *gcode, ESL_DSQ *dsqp) |
| 626 |
{ |
| 627 |
ESL_DSQ x, y, z; |
| 628 |
int codon; |
| 629 |
int aa = -1; |
| 630 |
|
| 631 |
if (esl_abc_XIsCanonical(gcode->nt_abc, dsqp[0]) && esl_abc_XIsCanonical(gcode->nt_abc, dsqp[1]) && esl_abc_XIsCanonical(gcode->nt_abc, dsqp[2])) |
| 632 |
{ |
| 633 |
codon = 16*dsqp[0] + 4*dsqp[1] + dsqp[2]; |
| 634 |
return gcode->basic[codon]; |
| 635 |
} |
| 636 |
|
| 637 |
for (x = 0; x < 4; x++) |
| 638 |
{ |
| 639 |
if (! gcode->nt_abc->degen[dsqp[0]][x]) continue; |
| 640 |
for (y = 0; y < 4; y++) |
| 641 |
{ |
| 642 |
if (! gcode->nt_abc->degen[dsqp[1]][y]) continue; |
| 643 |
for (z = 0; z < 4; z++) |
| 644 |
{ |
| 645 |
if (! gcode->nt_abc->degen[dsqp[2]][z]) continue; |
| 646 |
|
| 647 |
codon = x * 16 + y * 4 + z; |
| 648 |
if (aa == -1) aa = gcode->basic[codon]; |
| 649 |
else if (aa != gcode->basic[codon]) return esl_abc_XGetUnknown(gcode->aa_abc); |
| 650 |
} |
| 651 |
} |
| 652 |
} |
| 653 |
return aa; |
| 654 |
} |
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
int |
| 688 |
esl_gencode_IsInitiator(const ESL_GENCODE *gcode, ESL_DSQ *dsqp) |
| 689 |
{ |
| 690 |
ESL_DSQ x, y, z; |
| 691 |
int codon; |
| 692 |
int ncodons = 0; |
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
if (esl_abc_XIsCanonical(gcode->nt_abc, dsqp[0]) && esl_abc_XIsCanonical(gcode->nt_abc, dsqp[1]) && esl_abc_XIsCanonical(gcode->nt_abc, dsqp[2])) |
| 699 |
{ |
| 700 |
codon = 16*dsqp[0] + 4*dsqp[1] + dsqp[2]; |
| 701 |
return gcode->is_initiator[codon]; |
| 702 |
} |
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
for (x = 0; x < 4; x++) |
| 708 |
{ |
| 709 |
if (! gcode->nt_abc->degen[dsqp[0]][x]) continue; |
| 710 |
for (y = 0; y < 4; y++) |
| 711 |
{ |
| 712 |
if (! gcode->nt_abc->degen[dsqp[1]][y]) continue; |
| 713 |
for (z = 0; z < 4; z++) |
| 714 |
{ |
| 715 |
if (! gcode->nt_abc->degen[dsqp[2]][z]) continue; |
| 716 |
|
| 717 |
codon = x * 16 + y * 4 + z; |
| 718 |
ncodons++; |
| 719 |
if (! gcode->is_initiator[codon]) return FALSE; |
| 720 |
} |
| 721 |
} |
| 722 |
} |
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
return (ncodons ? TRUE : FALSE); |
| 729 |
} |
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
void |
| 736 |
esl_gencode_WorkstateDestroy(ESL_GENCODE_WORKSTATE *wrk) |
| 737 |
{ |
| 738 |
int f; |
| 739 |
if (wrk) |
| 740 |
{ |
| 741 |
for (f = 0; f < 3; f++) esl_sq_Destroy(wrk->psq[f]); |
| 742 |
|
| 743 |
if(wrk->orf_block != NULL) |
| 744 |
{ |
| 745 |
esl_sq_DestroyBlock(wrk->orf_block); |
| 746 |
wrk->orf_block = NULL; |
| 747 |
} |
| 748 |
|
| 749 |
free(wrk); |
| 750 |
} |
| 751 |
} |
| 752 |
|
| 753 |
ESL_GENCODE_WORKSTATE * |
| 754 |
esl_gencode_WorkstateCreate(ESL_GETOPTS *go, ESL_GENCODE *gcode) |
| 755 |
{ |
| 756 |
ESL_GENCODE_WORKSTATE *wrk = NULL; |
| 757 |
int f; |
| 758 |
int status; |
| 759 |
|
| 760 |
ESL_ALLOC(wrk, sizeof(ESL_GENCODE_WORKSTATE)); |
| 761 |
for (f = 0; f < 3; f++) wrk->psq[f] = NULL; |
| 762 |
|
| 763 |
for (f = 0; f < 3; f++) |
| 764 |
{ |
| 765 |
wrk->psq[f] = esl_sq_CreateDigital(gcode->aa_abc); |
| 766 |
wrk->psq[f]->dsq[0] = eslDSQ_SENTINEL; |
| 767 |
wrk->in_orf[f] = FALSE; |
| 768 |
} |
| 769 |
|
| 770 |
wrk->apos = 1; |
| 771 |
wrk->frame = 0; |
| 772 |
wrk->codon = 0; |
| 773 |
wrk->inval = 0; |
| 774 |
wrk->is_revcomp = FALSE; |
| 775 |
wrk->orfcount = 0; |
| 776 |
|
| 777 |
wrk->orf_block = NULL; |
| 778 |
|
| 779 |
wrk->do_watson = (esl_opt_GetBoolean(go, "--crick") ? FALSE : TRUE); |
| 780 |
wrk->do_crick = (esl_opt_GetBoolean(go, "--watson") ? FALSE : TRUE); |
| 781 |
wrk->using_initiators = ((esl_opt_GetBoolean(go, "-m") || esl_opt_GetBoolean(go, "-M")) ? TRUE : FALSE); |
| 782 |
wrk->minlen = esl_opt_GetInteger(go, "-l"); |
| 783 |
wrk->outfp = stdout; |
| 784 |
wrk->outformat = eslSQFILE_FASTA; |
| 785 |
|
| 786 |
return wrk; |
| 787 |
|
| 788 |
ERROR: |
| 789 |
esl_gencode_WorkstateDestroy(wrk); |
| 790 |
return NULL; |
| 791 |
} |
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
int |
| 798 |
esl_gencode_ProcessOrf(ESL_GENCODE_WORKSTATE *wrk, ESL_SQ *sq) |
| 799 |
{ |
| 800 |
|
| 801 |
int status = eslOK; |
| 802 |
ESL_SQ *psq = wrk->psq[wrk->frame]; |
| 803 |
psq->end = (wrk->is_revcomp ? wrk->apos+1 : wrk->apos-1); |
| 804 |
if (wrk->in_orf[wrk->frame] && psq->n >= wrk->minlen) |
| 805 |
{ |
| 806 |
wrk->orfcount++; |
| 807 |
if (psq->n+2 > psq->salloc) |
| 808 |
esl_sq_Grow(psq, NULL); |
| 809 |
psq->dsq[1+psq->n] = eslDSQ_SENTINEL; |
| 810 |
|
| 811 |
esl_sq_FormatName(psq, "orf%d", wrk->orfcount); |
| 812 |
esl_sq_FormatDesc(psq, "source=%s coords=%" PRId64 "..%" PRId64 " length=%" PRId64 " frame=%d desc=%s", psq->source, psq->start, psq->end, psq->n, wrk->frame + 1 + (wrk->is_revcomp ? 3 : 0), sq->desc); |
| 813 |
|
| 814 |
if (wrk->orf_block == NULL) |
| 815 |
{ |
| 816 |
esl_sqio_Write(wrk->outfp, psq, wrk->outformat, FALSE); |
| 817 |
} |
| 818 |
else |
| 819 |
{ |
| 820 |
if (wrk->orf_block->count == wrk->orf_block->listSize) |
| 821 |
{ |
| 822 |
status = esl_sq_BlockGrowTo(wrk->orf_block, wrk->orf_block->listSize + 128, TRUE, psq->abc); |
| 823 |
if (status != eslOK) ESL_XEXCEPTION(eslEMEM, "Cannot increase size of ORF sequence block"); |
| 824 |
} |
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
esl_sq_Copy(psq, &(wrk->orf_block->list[wrk->orf_block->count])); |
| 829 |
|
| 830 |
|
| 831 |
wrk->orf_block->count++; |
| 832 |
} |
| 833 |
} |
| 834 |
|
| 835 |
esl_sq_Reuse(psq); |
| 836 |
esl_sq_SetSource(psq, sq->name); |
| 837 |
wrk->in_orf[wrk->frame] = FALSE; |
| 838 |
|
| 839 |
ERROR: |
| 840 |
return status; |
| 841 |
} |
| 842 |
|
| 843 |
void |
| 844 |
esl_gencode_ProcessStart(ESL_GENCODE *gcode, ESL_GENCODE_WORKSTATE *wrk, ESL_SQ *sq) |
| 845 |
{ |
| 846 |
int f; |
| 847 |
|
| 848 |
ESL_DASSERT1(( sq->n >= 3 )); |
| 849 |
|
| 850 |
for (f = 0; f < 3; f++) |
| 851 |
{ |
| 852 |
esl_sq_SetSource(wrk->psq[f], sq->name); |
| 853 |
wrk->in_orf[f] = FALSE; |
| 854 |
} |
| 855 |
wrk->frame = 0; |
| 856 |
wrk->codon = 0; |
| 857 |
wrk->inval = 0; |
| 858 |
wrk->is_revcomp = (sq->end > sq->start ? FALSE : TRUE ); |
| 859 |
wrk->apos = (wrk->is_revcomp ? sq->L : 1 ); |
| 860 |
|
| 861 |
if (esl_abc_XIsCanonical(gcode->nt_abc, sq->dsq[1])) wrk->codon += 4 * sq->dsq[1]; else wrk->inval = 1; |
| 862 |
if (esl_abc_XIsCanonical(gcode->nt_abc, sq->dsq[2])) wrk->codon += sq->dsq[2]; else wrk->inval = 2; |
| 863 |
} |
| 864 |
|
| 865 |
|
| 866 |
int |
| 867 |
esl_gencode_ProcessPiece(ESL_GENCODE *gcode, ESL_GENCODE_WORKSTATE *wrk, ESL_SQ *sq) |
| 868 |
{ |
| 869 |
ESL_DSQ aa; |
| 870 |
int rpos; |
| 871 |
|
| 872 |
for (rpos = 1; rpos <= sq->n-2; rpos++) |
| 873 |
{ |
| 874 |
wrk->codon = (wrk->codon * 4) % 64; |
| 875 |
if ( esl_abc_XIsCanonical(gcode->nt_abc, sq->dsq[rpos+2])) wrk->codon += sq->dsq[rpos+2]; |
| 876 |
else wrk->inval = 3; |
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
if (wrk->inval > 0) |
| 882 |
{ |
| 883 |
aa = esl_gencode_GetTranslation(gcode, sq->dsq+rpos); |
| 884 |
if (! wrk->in_orf[wrk->frame] && esl_gencode_IsInitiator(gcode, sq->dsq+rpos)) |
| 885 |
{ |
| 886 |
if (wrk->using_initiators) |
| 887 |
aa = esl_abc_DigitizeSymbol(gcode->aa_abc, 'M'); |
| 888 |
wrk->in_orf[wrk->frame] = TRUE; |
| 889 |
wrk->psq[wrk->frame]->start = wrk->apos; |
| 890 |
} |
| 891 |
wrk->inval--; |
| 892 |
} |
| 893 |
else |
| 894 |
{ |
| 895 |
aa = gcode->basic[wrk->codon]; |
| 896 |
if (gcode->is_initiator[wrk->codon] && ! wrk->in_orf[wrk->frame]) |
| 897 |
{ |
| 898 |
if (wrk->using_initiators) |
| 899 |
aa = esl_abc_DigitizeSymbol(gcode->aa_abc, 'M'); |
| 900 |
wrk->psq[wrk->frame]->start = wrk->apos; |
| 901 |
wrk->in_orf[wrk->frame] = TRUE; |
| 902 |
} |
| 903 |
} |
| 904 |
|
| 905 |
|
| 906 |
if ( esl_abc_XIsNonresidue(gcode->aa_abc, aa)) |
| 907 |
esl_gencode_ProcessOrf(wrk, sq); |
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
if (wrk->in_orf[wrk->frame]) |
| 913 |
{ |
| 914 |
if (wrk->psq[wrk->frame]->n + 2 > wrk->psq[wrk->frame]->salloc) |
| 915 |
esl_sq_Grow(wrk->psq[wrk->frame], NULL); |
| 916 |
wrk->psq[wrk->frame]->dsq[1+ wrk->psq[wrk->frame]->n] = aa; |
| 917 |
wrk->psq[wrk->frame]->n++; |
| 918 |
} |
| 919 |
|
| 920 |
|
| 921 |
if (wrk->is_revcomp) wrk->apos--; else wrk->apos++; |
| 922 |
wrk->frame = (wrk->frame + 1) % 3; |
| 923 |
} |
| 924 |
return eslOK; |
| 925 |
} |
| 926 |
|
| 927 |
|
| 928 |
int |
| 929 |
esl_gencode_ProcessEnd(ESL_GENCODE_WORKSTATE *wrk, ESL_SQ *sq) |
| 930 |
{ |
| 931 |
int f; |
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
ESL_DASSERT1(( (wrk->is_revcomp && wrk->apos == 2) || (! wrk->is_revcomp && wrk->apos == sq->L-1) )); |
| 938 |
for (f = 0; f < 3; f++) |
| 939 |
{ |
| 940 |
esl_gencode_ProcessOrf(wrk, sq); |
| 941 |
if (wrk->is_revcomp) wrk->apos--; else wrk->apos++; |
| 942 |
wrk->frame = (wrk->frame + 1) % 3; |
| 943 |
} |
| 944 |
return eslOK; |
| 945 |
} |
| 946 |
|
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
char * |
| 966 |
esl_gencode_DecodeDigicodon(const ESL_GENCODE *gcode, int digicodon, char *codon) |
| 967 |
{ |
| 968 |
codon[0] = gcode->nt_abc->sym[ digicodon / 16 ]; |
| 969 |
codon[1] = gcode->nt_abc->sym[ (digicodon % 16) / 4 ]; |
| 970 |
codon[2] = gcode->nt_abc->sym[ digicodon % 4 ]; |
| 971 |
codon[3] = '\0'; |
| 972 |
return codon; |
| 973 |
} |
| 974 |
|
| 975 |
|
| 976 |
|
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
int |
| 987 |
esl_gencode_DumpAltCodeTable(FILE *ofp) |
| 988 |
{ |
| 989 |
int ntables = sizeof(esl_transl_tables) / sizeof(ESL_GENCODE); |
| 990 |
int t; |
| 991 |
|
| 992 |
fprintf(ofp, "id description\n"); |
| 993 |
fprintf(ofp, "--- -----------------------------------\n"); |
| 994 |
for (t = 0; t < ntables; t++) |
| 995 |
fprintf(ofp, "%3d %s\n", esl_transl_tables[t].transl_table, esl_transl_tables[t].desc); |
| 996 |
return eslOK; |
| 997 |
} |
| 998 |
|
| 999 |
|
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
int |
| 1007 |
esl_gencode_Compare(const ESL_GENCODE *gc1, const ESL_GENCODE *gc2, int metadata_too) |
| 1008 |
{ |
| 1009 |
int x; |
| 1010 |
|
| 1011 |
|
| 1012 |
if (gc1->nt_abc->type != gc2->nt_abc->type) return eslFAIL; |
| 1013 |
if (gc1->aa_abc->type != gc2->aa_abc->type) return eslFAIL; |
| 1014 |
|
| 1015 |
if (metadata_too) { |
| 1016 |
if (gc1->transl_table != gc2->transl_table) return eslFAIL; |
| 1017 |
if (strcmp(gc1->desc, gc2->desc) != 0) return eslFAIL; |
| 1018 |
} |
| 1019 |
|
| 1020 |
for (x = 0; x < 64; x++) |
| 1021 |
{ |
| 1022 |
if (gc1->basic[x] != gc2->basic[x]) return eslFAIL; |
| 1023 |
if (gc1->is_initiator[x] != gc2->is_initiator[x]) return eslFAIL; |
| 1024 |
} |
| 1025 |
return eslOK; |
| 1026 |
} |
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
#ifdef eslGENCODE_TESTDRIVE |
| 1033 |
|
| 1034 |
static void |
| 1035 |
utest_ReadWrite(void) |
| 1036 |
{ |
| 1037 |
char msg[] = "esl_gencode :: Read/Write unit test failed"; |
| 1038 |
char tmpfile[16] = "esltmpXXXXXX"; |
| 1039 |
int ntables = sizeof(esl_transl_tables) / sizeof(ESL_GENCODE); |
| 1040 |
ESL_ALPHABET *nt_abc = esl_alphabet_Create(eslDNA); |
| 1041 |
ESL_ALPHABET *aa_abc = esl_alphabet_Create(eslAMINO); |
| 1042 |
ESL_GENCODE *gc1 = NULL; |
| 1043 |
ESL_GENCODE *gc2 = NULL; |
| 1044 |
FILE *ofp = NULL; |
| 1045 |
ESL_FILEPARSER *efp = NULL; |
| 1046 |
int t; |
| 1047 |
|
| 1048 |
for (t = 0; t < ntables; t++) |
| 1049 |
{ |
| 1050 |
strcpy(tmpfile, "esltmpXXXXXX"); |
| 1051 |
if ( (gc1 = esl_gencode_Create(nt_abc, aa_abc)) == NULL) esl_fatal(msg); |
| 1052 |
if ( esl_gencode_Set(gc1, esl_transl_tables[t].transl_table) != eslOK) esl_fatal(msg); |
| 1053 |
|
| 1054 |
if ( esl_tmpfile_named(tmpfile, &ofp) != eslOK) esl_fatal(msg); |
| 1055 |
if ( esl_gencode_Write(ofp, gc1, TRUE) != eslOK) esl_fatal(msg); |
| 1056 |
fclose(ofp); |
| 1057 |
|
| 1058 |
if ( esl_fileparser_Open(tmpfile, NULL, &efp) != eslOK) esl_fatal(msg); |
| 1059 |
if ( esl_gencode_Read(efp, nt_abc, aa_abc, &gc2) != eslOK) esl_fatal(msg); |
| 1060 |
if ( esl_gencode_Compare(gc1, gc2, FALSE) != eslOK) esl_fatal(msg); |
| 1061 |
|
| 1062 |
esl_gencode_Destroy(gc1); |
| 1063 |
esl_gencode_Destroy(gc2); |
| 1064 |
esl_fileparser_Close(efp); |
| 1065 |
remove(tmpfile); |
| 1066 |
} |
| 1067 |
esl_alphabet_Destroy(nt_abc); |
| 1068 |
esl_alphabet_Destroy(aa_abc); |
| 1069 |
} |
| 1070 |
|
| 1071 |
#endif |
| 1072 |
|
| 1073 |
|
| 1074 |
|
| 1075 |
|
| 1076 |
|
| 1077 |
#ifdef eslGENCODE_TESTDRIVE |
| 1078 |
|
| 1079 |
#include <esl_config.h> |
| 1080 |
|
| 1081 |
#include "esl_gencode.h" |
| 1082 |
|
| 1083 |
int |
| 1084 |
main(int argc, char **argv) |
| 1085 |
{ |
| 1086 |
utest_ReadWrite(); |
| 1087 |
return eslOK; |
| 1088 |
} |
| 1089 |
#endif |
| 1090 |
|
| 1091 |
|
| 1092 |
|
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
#ifdef eslGENCODE_EXAMPLE |
| 1097 |
#include "easel.h" |
| 1098 |
#include "esl_alphabet.h" |
| 1099 |
#include "esl_fileparser.h" |
| 1100 |
#include "esl_gencode.h" |
| 1101 |
|
| 1102 |
#include <stdio.h> |
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
int |
| 1111 |
main(int argc, char **argv) |
| 1112 |
{ |
| 1113 |
char *codefile = argv[1]; |
| 1114 |
ESL_FILEPARSER *efp = NULL; |
| 1115 |
ESL_GENCODE *gcode = NULL; |
| 1116 |
ESL_ALPHABET *nt_abc = esl_alphabet_Create(eslDNA); |
| 1117 |
ESL_ALPHABET *aa_abc = esl_alphabet_Create(eslAMINO); |
| 1118 |
int digicodon; |
| 1119 |
char codon[4]; |
| 1120 |
int status; |
| 1121 |
|
| 1122 |
if (esl_fileparser_Open(codefile, NULL, &efp) != eslOK) esl_fatal("Failed to open code file %s", codefile); |
| 1123 |
esl_fileparser_SetCommentChar(efp, '#'); |
| 1124 |
|
| 1125 |
status = esl_gencode_Read(efp, nt_abc, aa_abc, &gcode); |
| 1126 |
if (status == eslEFORMAT) esl_fatal("Failed to parse genetic code datafile %s\n %s\n", codefile, efp->errbuf); |
| 1127 |
else if (status != eslOK) esl_fatal("Unexpected failure parsing genetic code datafile %s : code %d\n", codefile, status); |
| 1128 |
|
| 1129 |
printf("/* "); |
| 1130 |
for (digicodon = 0; digicodon < 64; digicodon++) |
| 1131 |
printf("%3s ", esl_gencode_DecodeDigicodon(gcode, digicodon, codon)); |
| 1132 |
printf("*/\n"); |
| 1133 |
|
| 1134 |
printf(" {"); |
| 1135 |
for (digicodon = 0; digicodon < 64; digicodon++) |
| 1136 |
printf("%3d%c", gcode->basic[digicodon], (digicodon < 63 ? ',' : ' ')); |
| 1137 |
printf("},\n"); |
| 1138 |
|
| 1139 |
printf(" {"); |
| 1140 |
for (digicodon = 0; digicodon < 64; digicodon++) |
| 1141 |
printf("%3d%c", gcode->is_initiator[digicodon], (digicodon < 63 ? ',' : ' ')); |
| 1142 |
printf("},\n"); |
| 1143 |
|
| 1144 |
printf("/* "); |
| 1145 |
for (digicodon = 0; digicodon < 64; digicodon++) |
| 1146 |
printf(" %c ", gcode->aa_abc->sym [gcode->basic[digicodon]]); |
| 1147 |
printf("*/\n"); |
| 1148 |
|
| 1149 |
esl_alphabet_Destroy(aa_abc); |
| 1150 |
esl_alphabet_Destroy(nt_abc); |
| 1151 |
esl_gencode_Destroy(gcode); |
| 1152 |
esl_fileparser_Close(efp); |
| 1153 |
} |
| 1154 |
#endif |
| 1155 |
|
| 1156 |
|
| 1157 |
#ifdef eslGENCODE_EXAMPLE2 |
| 1158 |
#include "easel.h" |
| 1159 |
#include "esl_alphabet.h" |
| 1160 |
#include "esl_fileparser.h" |
| 1161 |
#include "esl_gencode.h" |
| 1162 |
|
| 1163 |
#include <stdio.h> |
| 1164 |
|
| 1165 |
|
| 1166 |
|
| 1167 |
|
| 1168 |
int |
| 1169 |
main(int argc, char **argv) |
| 1170 |
{ |
| 1171 |
ESL_ALPHABET *nt_abc = esl_alphabet_Create(eslDNA); |
| 1172 |
ESL_ALPHABET *aa_abc = esl_alphabet_Create(eslAMINO); |
| 1173 |
ESL_GENCODE *gcode = esl_gencode_Create(nt_abc, aa_abc); |
| 1174 |
|
| 1175 |
esl_gencode_Write(stdout, gcode, TRUE); |
| 1176 |
|
| 1177 |
esl_gencode_Destroy(gcode); |
| 1178 |
return eslOK; |
| 1179 |
} |
| 1180 |
#endif |
| 1181 |
|