Skip to content

Instantly share code, notes, and snippets.

@cory-ko-g
Created November 21, 2011 17:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cory-ko-g/1383335 to your computer and use it in GitHub Desktop.
Save cory-ko-g/1383335 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include "emboss.h"
static AjPStr getUniqueFileName(void);
int main (int argc, char **argv) {
AjPSeqall seqall;
AjPSeqout seqout;
AjPSeq seq = NULL;
embInitPV("ctest", argc, argv, "CORY", "1.0.0");
seqall = ajAcdGetSeqall("sequence");
seqout = ajAcdGetSeqoutall("outseq");
// [START] make temporary multi-fasta file
AjPStr tmp = NULL;
AjPStr tmpFileName = NULL;
AjPSeqout fil_file;
ajint nb = 0;
AjBool are_prot = ajFalse;
ajint size = 0;
fil_file = ajSeqoutNew();
tmpFileName = getUniqueFileName();
if( !ajSeqoutOpenFilename(fil_file, tmpFileName) ) {
embExitBad();
}
tmp = ajStrNewC("fasta");
ajSeqoutSetFormatS(fil_file, tmp);
while (ajSeqallNext(seqall, &seq)) {
if (!nb) {
are_prot = ajSeqIsProt(seq);
}
ajSeqoutWriteSeq(fil_file, seq);
++nb;
}
ajSeqoutClose(fil_file);
ajSeqoutDel(&fil_file);
if (nb < 2) {
ajFatal("Multiple alignments need at least two sequences");
}
// [END] make temporary multi-fasta file
// your code...
ajSysFileUnlinkS(tmpFileName);
ajSeqoutClose(seqout);
ajSeqallDel(&seqall);
ajSeqDel(&seq);
ajSeqoutDel(&seqout);
embExit();
return 0;
}
static AjPStr getUniqueFileName(void) {
static char ext[2] = "A";
AjPStr filename = NULL;
ajFmtPrintS(&filename, "%08d%s",getpid(), ext);
if( ++ext[0] > 'Z' ) {
ext[0] = 'A';
}
return filename;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment