File: savebest.cpp

package info (click to toggle)
muscle 1%3A3.8.1551-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 1,512 kB
  • sloc: cpp: 27,031; xml: 230; makefile: 38; sh: 10
file content (66 lines) | stat: -rw-r--r-- 1,446 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "muscle.h"
#include "msa.h"
#include "textfile.h"
#include <time.h>

MSA *ptrBestMSA;
static const char *pstrOutputFileName;

void SetOutputFileName(const char *out)
	{
	pstrOutputFileName = out;
	}

void SetCurrentAlignment(MSA &msa)
	{
	ptrBestMSA = &msa;
	}

void SaveCurrentAlignment()
	{
	static bool bCalled = false;
	if (bCalled)
		{
		fprintf(stderr,
		  "\nRecursive call to SaveCurrentAlignment, giving up attempt to save.\n");
		exit(EXIT_FatalError);
		}

	if (0 == ptrBestMSA)
		{
		fprintf(stderr, "\nAlignment not completed, cannot save.\n");
		Log("Alignment not completed, cannot save.\n");
		exit(EXIT_FatalError);
		}

	if (0 == pstrOutputFileName)
		{
		fprintf(stderr, "\nOutput file name not specified, cannot save.\n");
		exit(EXIT_FatalError);
		}

	fprintf(stderr, "\nSaving current alignment ...\n");

	TextFile fileOut(pstrOutputFileName, true);
	ptrBestMSA->ToFASTAFile(fileOut);

	fprintf(stderr, "Current alignment saved to \"%s\".\n", pstrOutputFileName);
	Log("Current alignment saved to \"%s\".\n", pstrOutputFileName);
	}

void CheckMaxTime()
	{
	if (0 == g_ulMaxSecs)
		return;

	time_t Now = time(0);
	time_t ElapsedSecs = Now - GetStartTime();
	if (ElapsedSecs <= (time_t) g_ulMaxSecs)
		return;

	Log("Max time %s exceeded, elapsed seconds = %ul\n",
	  MaxSecsToStr(), ElapsedSecs);

	SaveCurrentAlignment();
	exit(EXIT_Success);
	}