Debian Codegraph @

easel/esl_msa.h

raw symbols SCIP
1 /* Multiple sequence alignments
2 */
3 #ifndef eslMSA_INCLUDED
4 #define eslMSA_INCLUDED
5
6 #include <esl_config.h>
7
8 #include <stdio.h>
9
10 #include "esl_alphabet.h" // digital alphabets
11 #include "esl_bitfield.h" // large bit fields (esl_msa_MarkFragments()
12 #include "esl_keyhash.h" // string hashes, for mapping uniq seq names
13 #include "esl_random.h"
14 #include "esl_randomseq.h"
15 #include "esl_ssi.h" // indexes of large flatfiles on disk
16
17 #ifdef __cplusplus // magic to make C++ compilers happy
18 extern "C" {
19 #endif
20 /* The following constants define the Pfam/Rfam cutoff set we propagate
21 * from Stockholm format msa's into HMMER and Infernal models.
22 */
23 /*::cexcerpt::msa_cutoffs::begin::*/
24 #define eslMSA_TC1 0
25 #define eslMSA_TC2 1
26 #define eslMSA_GA1 2
27 #define eslMSA_GA2 3
28 #define eslMSA_NC1 4
29 #define eslMSA_NC2 5
30 #define eslMSA_NCUTS 6
31 /*::cexcerpt::msa_cutoffs::end::*/
32
33 /* Object: ESL_MSA
34 *
35 * A multiple sequence alignment.
36 */
37 typedef struct {
38 /* Mandatory information associated with the alignment.
39 * (The important stuff.)
40 */
41 /*::cexcerpt::msa_mandatory::begin::*/
42 char **aseq; /* alignment itself, [0..nseq-1][0..alen-1], \0-terminated */
43 char **sqname; /* sequence names [0..nseq-1][], \0-terminated */
44 double *wgt; /* sequence weights [0..nseq-1], default 1.0 */
45 int64_t alen; /* length of alignment (columns); or (if growable) -1 */
46 int nseq; /* number of seqs in alignment; or (if growable) blocksize */
47 int flags; /* flags for what info has been set */
48 /*::cexcerpt::msa_mandatory::end::*/
49
50 /* w/ digital alphabets, we store pre-digitized data in
51 * ax[][], instead of the text info in aseq[][].
52 */
53 ESL_ALPHABET *abc; /* reference ptr to alphabet */
54 ESL_DSQ **ax; /* digitized aseqs [0..nseq-1][1..alen] */
55
56 /* Optional information that we understand, and that we might have.
57 * (The occasionally useful stuff.)
58 */
59 /*::cexcerpt::msa_optional::begin::*/
60 char *name; /* name of alignment, or NULL */
61 char *desc; /* description of alignment, or NULL */
62 char *acc; /* accession of alignment, or NULL */
63 char *au; /* "author" information, or NULL */
64 char *ss_cons; /* consensus sec structure, or NULL; [0..alen-1], even in digital mode */
65 char *sa_cons; /* consensus surface access, or NULL; [0..alen-1], even in digital mode */
66 char *pp_cons; /* consensus posterior prob, or NULL; [0..alen-1], even in digital mode */
67 char *rf; /* reference coord system, or NULL; [0..alen-1], even in digital mode */
68 char *mm; /* model mask, or NULL; [0..alen-1], even in digital mode */
69 char **sqacc; /* accession numbers for sequences i */
70 char **sqdesc; /* description lines for sequences i */
71 char **ss; /* per-seq secondary structures, or NULL (string, \0-term) */
72 char **sa; /* per-seq surface accessibilities, or NULL (string, \0-term) */
73 char **pp; /* posterior prob per residue, or NULL. (string, \0-term) */
74 float cutoff[eslMSA_NCUTS]; /* NC/TC/GA cutoffs propagated to Pfam/Rfam */
75 int cutset[eslMSA_NCUTS]; /* TRUE if a cutoff is set; else FALSE */
76 /*::cexcerpt::msa_optional::end::*/
77
78 /* Info needed for maintenance of the data structure
79 * (internal stuff.)
80 */
81 int sqalloc; /* # seqs currently allocated for */
82 int64_t *sqlen; /* individual seq lengths during parsing */
83 int64_t *sslen; /* individual ss lengths during parsing */
84 int64_t *salen; /* individual sa lengths during parsing */
85 int64_t *pplen; /* individual pp lengths during parsing */
86 int lastidx; /* last index we saw; use for guessing next */
87
88 /* Optional information, especially Stockholm markup.
89 * (The stuff we don't understand, but we can regurgitate.)
90 *
91 * That is, we know what type of information it is, but it's
92 * either (interpreted as) free-text comment, or it's Stockholm
93 * markup with unfamiliar tags.
94 */
95 char **comment; /* free text comments, or NULL */
96 int ncomment; /* number of comment lines */
97 int alloc_ncomment; /* number of comment lines alloc'ed */
98
99 char **gf_tag; /* markup tags for unparsed #=GF lines */
100 char **gf; /* annotations for unparsed #=GF lines */
101 int ngf; /* number of unparsed #=GF lines */
102 int alloc_ngf; /* number of gf lines alloc'ed */
103
104 char **gs_tag; /* markup tags for unparsed #=GS lines */
105 char ***gs; /* [0..ngs-1][0..nseq-1][free text] markup */
106 int ngs; /* number of #=GS tag types */
107
108 char **gc_tag; /* markup tags for unparsed #=GC lines */
109 char **gc; /* [0..ngc-1][0..alen-1] markup */
110 int ngc; /* number of #=GC tag types */
111
112 char **gr_tag; /* markup tags for unparsed #=GR lines */
113 char ***gr; /* [0..ngr-1][0..nseq-1][0..alen-1] markup */
114 int ngr; /* number of #=GR tag types */
115
116 /* Keyhashing significantly speeds up parsing of large alignments.
117 */
118 ESL_KEYHASH *index; /* name ->seqidx hash table */
119 ESL_KEYHASH *gs_idx; /* hash of #=GS tag types */
120 ESL_KEYHASH *gc_idx; /* hash of #=GC tag types */
121 ESL_KEYHASH *gr_idx; /* hash of #=GR tag types */
122
123 off_t offset; /* disk offset to start of 1st line of this MSA's record */
124 } ESL_MSA;
125
126
127
128 /* Flags for msa->flags */
129 #define eslMSA_HASWGTS (1 << 0) /* 1 if wgts were set, 0 if default 1.0's */
130 #define eslMSA_DIGITAL (1 << 1) /* if ax[][] is used instead of aseq[][] */
131
132
133 /* Declarations of the API */
134
135 /* 1. The ESL_MSA object */
136 extern ESL_MSA *esl_msa_Create(int nseq, int64_t alen);
137 extern int esl_msa_Expand(ESL_MSA *msa);
138 extern int esl_msa_Copy(const ESL_MSA *msa, ESL_MSA *new_msa);
139 extern ESL_MSA *esl_msa_Clone(const ESL_MSA *msa);
140 extern void esl_msa_Destroy(ESL_MSA *msa);
141
142 /* 2. Digital mode MSA's */
143 extern int esl_msa_GuessAlphabet(const ESL_MSA *msa, int *ret_type);
144 extern ESL_MSA *esl_msa_CreateDigital(const ESL_ALPHABET *abc, int nseq, int64_t alen);
145 extern int esl_msa_Digitize(const ESL_ALPHABET *abc, ESL_MSA *msa, char *errmsg);
146 extern int esl_msa_Textize(ESL_MSA *msa);
147 extern int esl_msa_ConvertDegen2X(ESL_MSA *msa);
148
149 /* 3. Setting or checking data fields in an ESL_MSA */
150 extern int esl_msa_SetName (ESL_MSA *msa, const char *s, esl_pos_t n);
151 extern int esl_msa_SetDesc (ESL_MSA *msa, const char *s, esl_pos_t n);
152 extern int esl_msa_SetAccession (ESL_MSA *msa, const char *s, esl_pos_t n);
153 extern int esl_msa_SetAuthor (ESL_MSA *msa, const char *s, esl_pos_t n);
154 extern int esl_msa_SetSeqName (ESL_MSA *msa, int idx, const char *s, esl_pos_t n);
155 extern int esl_msa_SetSeqAccession (ESL_MSA *msa, int idx, const char *s, esl_pos_t n);
156 extern int esl_msa_SetSeqDescription(ESL_MSA *msa, int idx, const char *s, esl_pos_t n);
157 extern int esl_msa_SetDefaultWeights(ESL_MSA *msa);
158
159 extern int esl_msa_FormatName (ESL_MSA *msa, const char *name, ...);
160 extern int esl_msa_FormatDesc (ESL_MSA *msa, const char *desc, ...);
161 extern int esl_msa_FormatAccession (ESL_MSA *msa, const char *acc, ...);
162 extern int esl_msa_FormatAuthor (ESL_MSA *msa, const char *author, ...);
163 extern int esl_msa_FormatSeqName (ESL_MSA *msa, int idx, const char *name, ...);
164 extern int esl_msa_FormatSeqAccession (ESL_MSA *msa, int idx, const char *acc, ...);
165 extern int esl_msa_FormatSeqDescription(ESL_MSA *msa, int idx, const char *desc, ...);
166
167 extern int esl_msa_AddComment(ESL_MSA *msa, char *p, esl_pos_t n);
168 extern int esl_msa_AddGF (ESL_MSA *msa, char *tag, esl_pos_t taglen, char *value, esl_pos_t vlen);
169 extern int esl_msa_AddGS (ESL_MSA *msa, char *tag, esl_pos_t taglen, int sqidx, char *value, esl_pos_t vlen);
170 extern int esl_msa_AppendGC (ESL_MSA *msa, char *tag, char *value);
171 extern int esl_msa_AppendGR (ESL_MSA *msa, char *tag, int sqidx, char *value);
172
173 extern int esl_msa_CheckUniqueNames(const ESL_MSA *msa);
174
175 /* 4. Miscellaneous functions for manipulating MSAs */
176 extern int esl_msa_ReasonableRF(ESL_MSA *msa, double symfrac, int useconsseq, char *rfline);
177 extern int esl_msa_MarkFragments (const ESL_MSA *msa, float fragthresh, ESL_BITFIELD **ret_fragassign);
178 extern int esl_msa_MarkFragments_old(ESL_MSA *msa, double fragthresh);
179 extern int esl_msa_SequenceSubset(const ESL_MSA *msa, const int *useme, ESL_MSA **ret_new);
180 extern int esl_msa_ColumnSubset (ESL_MSA *msa, char *errbuf, const int *useme);
181 extern int esl_msa_MinimGaps (ESL_MSA *msa, char *errbuf, const char *gaps, int consider_rf);
182 extern int esl_msa_MinimGapsText(ESL_MSA *msa, char *errbuf, const char *gaps, int consider_rf, int fix_bps);
183 extern int esl_msa_NoGaps (ESL_MSA *msa, char *errbuf, const char *gaps);
184 extern int esl_msa_NoGapsText (ESL_MSA *msa, char *errbuf, const char *gaps, int fix_bps);
185 extern int esl_msa_SymConvert(ESL_MSA *msa, const char *oldsyms, const char *newsyms);
186 extern int esl_msa_Checksum(const ESL_MSA *msa, uint32_t *ret_checksum);
187
188 extern int esl_msa_RemoveBrokenBasepairsFromSS(char *ss, char *errbuf, int len, const int *useme);
189 extern int esl_msa_RemoveBrokenBasepairs(ESL_MSA *msa, char *errbuf, const int *useme);
190
191 extern int esl_msa_ReverseComplement(ESL_MSA *msa);
192 extern int esl_msa_Hash(ESL_MSA *msa);
193 extern int esl_msa_FlushLeftInserts(ESL_MSA *msa);
194
195 /* 5. Debugging, testing, development */
196 extern int esl_msa_Validate(const ESL_MSA *msa, char *errmsg);
197 extern ESL_MSA *esl_msa_CreateFromString(const char *s, int fmt);
198 extern int esl_msa_Compare (ESL_MSA *a1, ESL_MSA *a2);
199 extern int esl_msa_CompareMandatory(ESL_MSA *a1, ESL_MSA *a2);
200 extern int esl_msa_CompareOptional (ESL_MSA *a1, ESL_MSA *a2);
201 extern int esl_msa_Sample(ESL_RANDOMNESS *rng, const ESL_ALPHABET *abc, int max_nseq, int max_alen, ESL_MSA **ret_msa);
202
203 #ifdef __cplusplus // magic to make C++ compilers happy
204 }
205 #endif
206 #endif /*eslMSA_INCLUDED*/
207