Debian Codegraph @

easel/miniapps/esl-alirev.c

raw symbols SCIP
1
2
3 #include "easel.h"
4 #include "esl_alphabet.h"
5 #include "esl_getopts.h"
6 #include "esl_msa.h"
7 #include "esl_msafile.h"
8 #include "esl_vectorops.h"
9
10 #include <stdio.h>
11
12 static ESL_OPTIONS options[] = {
13 /* name type default env range toggles reqs incomp help docgroup*/
14 { "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show brief help on version and usage", 0 },
15 { "--informat", eslARG_STRING, NULL, NULL, NULL, NULL, NULL, NULL, "specify the input MSA file is in format <s>", 0 },
16 { "--outformat", eslARG_STRING, NULL, NULL, NULL, NULL, NULL, NULL, "write the output MSA in format <s>", 0 },
17 { "--dna", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "use DNA alphabet", 0 },
18 { "--rna", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "use RNA alphabet", 0 },
19 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
20 };
21 static char usage[] = "[-options] <msafile>";
22 static char banner[] = "reverse complement multiple sequence alignment(s)";
23
24 int
25 main(int argc, char **argv)
26 {
27 ESL_GETOPTS *go = esl_getopts_CreateDefaultApp(options, 1, argc, argv, banner, usage);
28 char *msafile = esl_opt_GetArg(go, 1);
29 int infmt = eslMSAFILE_UNKNOWN;
30 int outfmt = eslMSAFILE_UNKNOWN;
31 ESL_ALPHABET *abc = NULL;
32 ESL_MSAFILE *afp = NULL;
33 ESL_MSA *msa = NULL;
34 int nali = 0;
35 int status;
36
37 /* Alphabet specification from cmdline? */
38 if (esl_opt_GetBoolean(go, "--rna")) abc = esl_alphabet_Create(eslRNA);
39 else if (esl_opt_GetBoolean(go, "--dna")) abc = esl_alphabet_Create(eslDNA);
40
41 /* MSA input file format from cmdline? */
42 if (esl_opt_IsOn(go, "--informat") &&
43 (infmt = esl_msafile_EncodeFormat(esl_opt_GetString(go, "--informat"))) == eslMSAFILE_UNKNOWN)
44 esl_fatal("Your --informat, %s, is not a recognized multiple alignment file format",
45 esl_opt_GetString(go, "--informat"));
46
47 /* Open in digital mode. Autoguess alphabet, format if we haven't set them already. */
48 if (( status = esl_msafile_Open(&abc, msafile, NULL, infmt, NULL, &afp)) != eslOK)
49 esl_msafile_OpenFailure(afp, status);
50
51 /* Reverse complementation only makes sense for alphabets that have abc->complement set */
52 if (! abc->complement)
53 esl_fatal("File %s appears to use the %s alphabet.\nThat alphabet cannot be reverse complemented.\n",
54 msafile, esl_abc_DecodeType(abc->type));
55
56 /* Set the output format, if requested.
57 * By default, write in the same format we read in.
58 * Remember, it's afp->format that gets set; infmt was only a hint.
59 */
60 if ( esl_opt_IsOn(go, "--outformat") )
61 {
62 outfmt = esl_msafile_EncodeFormat(esl_opt_GetString(go, "--outformat"));
63 if (outfmt == eslMSAFILE_UNKNOWN)
64 esl_fatal("Your --outformat, %s, is not a recognized multiple alignment file format.\n",
65 esl_opt_GetString(go, "--outformat"));
66 }
67 else outfmt = afp->format;
68
69 /* Here we go. */
70 while ((status = esl_msafile_Read(afp, &msa)) == eslOK)
71 {
72 nali++;
73
74 status = esl_msa_ReverseComplement(msa);
75
76 esl_msafile_Write(stdout, msa, outfmt);
77
78 esl_msa_Destroy(msa);
79 }
80 if (nali == 0) esl_fatal("No alignments found in input file %s\n", msafile);
81 if (status != eslEOF) esl_msafile_ReadFailure(afp, status);
82
83 esl_msafile_Close(afp);
84 esl_alphabet_Destroy(abc);
85 esl_getopts_Destroy(go);
86 return 0;
87 }