Debian Codegraph @

easel/esl_msafile.h

raw symbols SCIP
1 /* Multiple sequence alignment file i/o
2 *
3 * See also: esl_msafile2.[ch], which contains a legacy ESL_MSAFILE2 interface
4 * that includes support for --small option in various tools.
5 */
6 #ifndef eslMSAFILE_INCLUDED
7 #define eslMSAFILE_INCLUDED
8 #include <esl_config.h>
9
10 #include <stdio.h>
11
12 #include "esl_alphabet.h" /* digital alphabets */
13 #include "esl_buffer.h" /* string hashes, for mapping uniq seq names */
14 #include "esl_msa.h" /* ESL_MSA structure */
15 #include "esl_ssi.h" /* indexes of large flatfiles on disk */
16
17 /* Object: ESL_MSAFILE_FMTDATA
18 *
19 * Additional (often optional) information about variants of some file
20 * formats. Not much in here right now - but figured this might need
21 * to expand in the future, best to have the mechanism in place.
22 *
23 * Used in three ways:
24 * 1. When opening an MSA file in a known format (as opposed to
25 * guessing an unknown format), caller may provide an <ESL_MSAFILE_FMTDATA>
26 * structure containing any additional constraints on the format.
27 * The new <afp> will copy this information into <afp->fmtd>.
28 * 2. When opening an MSA file in an unknown format (calling GuessFileFormat()),
29 * format-specific autodetectors fill in <afp->fmtd> with any additional
30 * constraints.
31 * 3. When writing an MSA file, caller may provide additional constraints on
32 * the format; notably <fmtd->rpl>, the number of residues per line,
33 * used for many formats.
34 *
35 * TODO: If this fills up with more information, we should eventually
36 * consolidate the format code too; create ESL_MSAFORMAT structure
37 * to hold both integer code and optional information; implement
38 * it in esl_msaformat.[ch]; put format guessing routines there;
39 * rename eslMSAFILE_* -> eslMSAFORMAT_*. For now, not worth the
40 * time, because it's really only a placeholder dealing with a small
41 * PHYLIP-specific format issue. <format>, <fmtd> are generally
42 * an ordered pair, to facilitate eventual replacement w/ single
43 * <fmt>. [SRE, 19 Jul 11]
44 */
45 typedef struct {
46 int namewidth; /* PHYLIP only: width of the name field (usually 10, but can vary) unset=0 */
47 int rpl; /* several formats: residues per line unset=0 */
48 } ESL_MSAFILE_FMTDATA;
49
50
51
52 /* Object: ESL_MSAFILE
53 *
54 * An alignment file open for parsing.
55 */
56 typedef struct {
57 ESL_BUFFER *bf; /* input file/data being parsed */
58
59 int32_t format; /* format of alignment file we're reading */
60 ESL_MSAFILE_FMTDATA fmtd; /* additional (often optional) format-specific details. */
61
62 char *line; /* line read from <bf> by <esl_msafile_GetLine()> */
63 esl_pos_t n; /* length of line in bytes (line is not NUL-terminated) */
64 int64_t linenumber; /* input linenumber for diagnostics; -1 if we lose track */
65 esl_pos_t lineoffset; /* offset of start of <line> in <bf>; -1 if line unset */
66
67 ESL_DSQ inmap[128]; /* input map, 0..127 */
68 const ESL_ALPHABET *abc; /* non-NULL if in digital mode */
69 ESL_SSI *ssi; /* open SSI index; or NULL if none */
70 char errmsg[eslERRBUFSIZE]; /* user-directed message for normal errors */
71 } ESL_MSAFILE;
72
73
74 /* Alignment file format codes.
75 * Must coexist with sqio unaligned file format codes.
76 * Rules:
77 * - 0 is an unknown/unassigned format
78 * - <=100 reserved for unaligned formats
79 * - >100 reserved for aligned formats
80 */
81 #define eslMSAFILE_UNKNOWN 0 /* unknown format */
82 #define eslMSAFILE_STOCKHOLM 101 /* Stockholm format, interleaved */
83 #define eslMSAFILE_PFAM 102 /* Pfam/Rfam one-line-per-seq Stockholm format */
84 #define eslMSAFILE_A2M 103 /* UCSC SAM's fasta-like a2m format */
85 #define eslMSAFILE_PSIBLAST 104 /* NCBI PSI-BLAST alignment format */
86 #define eslMSAFILE_SELEX 105 /* old SELEX format (largely obsolete) */
87 #define eslMSAFILE_AFA 106 /* aligned FASTA format */
88 #define eslMSAFILE_CLUSTAL 107 /* CLUSTAL format */
89 #define eslMSAFILE_CLUSTALLIKE 108 /* CLUSTAL-like formats (MUSCLE, PROBCONS) */
90 #define eslMSAFILE_PHYLIP 109 /* interleaved PHYLIP format */
91 #define eslMSAFILE_PHYLIPS 110 /* sequential PHYLIP format */
92
93
94 /* 1. Opening/closing an ESL_MSAFILE */
95 extern int esl_msafile_Open (ESL_ALPHABET **byp_abc, const char *msafile, const char *env, int format, ESL_MSAFILE_FMTDATA *fmtd, ESL_MSAFILE **ret_afp);
96 extern int esl_msafile_OpenMem (ESL_ALPHABET **byp_abc, const char *p, esl_pos_t n, int format, ESL_MSAFILE_FMTDATA *fmtd, ESL_MSAFILE **ret_afp);
97 extern int esl_msafile_OpenBuffer(ESL_ALPHABET **byp_abc, ESL_BUFFER *bf, int format, ESL_MSAFILE_FMTDATA *fmtd, ESL_MSAFILE **ret_afp);
98 extern void esl_msafile_OpenFailure(ESL_MSAFILE *afp, int status);
99 extern int esl_msafile_SetDigital (ESL_MSAFILE *afp, const ESL_ALPHABET *abc);
100 extern void esl_msafile_Close(ESL_MSAFILE *afp);
101
102 /* 2. ESL_MSAFILE_FMTDATA: optional extra constraints on formats */
103 extern int esl_msafile_fmtdata_Init(ESL_MSAFILE_FMTDATA *fmtd);
104 extern int esl_msafile_fmtdata_Copy(ESL_MSAFILE_FMTDATA *src, ESL_MSAFILE_FMTDATA *dst);
105
106 /* 3. Utilities for different file formats */
107 extern int esl_msafile_GuessFileFormat(ESL_BUFFER *bf, int *ret_fmtcode, ESL_MSAFILE_FMTDATA *fmtd, char *errbuf);
108 extern int esl_msafile_IsMultiRecord(int fmt);
109 extern int esl_msafile_EncodeFormat(char *fmtstring);
110 extern char *esl_msafile_DecodeFormat(int fmt);
111
112 /* 4. Utilities for different alphabets */
113 extern int esl_msafile_GuessAlphabet(ESL_MSAFILE *afp, int *ret_type);
114
115 /* 5. Random access in a MSA flatfile database */
116 extern int esl_msafile_PositionByKey(ESL_MSAFILE *afp, const char *key);
117
118 /* 6. Reading an MSA from an ESL_MSAFILE */
119 extern int esl_msafile_Read(ESL_MSAFILE *afp, ESL_MSA **ret_msa);
120 extern void esl_msafile_ReadFailure(ESL_MSAFILE *afp, int status);
121
122 /* 7. Writing an MSA to a stream */
123 extern int esl_msafile_Write(FILE *fp, ESL_MSA *msa, int fmt);
124
125 /* 8. Utilities for specific parsers */
126 extern int esl_msafile_GetLine(ESL_MSAFILE *afp, char **opt_p, esl_pos_t *opt_n);
127 extern int esl_msafile_PutLine(ESL_MSAFILE *afp);
128
129 #include "esl_msafile_a2m.h"
130 #include "esl_msafile_afa.h"
131 #include "esl_msafile_clustal.h"
132 #include "esl_msafile_phylip.h"
133 #include "esl_msafile_psiblast.h"
134 #include "esl_msafile_selex.h"
135 #include "esl_msafile_stockholm.h"
136 #endif /*eslMSAFILE_INCLUDED*/