78 auto& os = target->ostream();
87 os << in <<
"\"version\": 3,\n";
90 os << in <<
"\"metadata\": {\n";
91 os << in << in <<
"\"program\": \"" <<
utils::escape( program_ ) <<
"\",\n";
92 os << in << in <<
"\"invocation\": \"" <<
utils::escape( invocation_ ) <<
"\",\n";
99 newick_writer.enable_names(
true);
100 newick_writer.enable_branch_lengths(
true);
101 newick_writer.branch_length_precision( branch_length_precision_ );
102 newick_writer.trailing_new_line(
false );
103 os << in <<
"\"tree\": \"";
108 os << in <<
"\"fields\": [ \"edge_num\", \"likelihood\", \"like_weight_ratio\", "
109 <<
"\"distal_length\", \"pendant_length\" ],\n";
112 os << in <<
"\"placements\": [\n";
113 for(
size_t i = 0; i < sample.
size(); ++i ) {
114 auto const& pquery = sample.
at(i);
115 os << in << in <<
"{\n";
118 os << in << in << in <<
"\"p\": [\n";
119 for(
size_t j = 0; j < pquery.placement_size(); ++j ) {
121 os << in << in << in << in <<
"[ ";
124 os << placement.likelihood <<
", ";
125 os << placement.like_weight_ratio <<
", ";
128 os << edge_data.
branch_length - placement.proximal_length <<
", ";
129 os << placement.pendant_length;
132 if( j < pquery.placement_size() - 1 ) {
137 os << in << in << in <<
"],\n";
141 for(
auto const& pqry_name : pquery.names() ) {
142 has_nm |= ( pqry_name.multiplicity != 1.0 );
149 os << in << in << in <<
"\"nm\": [\n";
150 for(
size_t j = 0; j < pquery.name_size(); ++j ) {
151 os << in << in << in << in <<
"[ \"";
153 os << pquery.name_at(j).multiplicity <<
" ]";
155 if( j < pquery.name_size() - 1 ) {
160 os << in << in << in <<
"]\n";
165 os << in << in << in <<
"\"n\": [ ";
166 for(
size_t j = 0; j < pquery.name_size(); ++j ) {
167 os <<
"\"" <<
utils::escape( pquery.name_at(j).name ) <<
"\"";
169 if( j < pquery.name_size() - 1 ) {
178 os << in << in <<
"}";
179 if( i < sample.
size() - 1 ) {
192 using namespace utils;
193 JsonDocument doc = JsonDocument::object();
197 newick_writer.enable_names(
true);
198 newick_writer.enable_branch_lengths(
true);
199 newick_writer.branch_length_precision( branch_length_precision_ );
200 newick_writer.trailing_new_line(
false );
201 doc[
"tree" ] = newick_writer.to_string( smp.
tree() );
204 auto& placements_arr = doc[
"placements" ];
205 for(
auto const& pqry : smp.
pqueries() ) {
206 auto jpqry = JsonDocument::object();
209 auto pqry_p_arr = JsonDocument::array();
210 for(
auto const& pqry_place : pqry.placements() ) {
211 auto pqry_fields = JsonDocument::array();
213 pqry_fields.push_back( JsonDocument::number_unsigned( pqry_place.edge_num() ));
214 pqry_fields.push_back( JsonDocument::number_float( pqry_place.likelihood ));
215 pqry_fields.push_back( JsonDocument::number_float( pqry_place.like_weight_ratio ));
219 pqry_fields.push_back( JsonDocument::number_float(
220 edge_data.branch_length - pqry_place.proximal_length
222 pqry_fields.push_back( JsonDocument::number_float( pqry_place.pendant_length ));
224 pqry_p_arr.push_back( pqry_fields );
226 jpqry[
"p" ] = pqry_p_arr;
230 for(
auto const& pqry_name : pqry.names() ) {
231 has_nm |= ( pqry_name.multiplicity != 1.0 );
236 auto pqry_nm_arr = JsonDocument::array();
237 for(
auto const& pqry_name : pqry.names() ) {
238 auto pqry_nm_val = JsonDocument::array();
239 pqry_nm_val.push_back( pqry_name.name );
240 pqry_nm_val.push_back( JsonDocument::number_float( pqry_name.multiplicity ));
241 pqry_nm_arr.push_back( pqry_nm_val );
243 jpqry[
"nm" ] = pqry_nm_arr;
245 auto pqry_n_arr = JsonDocument::array();
246 for(
auto const& pqry_name : pqry.names() ) {
247 pqry_n_arr.push_back( pqry_name.name );
249 jpqry[
"n" ] = pqry_n_arr;
252 placements_arr.push_back( jpqry );
256 auto jfields = JsonDocument::array();
257 jfields.push_back(
"edge_num" );
258 jfields.push_back(
"likelihood" );
259 jfields.push_back(
"like_weight_ratio" );
260 jfields.push_back(
"distal_length" );
261 jfields.push_back(
"pendant_length" );
262 doc[
"fields" ] = jfields;
265 doc[
"version" ] = 3;
268 auto jmetadata = JsonDocument::object();
269 jmetadata[
"program" ] = program_;
270 jmetadata[
"invocation" ] = invocation_;
272 doc[
"metadata" ] = jmetadata;