source: trunk/GDE/MUSCLE/src/savebest.cpp

Last change on this file was 10390, checked in by aboeckma, 11 years ago

added muscle sourcles amd makefile

File size: 1.4 KB
Line 
1#include "muscle.h"
2#include "msa.h"
3#include "textfile.h"
4#include <time.h>
5
6MSA *ptrBestMSA;
7static const char *pstrOutputFileName;
8
9void SetOutputFileName(const char *out)
10        {
11        pstrOutputFileName = out;
12        }
13
14void SetCurrentAlignment(MSA &msa)
15        {
16        ptrBestMSA = &msa;
17        }
18
19void SaveCurrentAlignment()
20        {
21        static bool bCalled = false;
22        if (bCalled)
23                {
24                fprintf(stderr,
25                  "\nRecursive call to SaveCurrentAlignment, giving up attempt to save.\n");
26                exit(EXIT_FatalError);
27                }
28
29        if (0 == ptrBestMSA)
30                {
31                fprintf(stderr, "\nAlignment not completed, cannot save.\n");
32                Log("Alignment not completed, cannot save.\n");
33                exit(EXIT_FatalError);
34                }
35
36        if (0 == pstrOutputFileName)
37                {
38                fprintf(stderr, "\nOutput file name not specified, cannot save.\n");
39                exit(EXIT_FatalError);
40                }
41
42        fprintf(stderr, "\nSaving current alignment ...\n");
43
44        TextFile fileOut(pstrOutputFileName, true);
45        ptrBestMSA->ToFASTAFile(fileOut);
46
47        fprintf(stderr, "Current alignment saved to \"%s\".\n", pstrOutputFileName);
48        Log("Current alignment saved to \"%s\".\n", pstrOutputFileName);
49        }
50
51void CheckMaxTime()
52        {
53        if (0 == g_ulMaxSecs)
54                return;
55
56        time_t Now = time(0);
57        time_t ElapsedSecs = Now - GetStartTime();
58        if (ElapsedSecs <= (time_t) g_ulMaxSecs)
59                return;
60
61        Log("Max time %s exceeded, elapsed seconds = %ul\n",
62          MaxSecsToStr(), ElapsedSecs);
63
64        SaveCurrentAlignment();
65        exit(EXIT_Success);
66        }
Note: See TracBrowser for help on using the repository browser.