-
Notifications
You must be signed in to change notification settings - Fork 4
/
phy_cut_partition.cpp
78 lines (54 loc) · 2.01 KB
/
phy_cut_partition.cpp
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
#include <stdexcept>
#include <iomanip>
#include <iterator>
#include <fstream>
#include "ivymike/large_phylip.h"
#include "blast_partassign.h"
#include "papara.h"
using ivy_mike::large_phylip;
int main( int argc, char *argv[] ) {
const char *in_phylip = argv[1];
const char *partfile = argv[2];
const char *part_name = argv[3];
assert( argc == 4 );
assert( in_phylip != 0 );
assert( partfile != 0 );
assert( part_name != 0 );
large_phylip lp( in_phylip );
// lp.map();
size_t col_min = -1;
size_t col_max = -1;
{
std::ifstream is( partfile );
while( is.good() ) {
partassign::partition part = partassign::next_partition(is);
if( part.start == -1 ) {
throw std::runtime_error( "partition not found" );
}
std::cout << "part: " << part.start << " "<< part.gene_name << "\n";
assert( part.start >= 0 );
assert( part.end > part.start );
if( part.gene_name == part_name ) {
col_min = part.start;
col_max = part.end + 1;
break;
}
}
}
assert( col_min != size_t(-1));
assert( col_min != col_max );
std::ostream &os = std::cout;
size_t name_width = lp.max_name_len() + 1;
os << lp.size() << " " << col_max - col_min << "\n";
for( int i = 0, size = lp.size(); i < size; ++i ) {
std::string name = lp.name_at(i);
ivy_mike::u1_t* seq_start = lp.sequence_begin_at(i);
ivy_mike::u1_t* seq_end = lp.sequence_end_at(i);
size_t seq_len = std::distance( seq_start, seq_end );
assert( col_min < seq_len );
assert( col_max <= seq_len );
os << std::setw(name_width) << std::left << name;
std::copy( seq_start + col_min, seq_start + col_max, std::ostream_iterator<char>(os) );
os << "\n";
}
}