<commit_before>#include "jplace_util.hpp"

#include <sstream>

using namespace std;

string placement_to_jplace_string(const Placement& p)
{
  ostringstream output;

  output << "[" << to_string(p.branch_id()) << ", ";
  output << to_string(p.likelihood()) << ", ";
  output << to_string(p.lwr()) << ", ";
  output << to_string(p.pendant_length()) << ", ";
  output << to_string(p.distal_length()) << "]";

  return output.str();
}

string pquery_to_jplace_string(const PQuery& pquery)
{
  ostringstream output;

  output << "    {\"p\":" << NEWL; // p for pquery
  output << "      [" << NEWL; // opening bracket for pquery array

  for (auto place : pquery)
  {
    // individual pquery
    output << "      " << placement_to_jplace_string(place) << "," << NEWL;
  }

  // undo last comma
  rwnd(output, 2);
  output << NEWL;

  // closing bracket for pquery array and name column
  output << "      ]," << NEWL <<"    \"n\": [\"" << pquery.sequence().header().c_str() << "\"]" << NEWL;

  output << "    }";// final bracket

  return output.str();
}

std::string pquery_set_to_jplace_string(const PQuery_Set& ps, string& invocation)
{
  ostringstream output;

  output << "{" << NEWL;

  output << "  \"tree\": \"" << ps.newick() << "\"," << NEWL;
  output << "  \"placements\": " << NEWL;
  output << "  [" << NEWL;

  for (auto p : ps)
    output << pquery_to_jplace_string(p) << "," << NEWL;

  // undo the last comma
  rwnd(output, 2);
  output << NEWL;

  output << "  ]," << NEWL;

  // metadata string<commit_msg>added header list support for jplace output<commit_after>#include "jplace_util.hpp"

#include <sstream>

using namespace std;

string placement_to_jplace_string(const Placement& p)
{
  ostringstream output;

  output << "[" << to_string(p.branch_id()) << ", ";
  output << to_string(p.likelihood()) << ", ";
  output << to_string(p.lwr()) << ", ";
  output << to_string(p.pendant_length()) << ", ";
  output << to_string(p.distal_length()) << "]";

  return output.str();
}

string pquery_to_jplace_string(const PQuery& pquery)
{
  ostringstream output;

  output << "    {\"p\":" << NEWL; // p for pquery
  output << "      [" << NEWL; // opening bracket for pquery array

  for (auto place : pquery)
  {
    // individual pquery
    output << "      " << placement_to_jplace_string(place) << "," << NEWL;
  }

  // undo last comma and newline
  rwnd(output, 2);
  output << NEWL;

  // closing bracket for pquery array, and start of name column
  output << "      ]," << NEWL <<"    \"n\": [";
  // list of sequence headers
  for (const auto& header : pquery.sequence().header_list() )
    output << "\"" << header.c_str() << "\",";

  // rewind last comma
  rwnd(output, 1);

  output << "]" << NEWL; // close name bracket

  output << "    }";// final bracket

  return output.str();
}

std::string pquery_set_to_jplace_string(const PQuery_Set& ps, string& invocation)
{
  ostringstream output;

  output << "{" << NEWL;

  output << "  \"tree\": \"" << ps.newick() << "\"," << NEWL;
  output << "  \"placements\": " << NEWL;
  output << "  [" << NEWL;

  for (auto p : ps)
    output << pquery_to_jplace_string(p) << "," << NEWL;

  // undo the last comma
  rwnd(output, 2);
  output << NEWL;

  output << "  ]," << NEWL;

  // metadata string
{'fraction_non_alphanumeric': 0.19565881993274228, 'fraction_numerical': 0.001528584530724549, 'mean_word_length': 3.105395232120452, 'pattern_counts': {'":': 8, '<': 181, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5353670', 'n_tokens_mistral': 1192, 'n_tokens_neox': 1137, 'n_words': 260}