-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsg2vg.cpp
152 lines (132 loc) · 3.67 KB
/
sg2vg.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
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
/*
* Copyright (C) 2015 by Glenn Hickey ([email protected])
*
* Released under the MIT license, see LICENSE.txt
*/
#include <string>
#include <cstdlib>
#include <iostream>
#include <cassert>
#include <fstream>
#include <cstdio>
#include <getopt.h>
#include "sgclient.h"
#include "download.h"
#include "side2seq.h"
#include "sg2vgjson.h"
using namespace std;
void help(char** argv)
{
cerr << "ga2vg: Convert GA4GH graph server to VG (JSON printed to stdout)\n"
<< "\nusage: " << argv[0] << " <URL> [options]\n"
<< "args:\n"
<< " URL: Input GA4GH graph server URL to convert\n"
<< " (Important: URL must end with version, ex. /v0.6.g)\n"
<< "options:\n"
<< " -h, --help \n"
<< " -p, --pageSize Number of records per POST request "
<< "(default=" << SGClient::DefaultPageSize << ").\n"
<< " -u, --upper Write all sequences in upper case.\n"
<< " -a, --paths Add a VG path for each input sequence.\n"
<< " -n, --no-paths Don't write any paths.\n"
<< endl;
}
int main(int argc, char** argv)
{
if (argc < 2)
{
help(argv);
return 1;
}
int pageSize = SGClient::DefaultPageSize;
bool upperCase = false;
bool seqPaths = false;
bool skipPaths = false;
optind = 1;
while (true)
{
static struct option long_options[] =
{
{"help", no_argument, 0, 'h'},
{"page", required_argument, 0, 'p'},
{"upper", no_argument, 0, 'u'},
{"paths", no_argument, 0, 'a'},
{"no-paths", no_argument, 0, 'n'}
};
int option_index = 0;
int c = getopt_long(argc, argv, "hp:uan", long_options, &option_index);
if (c == -1)
{
break;
}
switch(c)
{
case 'h':
case '?':
help(argv);
exit(1);
case 'p':
pageSize = atoi(optarg);
break;
case 'u':
upperCase = true;
break;
case 'a':
seqPaths = true;
break;
case 'n':
skipPaths = true;
break;
default:
abort();
}
}
Download::init();
string url = argv[optind];
SGClient sgClient;
sgClient.setURL(url);
sgClient.setOS(&cerr);
sgClient.setPageSize(pageSize);
sgClient.setSkipPaths(skipPaths);
// ith element is bases for sequence with id i in side graph
vector<string> bases;
// ith element is <name, segment vector> for allele i
vector<SGNamedPath> paths;
const SideGraph* sg = sgClient.downloadGraph(bases, paths);
// convert side graph into sequence graph (which is stored
cerr << "Converting Side Graph to VG Sequence Graph" << endl;
Side2Seq converter;
converter.init(sg, &bases, &paths, upperCase, seqPaths, "&SG_");
converter.convert();
const SideGraph* outGraph = converter.getOutGraph();
const vector<string>& outBases = converter.getOutBases();
const vector<SGNamedPath>& outPaths = converter.getOutPaths();
// write to vg json
cerr << "Writing VG JSON to stdout" << endl;
SG2VGJSON jsonWriter;
jsonWriter.init(&cout);
jsonWriter.writeGraph(outGraph, outBases, outPaths);
/*
cerr << "INPUT " << endl;
cerr << *sgClient.getSideGraph() << endl;
cerr << "OUTPUT " << endl;
cerr << *outGraph << endl;
for (int i = 0; i < outPaths.size(); ++i)
{
cerr << "path " << i << ":\n";
cerr << "input " << "name=" << outPaths[i].first;
for (int j = 0; j < outPaths[i].second.size(); ++j)
{
cerr << outPaths[i].second[j] << ", ";
}
cerr << endl;
cerr << "output " << "name=" << outPaths[i].first;
for (int j = 0; j < outPaths[i].second.size(); ++j)
{
cerr << outPaths[i].second[j] << ", ";
}
cerr << endl;
}
*/
Download::cleanup();
}