1 #include "muscle.h"
2 #include "textfile.h"
3 #include "msa.h"
4 #include "profile.h"
5 #include "pwpath.h"
6 #include "tree.h"
7 
8 #define TRACE	0
9 
MSAFromFileName(const char * FileName,MSA & a)10 static void MSAFromFileName(const char *FileName, MSA &a)
11 	{
12 	TextFile File(FileName);
13 	a.FromFile(File);
14 	}
15 
ProfileFromMSALocal(MSA & msa,Tree & tree)16 static ProfPos *ProfileFromMSALocal(MSA &msa, Tree &tree)
17 	{
18 	const unsigned uSeqCount = msa.GetSeqCount();
19 	for (unsigned uSeqIndex = 0; uSeqIndex < uSeqCount; ++uSeqIndex)
20 		msa.SetSeqId(uSeqIndex, uSeqIndex);
21 
22 	TreeFromMSA(msa, tree, g_Cluster1, g_Distance1, g_Root1);
23 	SetMuscleTree(tree);
24 	return ProfileFromMSA(msa);
25 	}
26 
Local()27 void Local()
28 	{
29 	if (0 == g_pstrFileName1 || 0 == g_pstrFileName2)
30 		Quit("Must specify both -in1 and -in2 for -sw");
31 
32 	SetSeqWeightMethod(g_SeqWeight1);
33 
34 	MSA msa1;
35 	MSA msa2;
36 
37 	MSAFromFileName(g_pstrFileName1, msa1);
38 	MSAFromFileName(g_pstrFileName2, msa2);
39 
40 	ALPHA Alpha = ALPHA_Undefined;
41 	switch (g_SeqType)
42 		{
43 	case SEQTYPE_Auto:
44 		Alpha = msa1.GuessAlpha();
45 		break;
46 
47 	case SEQTYPE_Protein:
48 		Alpha = ALPHA_Amino;
49 		break;
50 
51 	case SEQTYPE_DNA:
52 		Alpha = ALPHA_DNA;
53 		break;
54 
55 	case SEQTYPE_RNA:
56 		Alpha = ALPHA_RNA;
57 		break;
58 
59 	default:
60 		Quit("Invalid SeqType");
61 		}
62 	SetAlpha(Alpha);
63 
64 	msa1.FixAlpha();
65 	msa2.FixAlpha();
66 
67 	if (ALPHA_DNA == Alpha || ALPHA_RNA == Alpha)
68 		SetPPScore(PPSCORE_SPN);
69 
70 	const unsigned uSeqCount1 = msa1.GetSeqCount();
71 	const unsigned uSeqCount2 = msa2.GetSeqCount();
72 	const unsigned uMaxSeqCount = (uSeqCount1 > uSeqCount2 ? uSeqCount1 : uSeqCount2);
73 	MSA::SetIdCount(uMaxSeqCount);
74 
75 	unsigned uLength1 = msa1.GetColCount();
76 	unsigned uLength2 = msa2.GetColCount();
77 
78 	Tree tree1;
79 	Tree tree2;
80 
81 	ProfPos *Prof1 = ProfileFromMSALocal(msa1, tree1);
82 	ProfPos *Prof2 = ProfileFromMSALocal(msa2, tree2);
83 
84 	PWPath Path;
85 	SW(Prof1, uLength1, Prof2, uLength2, Path);
86 
87 #if	TRACE
88 	Path.LogMe();
89 #endif
90 
91 	MSA msaOut;
92 	AlignTwoMSAsGivenPathSW(Path, msa1, msa2, msaOut);
93 
94 #if	TRACE
95 	msaOut.LogMe();
96 #endif
97 
98 	TextFile fileOut(g_pstrOutFileName, true);
99 	msaOut.ToFile(fileOut);
100 	}
101