1 #include "muscle.h"
2 #include "textfile.h"
3 #include "seqvect.h"
4 #include "distfunc.h"
5 #include "msa.h"
6 #include "tree.h"
7 #include "clust.h"
8 #include "profile.h"
9 #include "clustsetmsa.h"
10 #include "muscle_context.h"
11 
Refine()12 void Refine()
13 	{
14     MuscleContext *ctx = getMuscleContext();
15 
16 	SetOutputFileName(ctx->params.g_pstrOutFileName);
17 	SetInputFileName(ctx->params.g_pstrInFileName);
18 	SetStartTime();
19 
20 	SetMaxIters(ctx->params.g_uMaxIters);
21 	SetSeqWeightMethod(ctx->params.g_SeqWeight1);
22 
23 	TextFile fileIn(ctx->params.g_pstrInFileName);
24 	MSA msa;
25 	msa.FromFile(fileIn);
26 
27 	const unsigned uSeqCount = msa.GetSeqCount();
28 	if (0 == uSeqCount)
29 		Quit("No sequences in input file");
30 
31 	ALPHA Alpha = ALPHA_Undefined;
32 	switch (ctx->params.g_SeqType)
33 		{
34 	case SEQTYPE_Auto:
35 		Alpha = msa.GuessAlpha();
36 		break;
37 
38 	case SEQTYPE_Protein:
39 		Alpha = ALPHA_Amino;
40 		break;
41 
42 	case SEQTYPE_DNA:
43 		Alpha = ALPHA_DNA;
44 		break;
45 
46 	case SEQTYPE_RNA:
47 		Alpha = ALPHA_RNA;
48 		break;
49 
50 	default:
51 		Quit("Invalid SeqType");
52 		}
53 	SetAlpha(Alpha);
54 	msa.FixAlpha();
55 
56 	SetPPScore();
57 	if (ALPHA_DNA == Alpha || ALPHA_RNA == Alpha)
58 		SetPPScore(PPSCORE_SPN);
59 
60 	MSA::SetIdCount(uSeqCount);
61 
62 // Initialize sequence ids.
63 // From this point on, ids must somehow propogate from here.
64 	for (unsigned uSeqIndex = 0; uSeqIndex < uSeqCount; ++uSeqIndex)
65 		msa.SetSeqId(uSeqIndex, uSeqIndex);
66 	SetMuscleInputMSA(msa);
67 
68 	Tree GuideTree;
69 	TreeFromMSA(msa, GuideTree, ctx->params.g_Cluster2, ctx->params.g_Distance2, ctx->params.g_Root2);
70 	SetMuscleTree(GuideTree);
71 
72 	if (ctx->params.g_bAnchors)
73 		RefineVert(msa, GuideTree, ctx->params.g_uMaxIters);
74 	else
75 		RefineHoriz(msa, GuideTree, ctx->params.g_uMaxIters, false, false);
76 
77 	ValidateMuscleIds(msa);
78 	ValidateMuscleIds(GuideTree);
79 
80 //	TextFile fileOut(g_pstrOutFileName, true);
81 //	msa.ToFile(fileOut);
82 	MuscleOutput(msa);
83 	}
84