/
delete-target-gaps.C
137 lines (117 loc) · 3.3 KB
/
delete-target-gaps.C
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
/****************************************************************
train-parallel.C
bmajoros@duke.edu
This is open-source software, governed by the Gnu General Public License (GPL) version 3.
****************************************************************/
#include <mpi.h>
#include <iostream>
#include <fstream>
#include <math.h>
#include "BOOM/String.H"
#include "BOOM/CommandLine.H"
#include "BOOM/MultiAlignment.H"
#include "BOOM/MultSeqAlignment.H"
#include "BOOM/DnaDashDotAlphabet.H"
#include "BOOM/Exceptions.H"
#include "BOOM/AlphabetMap.H"
#include "BOOM/PureDnaAlphabet.H"
using namespace std;
using namespace BOOM;
/****************************************************************
class Application
****************************************************************/
class Application
{
CommandLine *cmd;
MultSeqAlignment *alignment;
Alphabet *alphabet;
BitSet gapSymbols;
AlphabetMap *alphabetMap; // maps gapped alphabet to ungapped alphabet
public:
Application();
int main(int argc,char *argv[]);
};
/****************************************************************
main()
****************************************************************/
int main(int argc,char *argv[])
{
try
{
Application app;
return app.main(argc,argv);
}
catch(const char *p)
{
cerr << p << endl;
}
catch(const String &msg)
{
cerr << msg.c_str() << endl;
}
catch(const string &msg)
{
cerr << msg.c_str() << endl;
}
catch(const exception &e)
{
cerr << "STL exception caught in main:\n" << e.what() << endl;
}
catch(const RootException &e)
{
cerr << "exception: "<< e.getMessage() << endl;
}
catch(...)
{
cerr << "Unknown exception caught in main" << endl;
}
return -1;
}
/****************************************************************
Application methods
****************************************************************/
Application::Application()
: gapSymbols(256)
{
// ctor
}
int Application::main(int argc,char *argv[])
{
// Process command line
cmd=new CommandLine(argc,argv,"");
if(cmd->numArgs()!=2)
throw String("\ndelete-target-gaps <in.maf> <target-name>\n");
String mafFile=cmd->arg(0);
String targetName=cmd->arg(1);
// Setting up alphabet
alphabet=&DnaDashDotAlphabet::global();
gapSymbols.addMember(alphabet->lookup('-'));
gapSymbols.addMember(alphabet->lookup('.'));
gapSymbols.addMember(alphabet->lookup('N'));
alphabetMap=new DropGapMapping(*alphabet,PureDnaAlphabet::global());
// Load the alignments
//int rootID=phylogeny->getRoot()->getID();
alignment=NULL;
ifstream is(mafFile.c_str());
if(!is.good()) throw String("Can't open file ")+mafFile;
while(!is.eof()) {
MultiAlignment *a=new MultiAlignment;
a->loadMAF(is);
if(a->getNumTracks()>0) {
a->toupper();
MultSeqAlignment *m=new MultSeqAlignment(*a,*alphabet,gapSymbols);
int rootID=m->getTrackByName(targetName).getID();
m->deleteTargetGaps(rootID);
if(!alignment) alignment=m;
else {
alignment->append(*m);
delete m;
}
}
delete a;
}
is.close();
// Emit the processed alignment
alignment->printSlice(cout,0,alignment->getLength(),'+',60);
return 0;
}