File: profile.cpp

package info (click to toggle)
libmuscle 3.7%2B4565-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,828 kB
  • ctags: 2,200
  • sloc: cpp: 27,959; makefile: 55; sh: 26
file content (163 lines) | stat: -rw-r--r-- 3,481 bytes parent folder | download | duplicates (5)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#include "libMUSCLE/muscle.h"
#include "libMUSCLE/textfile.h"
#include "libMUSCLE/msa.h"
#include "libMUSCLE/tree.h"
#include "libMUSCLE/profile.h"
#include "libMUSCLE/objscore.h"

namespace muscle {

bool TreeNeededForWeighting(SEQWEIGHT s)
	{
	switch (s)
		{
	case SEQWEIGHT_ClustalW:
	case SEQWEIGHT_ThreeWay:
		return true;
	default:
		return false;
		}
	}

static ProfPos *ProfileFromMSALocal(MSA &msa, Tree &tree)
	{
	const unsigned uSeqCount = msa.GetSeqCount();
	for (unsigned uSeqIndex = 0; uSeqIndex < uSeqCount; ++uSeqIndex)
		msa.SetSeqId(uSeqIndex, uSeqIndex);
	if (TreeNeededForWeighting(g_SeqWeight2.get()))
		{
		TreeFromMSA(msa, tree, g_Cluster2.get(), g_Distance2.get(), g_Root1.get());
		SetMuscleTree(tree);
		}
	return ProfileFromMSA(msa);
	}

void SetProfileProfileAlphabet(MSA &msa1, MSA &msa2)
{
	ALPHA Alpha = ALPHA_Undefined;
	switch (g_SeqType.get())
		{
	case SEQTYPE_Auto:
		Alpha = msa1.GuessAlpha();
		break;

	case SEQTYPE_Protein:
		Alpha = ALPHA_Amino;
		break;

	case SEQTYPE_DNA:
		Alpha = ALPHA_DNA;
		break;

	case SEQTYPE_RNA:
		Alpha = ALPHA_RNA;
		break;

	default:
		Quit("Invalid SeqType");
		}
	SetAlpha(Alpha);

	msa1.FixAlpha();
	msa2.FixAlpha();

	if (ALPHA_DNA == Alpha || ALPHA_RNA == Alpha)
		SetPPScore(PPSCORE_SPN);
}

void ProfileProfile(MSA &msa1, MSA &msa2, MSA &msaOut)
	{

	unsigned uLength1;
	unsigned uLength2;

	uLength1 = msa1.GetColCount();
	uLength2 = msa2.GetColCount();

	Tree tree1;
	Tree tree2;
	ProfPos *Prof1 = ProfileFromMSALocal(msa1, tree1);
	ProfPos *Prof2 = ProfileFromMSALocal(msa2, tree2);

	PWPath Path;
	ProfPos *ProfOut;
	unsigned uLengthOut;
	Progress("Aligning profiles");
	AlignTwoProfs(Prof1, uLength1, 1.0, Prof2, uLength2, 1.0, Path, &ProfOut, &uLengthOut);

	Progress("Building output");
	AlignTwoMSAsGivenPath(Path, msa1, msa2, msaOut);
	delete[] Prof1;
	delete[] Prof2;
	delete[] ProfOut;
	}

// Do profile-profile alignment
void Profile()
	{
	if ( !g_bProfileOnStdIn.get() && (0 == g_pstrFileName1.get() || 0 == g_pstrFileName2.get()))
		Quit("-profile needs -in1 and -in2 or -ProfileOnStdIn");

	SetSeqWeightMethod(g_SeqWeight1.get());

	MSA msa1;
	MSA msa2;
	MSA msaOut;

	if( !g_bProfileOnStdIn.get() )
	{
		TextFile file1(g_pstrFileName1.get());
		TextFile file2(g_pstrFileName2.get());
		msa1.FromFile(file1);
		msa2.FromFile(file2);
	}else{
		TextFile file1("-");
		TextFile file2("-");
		msa1.FromFile(file1);
		msa2.FromFile(file2);
	}

	ALPHA Alpha = ALPHA_Undefined;
	switch (g_SeqType.get())
		{
	case SEQTYPE_Auto:
		Alpha = msa1.GuessAlpha();
		break;

	case SEQTYPE_Protein:
		Alpha = ALPHA_Amino;
		break;

	case SEQTYPE_DNA:
		Alpha = ALPHA_DNA;
		break;

	case SEQTYPE_RNA:
		Alpha = ALPHA_RNA;
		break;

	default:
		Quit("Invalid seq type");
		}
	SetAlpha(Alpha);
	msa1.FixAlpha();
	msa2.FixAlpha();
	SetPPScore();

	const unsigned uSeqCount1 = msa1.GetSeqCount();
	const unsigned uSeqCount2 = msa2.GetSeqCount();
	//const unsigned uMaxSeqCount = (uSeqCount1 > uSeqCount2 ? uSeqCount1 : uSeqCount2);
	//MSA::SetIdCount(uMaxSeqCount);
	const unsigned uSumSeqCount = uSeqCount1 + uSeqCount2;
	MSA::SetIdCount(uSumSeqCount);


	SetProfileProfileAlphabet(msa1, msa2);
	if( g_bAnchoredPP.get() )
		AnchoredProfileProfile(msa1, msa2, msaOut);
	else
		ProfileProfile(msa1, msa2, msaOut);

	MuscleOutput(msaOut);
	}
}