Generated by Cython 0.29.32

Yellow lines hint at Python interaction.
Click on a line that starts with a "+" to see the C code that Cython generated for it.

Raw output: _io.c

+001: # encoding: utf-8
  __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_1) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 002: # cython: profile=False, boundscheck=False, wraparound=False
 003: 
 004: from ._bp cimport BP
+005: import time
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_time, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 5, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_time, __pyx_t_1) < 0) __PYX_ERR(0, 5, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+006: import numpy as np
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_numpy, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_np, __pyx_t_1) < 0) __PYX_ERR(0, 6, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+007: import pandas as pd
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_pandas, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 7, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_pd, __pyx_t_1) < 0) __PYX_ERR(0, 7, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+008: import json
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_json, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 8, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_json, __pyx_t_1) < 0) __PYX_ERR(0, 8, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 009: cimport numpy as np
 010: cimport cython
+011: np.import_array()
  __pyx_t_2 = __pyx_f_5numpy_import_array(); if (unlikely(__pyx_t_2 == ((int)-1))) __PYX_ERR(0, 11, __pyx_L1_error)
 012: 
 013: 
+014: cdef inline np.double_t length_from_edge(unicode token):
static CYTHON_INLINE __pyx_t_5numpy_double_t __pyx_f_2bp_3_io_length_from_edge(PyObject *__pyx_v_token) {
  Py_ssize_t __pyx_v_split_idx;
  PyObject *__pyx_v_split_idx_curly = NULL;
  PyObject *__pyx_v_split_idx_square = NULL;
  __pyx_t_5numpy_double_t __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("length_from_edge", 0);
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_WriteUnraisable("bp._io.length_from_edge", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_split_idx_curly);
  __Pyx_XDECREF(__pyx_v_split_idx_square);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
 015:     cdef:
 016:         Py_ssize_t split_idx
 017: 
 018:     # 0.12345{0123} -> 0.12345
 019:     # OR 0.12345[0123] -> 0.12345
+020:     split_idx_curly = token.find('{')
  if (unlikely(__pyx_v_token == Py_None)) {
    PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "find");
    __PYX_ERR(0, 20, __pyx_L1_error)
  }
  __pyx_t_1 = PyUnicode_Find(__pyx_v_token, __pyx_kp_s_, 0, PY_SSIZE_T_MAX, 1); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-2))) __PYX_ERR(0, 20, __pyx_L1_error)
  __pyx_t_2 = PyInt_FromSsize_t(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 20, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_v_split_idx_curly = __pyx_t_2;
  __pyx_t_2 = 0;
+021:     split_idx_square = token.find('[')
  if (unlikely(__pyx_v_token == Py_None)) {
    PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "find");
    __PYX_ERR(0, 21, __pyx_L1_error)
  }
  __pyx_t_1 = PyUnicode_Find(__pyx_v_token, __pyx_kp_s__2, 0, PY_SSIZE_T_MAX, 1); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-2))) __PYX_ERR(0, 21, __pyx_L1_error)
  __pyx_t_2 = PyInt_FromSsize_t(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 21, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_v_split_idx_square = __pyx_t_2;
  __pyx_t_2 = 0;
+022:     split_idx = max(split_idx_curly, split_idx_square)
  __Pyx_INCREF(__pyx_v_split_idx_square);
  __pyx_t_2 = __pyx_v_split_idx_square;
  __Pyx_INCREF(__pyx_v_split_idx_curly);
  __pyx_t_3 = __pyx_v_split_idx_curly;
  __pyx_t_5 = PyObject_RichCompare(__pyx_t_2, __pyx_t_3, Py_GT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 22, __pyx_L1_error)
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 22, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (__pyx_t_6) {
    __Pyx_INCREF(__pyx_t_2);
    __pyx_t_4 = __pyx_t_2;
  } else {
    __Pyx_INCREF(__pyx_t_3);
    __pyx_t_4 = __pyx_t_3;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_1 = __Pyx_PyIndex_AsSsize_t(__pyx_t_4); if (unlikely((__pyx_t_1 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 22, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_split_idx = __pyx_t_1;
+023:     if split_idx == -1:
  __pyx_t_6 = ((__pyx_v_split_idx == -1L) != 0);
  if (__pyx_t_6) {
/* … */
  }
+024:         return np.double(token)
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 24, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_double); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 24, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_2)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    __pyx_t_4 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_v_token) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_token);
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 24, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_7 = __pyx_PyFloat_AsDouble(__pyx_t_4); if (unlikely((__pyx_t_7 == ((npy_double)-1)) && PyErr_Occurred())) __PYX_ERR(0, 24, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_r = __pyx_t_7;
    goto __pyx_L0;
 025:     else:
+026:         return np.double(token[:split_idx])
  /*else*/ {
    __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 26, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_double); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 26, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(__pyx_v_token == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 26, __pyx_L1_error)
    }
    __pyx_t_3 = __Pyx_PyUnicode_Substring(__pyx_v_token, 0, __pyx_v_split_idx); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 26, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
      }
    }
    __pyx_t_4 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_2, __pyx_t_5, __pyx_t_3) : __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 26, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_7 = __pyx_PyFloat_AsDouble(__pyx_t_4); if (unlikely((__pyx_t_7 == ((npy_double)-1)) && PyErr_Occurred())) __PYX_ERR(0, 26, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_r = __pyx_t_7;
    goto __pyx_L0;
  }
 027: 
 028: 
+029: cdef inline np.int32_t number_from_edge(unicode token):
static CYTHON_INLINE __pyx_t_5numpy_int32_t __pyx_f_2bp_3_io_number_from_edge(PyObject *__pyx_v_token) {
  Py_ssize_t __pyx_v_split_idx;
  Py_ssize_t __pyx_v_end;
  PyObject *__pyx_v_split_idx_curly = NULL;
  PyObject *__pyx_v_split_idx_square = NULL;
  __pyx_t_5numpy_int32_t __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("number_from_edge", 0);
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_WriteUnraisable("bp._io.number_from_edge", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_split_idx_curly);
  __Pyx_XDECREF(__pyx_v_split_idx_square);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
 030:     cdef:
 031:         Py_ssize_t split_idx
 032:         Py_ssize_t end
 033: 
 034:     # 0.12345{0123} -> 0123
 035:     # OR 0.12345[0123] -> 0123
+036:     split_idx_curly = token.find('{')
  if (unlikely(__pyx_v_token == Py_None)) {
    PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "find");
    __PYX_ERR(0, 36, __pyx_L1_error)
  }
  __pyx_t_1 = PyUnicode_Find(__pyx_v_token, __pyx_kp_s_, 0, PY_SSIZE_T_MAX, 1); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-2))) __PYX_ERR(0, 36, __pyx_L1_error)
  __pyx_t_2 = PyInt_FromSsize_t(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 36, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_v_split_idx_curly = __pyx_t_2;
  __pyx_t_2 = 0;
+037:     split_idx_square = token.find('[')
  if (unlikely(__pyx_v_token == Py_None)) {
    PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "find");
    __PYX_ERR(0, 37, __pyx_L1_error)
  }
  __pyx_t_1 = PyUnicode_Find(__pyx_v_token, __pyx_kp_s__2, 0, PY_SSIZE_T_MAX, 1); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-2))) __PYX_ERR(0, 37, __pyx_L1_error)
  __pyx_t_2 = PyInt_FromSsize_t(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 37, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_v_split_idx_square = __pyx_t_2;
  __pyx_t_2 = 0;
+038:     split_idx = max(split_idx_curly, split_idx_square)
  __Pyx_INCREF(__pyx_v_split_idx_square);
  __pyx_t_2 = __pyx_v_split_idx_square;
  __Pyx_INCREF(__pyx_v_split_idx_curly);
  __pyx_t_3 = __pyx_v_split_idx_curly;
  __pyx_t_5 = PyObject_RichCompare(__pyx_t_2, __pyx_t_3, Py_GT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 38, __pyx_L1_error)
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 38, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (__pyx_t_6) {
    __Pyx_INCREF(__pyx_t_2);
    __pyx_t_4 = __pyx_t_2;
  } else {
    __Pyx_INCREF(__pyx_t_3);
    __pyx_t_4 = __pyx_t_3;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_1 = __Pyx_PyIndex_AsSsize_t(__pyx_t_4); if (unlikely((__pyx_t_1 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 38, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_split_idx = __pyx_t_1;
+039:     if split_idx == -1:
  __pyx_t_6 = ((__pyx_v_split_idx == -1L) != 0);
  if (__pyx_t_6) {
/* … */
  }
+040:         return 0
    __pyx_r = 0;
    goto __pyx_L0;
 041:     else:
+042:         end = len(token)
  /*else*/ {
    if (unlikely(__pyx_v_token == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
      __PYX_ERR(0, 42, __pyx_L1_error)
    }
    __pyx_t_1 = __Pyx_PyUnicode_GET_LENGTH(__pyx_v_token); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(0, 42, __pyx_L1_error)
    __pyx_v_end = __pyx_t_1;
+043:         return np.int32(token[split_idx + 1:end - 1])
    __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 43, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_int32); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 43, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(__pyx_v_token == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 43, __pyx_L1_error)
    }
    __pyx_t_2 = __Pyx_PyUnicode_Substring(__pyx_v_token, (__pyx_v_split_idx + 1), (__pyx_v_end - 1)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 43, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    __pyx_t_4 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_5, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2);
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 43, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_7 = __Pyx_PyInt_As_npy_int32(__pyx_t_4); if (unlikely((__pyx_t_7 == ((npy_int32)-1)) && PyErr_Occurred())) __PYX_ERR(0, 43, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_r = __pyx_t_7;
    goto __pyx_L0;
  }
 044: 
 045: 
+046: cdef void _set_node_metadata(np.uint32_t ptr, unicode token,
static void __pyx_f_2bp_3_io__set_node_metadata(__pyx_t_5numpy_uint32_t __pyx_v_ptr, PyObject *__pyx_v_token, PyArrayObject *__pyx_v_names, PyArrayObject *__pyx_v_lengths, PyArrayObject *__pyx_v_edges) {
  __pyx_t_5numpy_double_t __pyx_v_length;
  __pyx_t_5numpy_int32_t __pyx_v_edge;
  Py_ssize_t __pyx_v_split_idx;
  Py_ssize_t __pyx_v_end;
  PyObject *__pyx_v_name = 0;
  PyObject *__pyx_v_token_parsed = 0;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_edges;
  __Pyx_Buffer __pyx_pybuffer_edges;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_lengths;
  __Pyx_Buffer __pyx_pybuffer_lengths;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_names;
  __Pyx_Buffer __pyx_pybuffer_names;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_set_node_metadata", 0);
  __Pyx_INCREF(__pyx_v_token);
  __pyx_pybuffer_names.pybuffer.buf = NULL;
  __pyx_pybuffer_names.refcount = 0;
  __pyx_pybuffernd_names.data = NULL;
  __pyx_pybuffernd_names.rcbuffer = &__pyx_pybuffer_names;
  __pyx_pybuffer_lengths.pybuffer.buf = NULL;
  __pyx_pybuffer_lengths.refcount = 0;
  __pyx_pybuffernd_lengths.data = NULL;
  __pyx_pybuffernd_lengths.rcbuffer = &__pyx_pybuffer_lengths;
  __pyx_pybuffer_edges.pybuffer.buf = NULL;
  __pyx_pybuffer_edges.refcount = 0;
  __pyx_pybuffernd_edges.data = NULL;
  __pyx_pybuffernd_edges.rcbuffer = &__pyx_pybuffer_edges;
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_names.rcbuffer->pybuffer, (PyObject*)__pyx_v_names, &__Pyx_TypeInfo_object, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 46, __pyx_L1_error)
  }
  __pyx_pybuffernd_names.diminfo[0].strides = __pyx_pybuffernd_names.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_names.diminfo[0].shape = __pyx_pybuffernd_names.rcbuffer->pybuffer.shape[0];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_lengths.rcbuffer->pybuffer, (PyObject*)__pyx_v_lengths, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 46, __pyx_L1_error)
  }
  __pyx_pybuffernd_lengths.diminfo[0].strides = __pyx_pybuffernd_lengths.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_lengths.diminfo[0].shape = __pyx_pybuffernd_lengths.rcbuffer->pybuffer.shape[0];
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_edges.rcbuffer->pybuffer, (PyObject*)__pyx_v_edges, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) __PYX_ERR(0, 46, __pyx_L1_error)
  }
  __pyx_pybuffernd_edges.diminfo[0].strides = __pyx_pybuffernd_edges.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_edges.diminfo[0].shape = __pyx_pybuffernd_edges.rcbuffer->pybuffer.shape[0];
/* … */
  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_9);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_edges.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_lengths.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_names.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_WriteUnraisable("bp._io._set_node_metadata", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_edges.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_lengths.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_names.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF(__pyx_v_name);
  __Pyx_XDECREF(__pyx_v_token_parsed);
  __Pyx_XDECREF(__pyx_v_token);
  __Pyx_RefNannyFinishContext();
}
 047:                              np.ndarray[object, ndim=1] names,
 048:                              np.ndarray[np.double_t, ndim=1] lengths,
 049:                              np.ndarray[np.int32_t, ndim=1] edges):
 050:     """Inplace update of names and lengths given token details"""
 051:     cdef:
 052:         np.double_t length
 053:         np.int32_t edge
 054:         Py_ssize_t split_idx, i, end
 055:         unicode name, token_parsed
 056: 
+057:     name = None
  __Pyx_INCREF(Py_None);
  __pyx_v_name = ((PyObject*)Py_None);
+058:     length = 0.0
  __pyx_v_length = 0.0;
+059:     edge = 0
  __pyx_v_edge = 0;
 060: 
 061:     # NOTE: there is likely some fat to trim in this method. we do a lot
 062:     # of work per token, we could probably do that work smarter. as is,
 063:     # the changes to support edge numbers increase parsing ~20%, which
 064:     # is annoying but probably not a critical
+065:     if token[0] == u':':
  __pyx_t_1 = __Pyx_GetItemInt_Unicode(__pyx_v_token, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(__pyx_t_1 == (Py_UCS4)-1)) __PYX_ERR(0, 65, __pyx_L1_error)
  __pyx_t_2 = ((__pyx_t_1 == 58) != 0);
  if (__pyx_t_2) {
/* … */
    goto __pyx_L3;
  }
+066:         token_parsed = token[1:]
    if (unlikely(__pyx_v_token == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 66, __pyx_L1_error)
    }
    __pyx_t_3 = __Pyx_PyUnicode_Substring(__pyx_v_token, 1, PY_SSIZE_T_MAX); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 66, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_v_token_parsed = ((PyObject*)__pyx_t_3);
    __pyx_t_3 = 0;
+067:         length = length_from_edge(token_parsed)
    __pyx_v_length = __pyx_f_2bp_3_io_length_from_edge(__pyx_v_token_parsed);
+068:         edge = number_from_edge(token_parsed)
    __pyx_v_edge = __pyx_f_2bp_3_io_number_from_edge(__pyx_v_token_parsed);
+069:     elif u':' in token:
  if (unlikely(__pyx_v_token == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
    __PYX_ERR(0, 69, __pyx_L1_error)
  }
  __pyx_t_2 = (__Pyx_PyUnicode_ContainsTF(__pyx_kp_u__3, __pyx_v_token, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 69, __pyx_L1_error)
  __pyx_t_4 = (__pyx_t_2 != 0);
  if (__pyx_t_4) {
/* … */
    goto __pyx_L3;
  }
+070:         split_idx = token.rfind(':')
    if (unlikely(__pyx_v_token == Py_None)) {
      PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "rfind");
      __PYX_ERR(0, 70, __pyx_L1_error)
    }
    __pyx_t_5 = PyUnicode_Find(__pyx_v_token, __pyx_kp_s__3, 0, PY_SSIZE_T_MAX, -1); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-2))) __PYX_ERR(0, 70, __pyx_L1_error)
    __pyx_v_split_idx = __pyx_t_5;
+071:         name = token[:split_idx]
    if (unlikely(__pyx_v_token == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 71, __pyx_L1_error)
    }
    __pyx_t_3 = __Pyx_PyUnicode_Substring(__pyx_v_token, 0, __pyx_v_split_idx); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 71, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF_SET(__pyx_v_name, ((PyObject*)__pyx_t_3));
    __pyx_t_3 = 0;
+072:         token_parsed = token[split_idx + 1:]
    if (unlikely(__pyx_v_token == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 72, __pyx_L1_error)
    }
    __pyx_t_3 = __Pyx_PyUnicode_Substring(__pyx_v_token, (__pyx_v_split_idx + 1), PY_SSIZE_T_MAX); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 72, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_v_token_parsed = ((PyObject*)__pyx_t_3);
    __pyx_t_3 = 0;
+073:         length = length_from_edge(token_parsed)
    __pyx_v_length = __pyx_f_2bp_3_io_length_from_edge(__pyx_v_token_parsed);
+074:         edge = number_from_edge(token_parsed)
    __pyx_v_edge = __pyx_f_2bp_3_io_number_from_edge(__pyx_v_token_parsed);
+075:         name = name.strip("'").strip()
    __pyx_t_6 = __Pyx_CallUnboundCMethod1(&__pyx_umethod_PyUnicode_Type_strip, __pyx_v_name, __pyx_kp_s__4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 75, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_strip); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 75, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
      }
    }
    __pyx_t_3 = (__pyx_t_6) ? __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6) : __Pyx_PyObject_CallNoArg(__pyx_t_7);
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 75, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (!(likely(PyUnicode_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_3)->tp_name), 0))) __PYX_ERR(0, 75, __pyx_L1_error)
    __Pyx_DECREF_SET(__pyx_v_name, ((PyObject*)__pyx_t_3));
    __pyx_t_3 = 0;
+076:     elif u'{' in token or u'[' in token:
  if (unlikely(__pyx_v_token == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
    __PYX_ERR(0, 76, __pyx_L1_error)
  }
  __pyx_t_2 = (__Pyx_PyUnicode_ContainsTF(__pyx_kp_u_, __pyx_v_token, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 76, __pyx_L1_error)
  __pyx_t_8 = (__pyx_t_2 != 0);
  if (!__pyx_t_8) {
  } else {
    __pyx_t_4 = __pyx_t_8;
    goto __pyx_L4_bool_binop_done;
  }
  if (unlikely(__pyx_v_token == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
    __PYX_ERR(0, 76, __pyx_L1_error)
  }
  __pyx_t_8 = (__Pyx_PyUnicode_ContainsTF(__pyx_kp_u__2, __pyx_v_token, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 76, __pyx_L1_error)
  __pyx_t_2 = (__pyx_t_8 != 0);
  __pyx_t_4 = __pyx_t_2;
  __pyx_L4_bool_binop_done:;
  if (__pyx_t_4) {
/* … */
    goto __pyx_L3;
  }
 077:         # strip as " {123}" is valid?
+078:         token = token.strip()
    __pyx_t_3 = __Pyx_CallUnboundCMethod0(&__pyx_umethod_PyUnicode_Type_strip, __pyx_v_token); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 78, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    if (!(likely(PyUnicode_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_3)->tp_name), 0))) __PYX_ERR(0, 78, __pyx_L1_error)
    __Pyx_DECREF_SET(__pyx_v_token, ((PyObject*)__pyx_t_3));
    __pyx_t_3 = 0;
+079:         end = len(token)
    if (unlikely(__pyx_v_token == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
      __PYX_ERR(0, 79, __pyx_L1_error)
    }
    __pyx_t_5 = __Pyx_PyUnicode_GET_LENGTH(__pyx_v_token); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 79, __pyx_L1_error)
    __pyx_v_end = __pyx_t_5;
+080:         edge = np.int32(token.strip()[1:end - 1])
    __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 80, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_int32); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 80, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_CallUnboundCMethod0(&__pyx_umethod_PyUnicode_Type_strip, __pyx_v_token); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 80, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_9 = __Pyx_PyObject_GetSlice(__pyx_t_7, 1, (__pyx_v_end - 1), NULL, NULL, NULL, 1, 1, 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 80, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
      __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6);
      if (likely(__pyx_t_7)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_7);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_6, function);
      }
    }
    __pyx_t_3 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_6, __pyx_t_7, __pyx_t_9) : __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_9);
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 80, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_10 = __Pyx_PyInt_As_npy_int32(__pyx_t_3); if (unlikely((__pyx_t_10 == ((npy_int32)-1)) && PyErr_Occurred())) __PYX_ERR(0, 80, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_edge = __pyx_t_10;
 081:     else:
+082:         name = token.replace("'", "").replace('"', "").strip()
  /*else*/ {
    if (unlikely(__pyx_v_token == Py_None)) {
      PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "replace");
      __PYX_ERR(0, 82, __pyx_L1_error)
    }
    __pyx_t_6 = PyUnicode_Replace(__pyx_v_token, __pyx_kp_s__4, __pyx_kp_s__5, -1L); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 82, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_9 = PyUnicode_Replace(((PyObject*)__pyx_t_6), __pyx_kp_s__6, __pyx_kp_s__5, -1L); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 82, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_strip); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 82, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_9 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
      __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_6);
      if (likely(__pyx_t_9)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_9);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_6, function);
      }
    }
    __pyx_t_3 = (__pyx_t_9) ? __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_9) : __Pyx_PyObject_CallNoArg(__pyx_t_6);
    __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
    if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 82, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (!(likely(PyUnicode_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_3)->tp_name), 0))) __PYX_ERR(0, 82, __pyx_L1_error)
    __Pyx_DECREF_SET(__pyx_v_name, ((PyObject*)__pyx_t_3));
    __pyx_t_3 = 0;
  }
  __pyx_L3:;
 083: 
+084:     names[ptr] = name
  __pyx_t_11 = __pyx_v_ptr;
  __pyx_t_12 = __Pyx_BufPtrStrided1d(PyObject **, __pyx_pybuffernd_names.rcbuffer->pybuffer.buf, __pyx_t_11, __pyx_pybuffernd_names.diminfo[0].strides);
  __Pyx_XGOTREF(*__pyx_t_12);
  __Pyx_INCREF(__pyx_v_name); __Pyx_XDECREF(*__pyx_t_12);
  *__pyx_t_12 = __pyx_v_name;
  __Pyx_XGIVEREF(*__pyx_t_12);
+085:     lengths[ptr] = length
  __pyx_t_11 = __pyx_v_ptr;
  *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_double_t *, __pyx_pybuffernd_lengths.rcbuffer->pybuffer.buf, __pyx_t_11, __pyx_pybuffernd_lengths.diminfo[0].strides) = __pyx_v_length;
+086:     edges[ptr] = edge
  __pyx_t_11 = __pyx_v_ptr;
  *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_int32_t *, __pyx_pybuffernd_edges.rcbuffer->pybuffer.buf, __pyx_t_11, __pyx_pybuffernd_edges.diminfo[0].strides) = __pyx_v_edge;
 087: 
 088: 
+089: def write_newick(BP tree, object output, bint include_edge):
/* Python wrapper */
static PyObject *__pyx_pw_2bp_3_io_1write_newick(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_2bp_3_io_1write_newick = {"write_newick", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_2bp_3_io_1write_newick, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_2bp_3_io_1write_newick(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_2bp_3_bp_BP *__pyx_v_tree = 0;
  PyObject *__pyx_v_output = 0;
  int __pyx_v_include_edge;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("write_newick (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_tree,&__pyx_n_s_output,&__pyx_n_s_include_edge,0};
    PyObject* values[3] = {0,0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_tree)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_output)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("write_newick", 1, 3, 3, 1); __PYX_ERR(0, 89, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_include_edge)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("write_newick", 1, 3, 3, 2); __PYX_ERR(0, 89, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "write_newick") < 0)) __PYX_ERR(0, 89, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 3) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
    }
    __pyx_v_tree = ((struct __pyx_obj_2bp_3_bp_BP *)values[0]);
    __pyx_v_output = values[1];
    __pyx_v_include_edge = __Pyx_PyObject_IsTrue(values[2]); if (unlikely((__pyx_v_include_edge == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 89, __pyx_L3_error)
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("write_newick", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 89, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("bp._io.write_newick", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_tree), __pyx_ptype_2bp_3_bp_BP, 1, "tree", 0))) __PYX_ERR(0, 89, __pyx_L1_error)
  __pyx_r = __pyx_pf_2bp_3_io_write_newick(__pyx_self, __pyx_v_tree, __pyx_v_output, __pyx_v_include_edge);
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_2bp_3_io_write_newick(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_2bp_3_bp_BP *__pyx_v_tree, PyObject *__pyx_v_output, int __pyx_v_include_edge) {
  PyObject *__pyx_v_name_stack = 0;
  PyObject *__pyx_v_edge_stack = 0;
  PyObject *__pyx_v_length_stack = 0;
  PyObject *__pyx_v_open_paren_stack = 0;
  PyObject *__pyx_v_name = 0;
  npy_float64 __pyx_v_length;
  Py_ssize_t __pyx_v_idx;
  npy_uint8 __pyx_v_v;
  Py_ssize_t __pyx_v_root_close;
  PyObject *__pyx_v_edge = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("write_newick", 0);
/* … */
  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_13);
  __Pyx_AddTraceback("bp._io.write_newick", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_name_stack);
  __Pyx_XDECREF(__pyx_v_edge_stack);
  __Pyx_XDECREF(__pyx_v_length_stack);
  __Pyx_XDECREF(__pyx_v_open_paren_stack);
  __Pyx_XDECREF(__pyx_v_name);
  __Pyx_XDECREF(__pyx_v_edge);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
/* … */
  __pyx_tuple__37 = PyTuple_Pack(13, __pyx_n_s_tree, __pyx_n_s_output, __pyx_n_s_include_edge, __pyx_n_s_name_stack, __pyx_n_s_edge_stack, __pyx_n_s_length_stack, __pyx_n_s_open_paren_stack, __pyx_n_s_name, __pyx_n_s_length, __pyx_n_s_idx, __pyx_n_s_v, __pyx_n_s_root_close, __pyx_n_s_edge); if (unlikely(!__pyx_tuple__37)) __PYX_ERR(0, 89, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__37);
  __Pyx_GIVEREF(__pyx_tuple__37);
/* … */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_2bp_3_io_1write_newick, NULL, __pyx_n_s_bp__io); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 89, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_write_newick, __pyx_t_1) < 0) __PYX_ERR(0, 89, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_codeobj__38 = (PyObject*)__Pyx_PyCode_New(3, 0, 13, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__37, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_bp__io_pyx, __pyx_n_s_write_newick, 89, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__38)) __PYX_ERR(0, 89, __pyx_L1_error)
 090:     cdef:
 091:         list name_stack
 092:         list edge_stack
 093:         list length_stack
 094:         list open_paren_stack
 095:         object name
 096:         np.npy_float64 length
 097:         Py_ssize_t idx
 098:         np.npy_uint8 v
 099:         Py_ssize_t root_close
 100: 
+101:     length_stack = []
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 101, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_length_stack = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;
+102:     name_stack = []
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 102, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_name_stack = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;
+103:     edge_stack = []
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 103, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_edge_stack = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;
+104:     open_paren_stack = []
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 104, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_open_paren_stack = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;
+105:     root_close = tree.close(0)
  __pyx_v_root_close = ((struct __pyx_vtabstruct_2bp_3_bp_BP *)__pyx_v_tree->__pyx_vtab)->close(__pyx_v_tree, 0, 0);
 106: 
+107:     for idx, v in enumerate(tree.B):
  __pyx_t_2 = 0;
  if (likely(PyList_CheckExact(((PyObject *)__pyx_v_tree->B))) || PyTuple_CheckExact(((PyObject *)__pyx_v_tree->B))) {
    __pyx_t_1 = ((PyObject *)__pyx_v_tree->B); __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = 0;
    __pyx_t_4 = NULL;
  } else {
    __pyx_t_3 = -1; __pyx_t_1 = PyObject_GetIter(((PyObject *)__pyx_v_tree->B)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 107, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 107, __pyx_L1_error)
  }
  for (;;) {
    if (likely(!__pyx_t_4)) {
      if (likely(PyList_CheckExact(__pyx_t_1))) {
        if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_5 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_5); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 107, __pyx_L1_error)
        #else
        __pyx_t_5 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 107, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        #endif
      } else {
        if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_5); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 107, __pyx_L1_error)
        #else
        __pyx_t_5 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 107, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        #endif
      }
    } else {
      __pyx_t_5 = __pyx_t_4(__pyx_t_1);
      if (unlikely(!__pyx_t_5)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 107, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_5);
    }
    __pyx_t_6 = __Pyx_PyInt_As_npy_uint8(__pyx_t_5); if (unlikely((__pyx_t_6 == ((npy_uint8)-1)) && PyErr_Occurred())) __PYX_ERR(0, 107, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_v_v = __pyx_t_6;
    __pyx_v_idx = __pyx_t_2;
    __pyx_t_2 = (__pyx_t_2 + 1);
/* … */
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+108:         if v:
    __pyx_t_7 = (__pyx_v_v != 0);
    if (__pyx_t_7) {
/* … */
      goto __pyx_L5;
    }
+109:             if not tree.isleaf(idx):
      __pyx_t_7 = ((!(((struct __pyx_vtabstruct_2bp_3_bp_BP *)__pyx_v_tree->__pyx_vtab)->isleaf(__pyx_v_tree, __pyx_v_idx, 0) != 0)) != 0);
      if (__pyx_t_7) {
/* … */
      }
+110:                 output.write('(')
        __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_output, __pyx_n_s_write); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 110, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_9 = NULL;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
          __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_8);
          if (likely(__pyx_t_9)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
            __Pyx_INCREF(__pyx_t_9);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_8, function);
          }
        }
        __pyx_t_5 = (__pyx_t_9) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_9, __pyx_kp_s__7) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_kp_s__7);
        __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
        if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 110, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+111:             name_stack.append(tree.name(idx))
      __pyx_t_5 = ((struct __pyx_vtabstruct_2bp_3_bp_BP *)__pyx_v_tree->__pyx_vtab)->name(__pyx_v_tree, __pyx_v_idx, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 111, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_10 = __Pyx_PyList_Append(__pyx_v_name_stack, __pyx_t_5); if (unlikely(__pyx_t_10 == ((int)-1))) __PYX_ERR(0, 111, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+112:             length_stack.append(tree.length(idx))
      __pyx_t_5 = PyFloat_FromDouble(((struct __pyx_vtabstruct_2bp_3_bp_BP *)__pyx_v_tree->__pyx_vtab)->length(__pyx_v_tree, __pyx_v_idx, 0)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 112, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_10 = __Pyx_PyList_Append(__pyx_v_length_stack, __pyx_t_5); if (unlikely(__pyx_t_10 == ((int)-1))) __PYX_ERR(0, 112, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+113:             edge_stack.append(tree.edge(idx))
      __pyx_t_5 = __Pyx_PyInt_From_npy_int32(((struct __pyx_vtabstruct_2bp_3_bp_BP *)__pyx_v_tree->__pyx_vtab)->edge(__pyx_v_tree, __pyx_v_idx, 0)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 113, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_10 = __Pyx_PyList_Append(__pyx_v_edge_stack, __pyx_t_5); if (unlikely(__pyx_t_10 == ((int)-1))) __PYX_ERR(0, 113, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
+114:             open_paren_stack.append(idx)
      __pyx_t_5 = PyInt_FromSsize_t(__pyx_v_idx); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 114, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_10 = __Pyx_PyList_Append(__pyx_v_open_paren_stack, __pyx_t_5); if (unlikely(__pyx_t_10 == ((int)-1))) __PYX_ERR(0, 114, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
 115:         else:
+116:             name = name_stack.pop()
    /*else*/ {
      __pyx_t_5 = __Pyx_PyList_Pop(__pyx_v_name_stack); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 116, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_XDECREF_SET(__pyx_v_name, __pyx_t_5);
      __pyx_t_5 = 0;
+117:             length = length_stack.pop()
      __pyx_t_5 = __Pyx_PyList_Pop(__pyx_v_length_stack); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 117, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_11 = __pyx_PyFloat_AsDouble(__pyx_t_5); if (unlikely((__pyx_t_11 == ((npy_float64)-1)) && PyErr_Occurred())) __PYX_ERR(0, 117, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_v_length = __pyx_t_11;
+118:             edge = edge_stack.pop()
      __pyx_t_5 = __Pyx_PyList_Pop(__pyx_v_edge_stack); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 118, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_XDECREF_SET(__pyx_v_edge, __pyx_t_5);
      __pyx_t_5 = 0;
 119: 
+120:             if name is not None:
      __pyx_t_7 = (__pyx_v_name != Py_None);
      __pyx_t_12 = (__pyx_t_7 != 0);
      if (__pyx_t_12) {
/* … */
      }
 121:                 # if we have magical characters, make sure we quote
+122:                 if set(name) & {';', ',', '(', ')', ':', '_'}:
        __pyx_t_5 = PySet_New(__pyx_v_name); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 122, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_8 = PySet_New(0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 122, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        if (PySet_Add(__pyx_t_8, __pyx_kp_s__8) < 0) __PYX_ERR(0, 122, __pyx_L1_error)
        if (PySet_Add(__pyx_t_8, __pyx_kp_s__9) < 0) __PYX_ERR(0, 122, __pyx_L1_error)
        if (PySet_Add(__pyx_t_8, __pyx_kp_s__7) < 0) __PYX_ERR(0, 122, __pyx_L1_error)
        if (PySet_Add(__pyx_t_8, __pyx_kp_s__10) < 0) __PYX_ERR(0, 122, __pyx_L1_error)
        if (PySet_Add(__pyx_t_8, __pyx_kp_s__3) < 0) __PYX_ERR(0, 122, __pyx_L1_error)
        if (PySet_Add(__pyx_t_8, __pyx_n_s__11) < 0) __PYX_ERR(0, 122, __pyx_L1_error)
        __pyx_t_9 = PyNumber_And(__pyx_t_5, __pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 122, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __pyx_t_12 = (PySet_GET_SIZE(__pyx_t_9) != 0);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        if (__pyx_t_12) {
/* … */
          goto __pyx_L8;
        }
+123:                     output.write("'%s'" % name)
          __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_output, __pyx_n_s_write); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 123, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __pyx_t_5 = __Pyx_PyString_FormatSafe(__pyx_kp_s_s, __pyx_v_name); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 123, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_5);
          __pyx_t_13 = NULL;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
            __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_8);
            if (likely(__pyx_t_13)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
              __Pyx_INCREF(__pyx_t_13);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_8, function);
            }
          }
          __pyx_t_9 = (__pyx_t_13) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_13, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_5);
          __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 123, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
 124:                 else:
+125:                     output.write(name)
        /*else*/ {
          __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_output, __pyx_n_s_write); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 125, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __pyx_t_5 = NULL;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
            __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_8);
            if (likely(__pyx_t_5)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
              __Pyx_INCREF(__pyx_t_5);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_8, function);
            }
          }
          __pyx_t_9 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_5, __pyx_v_name) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_v_name);
          __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
          if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 125, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        }
        __pyx_L8:;
 126: 
+127:             if include_edge:
      __pyx_t_12 = (__pyx_v_include_edge != 0);
      if (__pyx_t_12) {
/* … */
        goto __pyx_L9;
      }
+128:                 output.write(':%f{%d}' % (length, edge))
        __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_output, __pyx_n_s_write); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 128, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_5 = PyFloat_FromDouble(__pyx_v_length); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 128, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_13 = PyTuple_New(2); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 128, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_13);
        __Pyx_GIVEREF(__pyx_t_5);
        PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_5);
        __Pyx_INCREF(__pyx_v_edge);
        __Pyx_GIVEREF(__pyx_v_edge);
        PyTuple_SET_ITEM(__pyx_t_13, 1, __pyx_v_edge);
        __pyx_t_5 = 0;
        __pyx_t_5 = __Pyx_PyString_Format(__pyx_kp_s_f_d, __pyx_t_13); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 128, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
        __pyx_t_13 = NULL;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
          __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_8);
          if (likely(__pyx_t_13)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
            __Pyx_INCREF(__pyx_t_13);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_8, function);
          }
        }
        __pyx_t_9 = (__pyx_t_13) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_13, __pyx_t_5) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_5);
        __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 128, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
 129:             else:
+130:                 output.write(':%f' % length)
      /*else*/ {
        __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_output, __pyx_n_s_write); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 130, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_5 = PyFloat_FromDouble(__pyx_v_length); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 130, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_13 = __Pyx_PyString_Format(__pyx_kp_s_f, __pyx_t_5); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 130, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_13);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __pyx_t_5 = NULL;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
          __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_8);
          if (likely(__pyx_t_5)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
            __Pyx_INCREF(__pyx_t_5);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_8, function);
          }
        }
        __pyx_t_9 = (__pyx_t_5) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_5, __pyx_t_13) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_13);
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
        if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 130, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      }
      __pyx_L9:;
 131: 
+132:             if tree.nsibling(open_paren_stack.pop()) == 0:
      __pyx_t_9 = __Pyx_PyList_Pop(__pyx_v_open_paren_stack); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 132, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_14 = __Pyx_PyInt_As_Py_intptr_t(__pyx_t_9); if (unlikely((__pyx_t_14 == ((npy_intp)-1)) && PyErr_Occurred())) __PYX_ERR(0, 132, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_12 = ((((struct __pyx_vtabstruct_2bp_3_bp_BP *)__pyx_v_tree->__pyx_vtab)->nsibling(__pyx_v_tree, __pyx_t_14, 0) == 0) != 0);
      if (__pyx_t_12) {
/* … */
        goto __pyx_L10;
      }
+133:                 if idx != root_close:
        __pyx_t_12 = ((__pyx_v_idx != __pyx_v_root_close) != 0);
        if (__pyx_t_12) {
/* … */
        }
+134:                     output.write(')')
          __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_output, __pyx_n_s_write); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 134, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __pyx_t_13 = NULL;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
            __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_8);
            if (likely(__pyx_t_13)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
              __Pyx_INCREF(__pyx_t_13);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_8, function);
            }
          }
          __pyx_t_9 = (__pyx_t_13) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_13, __pyx_kp_s__10) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_kp_s__10);
          __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
          if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 134, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
 135:             else:
+136:                 output.write(',')
      /*else*/ {
        __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_output, __pyx_n_s_write); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 136, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_13 = NULL;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
          __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_8);
          if (likely(__pyx_t_13)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
            __Pyx_INCREF(__pyx_t_13);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_8, function);
          }
        }
        __pyx_t_9 = (__pyx_t_13) ? __Pyx_PyObject_Call2Args(__pyx_t_8, __pyx_t_13, __pyx_kp_s__9) : __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_kp_s__9);
        __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
        if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 136, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      }
      __pyx_L10:;
    }
    __pyx_L5:;
 137: 
+138:     output.write(';')
  __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_output, __pyx_n_s_write); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 138, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_8 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) {
    __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_9);
    if (likely(__pyx_t_8)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
      __Pyx_INCREF(__pyx_t_8);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_9, function);
    }
  }
  __pyx_t_1 = (__pyx_t_8) ? __Pyx_PyObject_Call2Args(__pyx_t_9, __pyx_t_8, __pyx_kp_s__8) : __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_kp_s__8);
  __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 138, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 139: 
 140: 
+141: cpdef parse_newick(unicode data):
static PyObject *__pyx_pw_2bp_3_io_3parse_newick(PyObject *__pyx_self, PyObject *__pyx_v_data); /*proto*/
static PyObject *__pyx_f_2bp_3_io_parse_newick(PyObject *__pyx_v_data, CYTHON_UNUSED int __pyx_skip_dispatch) {
  __pyx_t_5numpy_uint32_t __pyx_v_ptr;
  __pyx_t_5numpy_uint32_t __pyx_v_open_ptr;
  Py_ssize_t __pyx_v_token_ptr;
  Py_ssize_t __pyx_v_tmp;
  Py_ssize_t __pyx_v_lag;
  Py_ssize_t __pyx_v_datalen;
  struct __pyx_obj_2bp_3_bp_BP *__pyx_v_topology = 0;
  PyObject *__pyx_v_token = 0;
  PyObject *__pyx_v_last_token = 0;
  PyArrayObject *__pyx_v_names = 0;
  PyArrayObject *__pyx_v_lengths = 0;
  PyArrayObject *__pyx_v_edges = 0;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_edges;
  __Pyx_Buffer __pyx_pybuffer_edges;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_lengths;
  __Pyx_Buffer __pyx_pybuffer_lengths;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_names;
  __Pyx_Buffer __pyx_pybuffer_names;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("parse_newick", 0);
  __Pyx_INCREF(__pyx_v_data);
  __pyx_pybuffer_names.pybuffer.buf = NULL;
  __pyx_pybuffer_names.refcount = 0;
  __pyx_pybuffernd_names.data = NULL;
  __pyx_pybuffernd_names.rcbuffer = &__pyx_pybuffer_names;
  __pyx_pybuffer_lengths.pybuffer.buf = NULL;
  __pyx_pybuffer_lengths.refcount = 0;
  __pyx_pybuffernd_lengths.data = NULL;
  __pyx_pybuffernd_lengths.rcbuffer = &__pyx_pybuffer_lengths;
  __pyx_pybuffer_edges.pybuffer.buf = NULL;
  __pyx_pybuffer_edges.refcount = 0;
  __pyx_pybuffernd_edges.data = NULL;
  __pyx_pybuffernd_edges.rcbuffer = &__pyx_pybuffer_edges;
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_13);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_edges.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_lengths.rcbuffer->pybuffer);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_names.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("bp._io.parse_newick", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_edges.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_lengths.rcbuffer->pybuffer);
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_names.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_topology);
  __Pyx_XDECREF(__pyx_v_token);
  __Pyx_XDECREF(__pyx_v_last_token);
  __Pyx_XDECREF((PyObject *)__pyx_v_names);
  __Pyx_XDECREF((PyObject *)__pyx_v_lengths);
  __Pyx_XDECREF((PyObject *)__pyx_v_edges);
  __Pyx_XDECREF(__pyx_v_data);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_2bp_3_io_3parse_newick(PyObject *__pyx_self, PyObject *__pyx_v_data); /*proto*/
static PyObject *__pyx_pw_2bp_3_io_3parse_newick(PyObject *__pyx_self, PyObject *__pyx_v_data) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("parse_newick (wrapper)", 0);
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_data), (&PyUnicode_Type), 1, "data", 1))) __PYX_ERR(0, 141, __pyx_L1_error)
  __pyx_r = __pyx_pf_2bp_3_io_2parse_newick(__pyx_self, ((PyObject*)__pyx_v_data));
  int __pyx_lineno = 0;
  const char *__pyx_filename = NULL;
  int __pyx_clineno = 0;

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_2bp_3_io_2parse_newick(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_data) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("parse_newick", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = __pyx_f_2bp_3_io_parse_newick(__pyx_v_data, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 141, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("bp._io.parse_newick", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
 142:     cdef:
 143:         np.uint32_t ptr, open_ptr
 144:         Py_ssize_t token_ptr, tmp, lag, datalen
 145:         BP topology
 146:         unicode token, last_token
 147:         np.ndarray[object, ndim=1] names
 148:         np.ndarray[np.double_t, ndim=1] lengths
 149:         np.ndarray[np.int32_t, ndim=1] edges
 150: 
+151:     if data.count(',') == 0:
  if (unlikely(__pyx_v_data == Py_None)) {
    PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "count");
    __PYX_ERR(0, 151, __pyx_L1_error)
  }
  __pyx_t_1 = PyUnicode_Count(__pyx_v_data, __pyx_kp_s__9, 0, PY_SSIZE_T_MAX); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(0, 151, __pyx_L1_error)
  __pyx_t_2 = PyInt_FromSsize_t(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 151, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyInt_EqObjC(__pyx_t_2, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 151, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 151, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (unlikely(__pyx_t_4)) {
/* … */
  }
+152:         raise ValueError("Only trees with more than 1 node supported")
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__12, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 152, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(0, 152, __pyx_L1_error)
/* … */
  __pyx_tuple__12 = PyTuple_Pack(1, __pyx_kp_s_Only_trees_with_more_than_1_node); if (unlikely(!__pyx_tuple__12)) __PYX_ERR(0, 152, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__12);
  __Pyx_GIVEREF(__pyx_tuple__12);
 153: 
+154:     data = data.strip()
  __pyx_t_3 = __Pyx_CallUnboundCMethod0(&__pyx_umethod_PyUnicode_Type_strip, __pyx_v_data); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 154, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (!(likely(PyUnicode_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_3)->tp_name), 0))) __PYX_ERR(0, 154, __pyx_L1_error)
  __Pyx_DECREF_SET(__pyx_v_data, ((PyObject*)__pyx_t_3));
  __pyx_t_3 = 0;
+155:     if not data.endswith(';'):
  if (unlikely(__pyx_v_data == Py_None)) {
    PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "endswith");
    __PYX_ERR(0, 155, __pyx_L1_error)
  }
  __pyx_t_4 = __Pyx_PyUnicode_Tailmatch(__pyx_v_data, __pyx_kp_s__8, 0, PY_SSIZE_T_MAX, 1); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 155, __pyx_L1_error)
  __pyx_t_5 = ((!(__pyx_t_4 != 0)) != 0);
  if (unlikely(__pyx_t_5)) {
/* … */
  }
+156:         raise ValueError("Newick does not appear terminated with a semicolon")
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__13, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 156, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(0, 156, __pyx_L1_error)
/* … */
  __pyx_tuple__13 = PyTuple_Pack(1, __pyx_kp_s_Newick_does_not_appear_terminate); if (unlikely(!__pyx_tuple__13)) __PYX_ERR(0, 156, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__13);
  __Pyx_GIVEREF(__pyx_tuple__13);
 157: 
+158:     datalen = len(data)
  if (unlikely(__pyx_v_data == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
    __PYX_ERR(0, 158, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_PyUnicode_GET_LENGTH(__pyx_v_data); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(0, 158, __pyx_L1_error)
  __pyx_v_datalen = __pyx_t_1;
+159:     topology = _newick_to_bp(data)
  __pyx_t_3 = __pyx_f_2bp_3_io__newick_to_bp(__pyx_v_data); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 159, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (!(likely(((__pyx_t_3) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_3, __pyx_ptype_2bp_3_bp_BP))))) __PYX_ERR(0, 159, __pyx_L1_error)
  __pyx_v_topology = ((struct __pyx_obj_2bp_3_bp_BP *)__pyx_t_3);
  __pyx_t_3 = 0;
 160: 
+161:     names = np.full(len(topology.B), None, dtype=object)
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 161, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_full); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 161, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = ((PyObject *)__pyx_v_topology->B);
  __Pyx_INCREF(__pyx_t_3);
  __pyx_t_1 = PyObject_Length(__pyx_t_3); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(0, 161, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = PyInt_FromSsize_t(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 161, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 161, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_3);
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  PyTuple_SET_ITEM(__pyx_t_6, 1, Py_None);
  __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 161, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_dtype, __pyx_builtin_object) < 0) __PYX_ERR(0, 161, __pyx_L1_error)
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, __pyx_t_3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 161, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!(likely(((__pyx_t_7) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_7, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 161, __pyx_L1_error)
  __pyx_t_8 = ((PyArrayObject *)__pyx_t_7);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_names.rcbuffer->pybuffer);
    __pyx_t_9 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_names.rcbuffer->pybuffer, (PyObject*)__pyx_t_8, &__Pyx_TypeInfo_object, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_9 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_11, &__pyx_t_12);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_names.rcbuffer->pybuffer, (PyObject*)__pyx_v_names, &__Pyx_TypeInfo_object, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_11); Py_XDECREF(__pyx_t_12);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_11, __pyx_t_12);
      }
      __pyx_t_10 = __pyx_t_11 = __pyx_t_12 = 0;
    }
    __pyx_pybuffernd_names.diminfo[0].strides = __pyx_pybuffernd_names.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_names.diminfo[0].shape = __pyx_pybuffernd_names.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 161, __pyx_L1_error)
  }
  __pyx_t_8 = 0;
  __pyx_v_names = ((PyArrayObject *)__pyx_t_7);
  __pyx_t_7 = 0;
+162:     lengths = np.zeros(len(topology.B), dtype=np.double)
  __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_np); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 162, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_zeros); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 162, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = ((PyObject *)__pyx_v_topology->B);
  __Pyx_INCREF(__pyx_t_7);
  __pyx_t_1 = PyObject_Length(__pyx_t_7); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(0, 162, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_7 = PyInt_FromSsize_t(__pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 162, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 162, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7);
  __pyx_t_7 = 0;
  __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 162, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 162, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_double); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 162, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_13);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_dtype, __pyx_t_13) < 0) __PYX_ERR(0, 162, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
  __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 162, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_13);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  if (!(likely(((__pyx_t_13) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_13, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 162, __pyx_L1_error)
  __pyx_t_14 = ((PyArrayObject *)__pyx_t_13);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_lengths.rcbuffer->pybuffer);
    __pyx_t_9 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_lengths.rcbuffer->pybuffer, (PyObject*)__pyx_t_14, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_9 < 0)) {
      PyErr_Fetch(&__pyx_t_12, &__pyx_t_11, &__pyx_t_10);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_lengths.rcbuffer->pybuffer, (PyObject*)__pyx_v_lengths, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_12); Py_XDECREF(__pyx_t_11); Py_XDECREF(__pyx_t_10);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_12, __pyx_t_11, __pyx_t_10);
      }
      __pyx_t_12 = __pyx_t_11 = __pyx_t_10 = 0;
    }
    __pyx_pybuffernd_lengths.diminfo[0].strides = __pyx_pybuffernd_lengths.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_lengths.diminfo[0].shape = __pyx_pybuffernd_lengths.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 162, __pyx_L1_error)
  }
  __pyx_t_14 = 0;
  __pyx_v_lengths = ((PyArrayObject *)__pyx_t_13);
  __pyx_t_13 = 0;
+163:     edges = np.full(len(topology.B), 0, dtype=np.int32)
  __Pyx_GetModuleGlobalName(__pyx_t_13, __pyx_n_s_np); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 163, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_13);
  __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_n_s_full); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 163, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
  __pyx_t_13 = ((PyObject *)__pyx_v_topology->B);
  __Pyx_INCREF(__pyx_t_13);
  __pyx_t_1 = PyObject_Length(__pyx_t_13); if (unlikely(__pyx_t_1 == ((Py_ssize_t)-1))) __PYX_ERR(0, 163, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
  __pyx_t_13 = PyInt_FromSsize_t(__pyx_t_1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 163, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_13);
  __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 163, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_GIVEREF(__pyx_t_13);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_13);
  __Pyx_INCREF(__pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_int_0);
  __pyx_t_13 = 0;
  __pyx_t_13 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 163, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_13);
  __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_np); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 163, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_int32); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 163, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (PyDict_SetItem(__pyx_t_13, __pyx_n_s_dtype, __pyx_t_2) < 0) __PYX_ERR(0, 163, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_6, __pyx_t_13); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 163, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
  if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 163, __pyx_L1_error)
  __pyx_t_15 = ((PyArrayObject *)__pyx_t_2);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_edges.rcbuffer->pybuffer);
    __pyx_t_9 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_edges.rcbuffer->pybuffer, (PyObject*)__pyx_t_15, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_9 < 0)) {
      PyErr_Fetch(&__pyx_t_10, &__pyx_t_11, &__pyx_t_12);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_edges.rcbuffer->pybuffer, (PyObject*)__pyx_v_edges, &__Pyx_TypeInfo_nn___pyx_t_5numpy_int32_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_11); Py_XDECREF(__pyx_t_12);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_10, __pyx_t_11, __pyx_t_12);
      }
      __pyx_t_10 = __pyx_t_11 = __pyx_t_12 = 0;
    }
    __pyx_pybuffernd_edges.diminfo[0].strides = __pyx_pybuffernd_edges.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_edges.diminfo[0].shape = __pyx_pybuffernd_edges.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 163, __pyx_L1_error)
  }
  __pyx_t_15 = 0;
  __pyx_v_edges = ((PyArrayObject *)__pyx_t_2);
  __pyx_t_2 = 0;
 164: 
+165:     ptr = 0
  __pyx_v_ptr = 0;
+166:     token_ptr = _ctoken(data, datalen, 0)
  __pyx_v_token_ptr = __pyx_f_2bp_3_io__ctoken(__pyx_v_data, __pyx_v_datalen, 0);
+167:     token = data[0:token_ptr]
  if (unlikely(__pyx_v_data == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 167, __pyx_L1_error)
  }
  __pyx_t_2 = __Pyx_PyUnicode_Substring(__pyx_v_data, 0, __pyx_v_token_ptr); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 167, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_v_token = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;
+168:     last_token = None
  __Pyx_INCREF(Py_None);
  __pyx_v_last_token = ((PyObject*)Py_None);
 169: 
 170:     # lag reflects the scenario where ((x))y, where the label y gets may end
 171:     # up being associated with an earlier unnamed vertex. lag represents the
 172:     # offset between the topology pointer and the token pointer effectively.
+173:     lag = 0
  __pyx_v_lag = 0;
+174:     while token != ';':
  while (1) {
    __pyx_t_5 = (__Pyx_PyUnicode_Equals(__pyx_v_token, __pyx_kp_s__8, Py_NE)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 174, __pyx_L1_error)
    __pyx_t_4 = (__pyx_t_5 != 0);
    if (!__pyx_t_4) break;
+175:         if token == '(':
    __pyx_t_4 = (__Pyx_PyUnicode_Equals(__pyx_v_token, __pyx_kp_s__7, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 175, __pyx_L1_error)
    __pyx_t_5 = (__pyx_t_4 != 0);
    if (__pyx_t_5) {
/* … */
    }
 176:             # an open parenthesis never has metadata associated with it
+177:             ptr += 1
      __pyx_v_ptr = (__pyx_v_ptr + 1);
 178: 
+179:         if (token == ')' or token == ',') and last_token == ')':
    __pyx_t_4 = (__Pyx_PyUnicode_Equals(__pyx_v_token, __pyx_kp_s__10, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 179, __pyx_L1_error)
    __pyx_t_16 = (__pyx_t_4 != 0);
    if (!__pyx_t_16) {
    } else {
      goto __pyx_L10_next_and;
    }
    __pyx_t_16 = (__Pyx_PyUnicode_Equals(__pyx_v_token, __pyx_kp_s__9, Py_EQ)); if (unlikely(__pyx_t_16 < 0)) __PYX_ERR(0, 179, __pyx_L1_error)
    __pyx_t_4 = (__pyx_t_16 != 0);
    if (__pyx_t_4) {
    } else {
      __pyx_t_5 = __pyx_t_4;
      goto __pyx_L9_bool_binop_done;
    }
    __pyx_L10_next_and:;
    __pyx_t_4 = (__Pyx_PyUnicode_Equals(__pyx_v_last_token, __pyx_kp_s__10, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 179, __pyx_L1_error)
    __pyx_t_16 = (__pyx_t_4 != 0);
    __pyx_t_5 = __pyx_t_16;
    __pyx_L9_bool_binop_done:;
    if (__pyx_t_5) {
/* … */
      goto __pyx_L8;
    }
 180:             # determine if there are unnamed/unlengthed nodes 
+181:             lag += 1
      __pyx_v_lag = (__pyx_v_lag + 1);
 182: 
+183:         elif token not in '(),:;':
    __pyx_t_5 = (__Pyx_PySequence_ContainsTF(__pyx_v_token, __pyx_kp_s__14, Py_NE)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 183, __pyx_L1_error)
    __pyx_t_16 = (__pyx_t_5 != 0);
    if (__pyx_t_16) {
/* … */
    }
    __pyx_L8:;
+184:             ptr += lag
      __pyx_v_ptr = (__pyx_v_ptr + __pyx_v_lag);
+185:             lag = 0
      __pyx_v_lag = 0;
 186: 
+187:             open_ptr = topology.open(ptr)
      __pyx_v_open_ptr = ((struct __pyx_vtabstruct_2bp_3_bp_BP *)__pyx_v_topology->__pyx_vtab)->open(__pyx_v_topology, __pyx_v_ptr);
+188:             _set_node_metadata(open_ptr, token, names, lengths, edges)
      __pyx_f_2bp_3_io__set_node_metadata(__pyx_v_open_ptr, __pyx_v_token, ((PyArrayObject *)__pyx_v_names), ((PyArrayObject *)__pyx_v_lengths), ((PyArrayObject *)__pyx_v_edges));
 189: 
+190:             if topology.isleaf(ptr):
      __pyx_t_16 = (((struct __pyx_vtabstruct_2bp_3_bp_BP *)__pyx_v_topology->__pyx_vtab)->isleaf(__pyx_v_topology, __pyx_v_ptr, 0) != 0);
      if (__pyx_t_16) {
/* … */
        goto __pyx_L12;
      }
+191:                 ptr += 2
        __pyx_v_ptr = (__pyx_v_ptr + 2);
 192:             else:
+193:                 ptr += 1
      /*else*/ {
        __pyx_v_ptr = (__pyx_v_ptr + 1);
      }
      __pyx_L12:;
 194: 
+195:         last_token = token
    __Pyx_INCREF(__pyx_v_token);
    __Pyx_DECREF_SET(__pyx_v_last_token, __pyx_v_token);
+196:         tmp = _ctoken(data, datalen, token_ptr)
    __pyx_v_tmp = __pyx_f_2bp_3_io__ctoken(__pyx_v_data, __pyx_v_datalen, __pyx_v_token_ptr);
+197:         token = data[token_ptr:tmp]
    if (unlikely(__pyx_v_data == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 197, __pyx_L1_error)
    }
    __pyx_t_2 = __Pyx_PyUnicode_Substring(__pyx_v_data, __pyx_v_token_ptr, __pyx_v_tmp); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 197, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF_SET(__pyx_v_token, ((PyObject*)__pyx_t_2));
    __pyx_t_2 = 0;
+198:         token_ptr = tmp
    __pyx_v_token_ptr = __pyx_v_tmp;
  }
 199: 
+200:     topology.set_names(names)
  __pyx_t_13 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_topology), __pyx_n_s_set_names); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 200, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_13);
  __pyx_t_6 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_13))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_13);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_13, function);
    }
  }
  __pyx_t_2 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_13, __pyx_t_6, ((PyObject *)__pyx_v_names)) : __Pyx_PyObject_CallOneArg(__pyx_t_13, ((PyObject *)__pyx_v_names));
  __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 200, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+201:     topology.set_lengths(lengths)
  __pyx_t_13 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_topology), __pyx_n_s_set_lengths); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 201, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_13);
  __pyx_t_6 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_13))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_13);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_13, function);
    }
  }
  __pyx_t_2 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_13, __pyx_t_6, ((PyObject *)__pyx_v_lengths)) : __Pyx_PyObject_CallOneArg(__pyx_t_13, ((PyObject *)__pyx_v_lengths));
  __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 201, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+202:     topology.set_edges(edges)
  __pyx_t_13 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_topology), __pyx_n_s_set_edges); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 202, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_13);
  __pyx_t_6 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_13))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_13);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_13, function);
    }
  }
  __pyx_t_2 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_13, __pyx_t_6, ((PyObject *)__pyx_v_edges)) : __Pyx_PyObject_CallOneArg(__pyx_t_13, ((PyObject *)__pyx_v_edges));
  __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 202, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
 203: 
+204:     return topology
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(((PyObject *)__pyx_v_topology));
  __pyx_r = ((PyObject *)__pyx_v_topology);
  goto __pyx_L0;
 205: 
 206: 
+207: cdef object _newick_to_bp(unicode data):
static PyObject *__pyx_f_2bp_3_io__newick_to_bp(PyObject *__pyx_v_data) {
  Py_ssize_t __pyx_v_i;
  Py_ssize_t __pyx_v_topology_ptr;
  Py_UCS4 __pyx_v_c;
  Py_UCS4 __pyx_v_last_c;
  PyArrayObject *__pyx_v_topology = 0;
  int __pyx_v_potential_single_descendant;
  int __pyx_v_in_quote;
  __Pyx_LocalBuf_ND __pyx_pybuffernd_topology;
  __Pyx_Buffer __pyx_pybuffer_topology;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_newick_to_bp", 0);
  __pyx_pybuffer_topology.pybuffer.buf = NULL;
  __pyx_pybuffer_topology.refcount = 0;
  __pyx_pybuffernd_topology.data = NULL;
  __pyx_pybuffernd_topology.rcbuffer = &__pyx_pybuffer_topology;
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  { PyObject *__pyx_type, *__pyx_value, *__pyx_tb;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb);
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_topology.rcbuffer->pybuffer);
  __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);}
  __Pyx_AddTraceback("bp._io._newick_to_bp", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  goto __pyx_L2;
  __pyx_L0:;
  __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_topology.rcbuffer->pybuffer);
  __pyx_L2:;
  __Pyx_XDECREF((PyObject *)__pyx_v_topology);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
 208:     """Convert newick to balanced parentheses
 209: 
 210:     Newick is _similar_ to BP, but differs notably at the tips of the tree.
 211:     The complexity of the parse below comes from handling tips, and single
 212:     descendents. Examples of situations that introduce this complexity are:
 213: 
 214:     ((a,b)) -> 11101000
 215:     (a) -> 1100
 216:     () -> 1100
 217:     ((a,b),c) -> 1110100100
 218:     (a,(b,c)) -> 1101101000
 219: 
 220:     Newick is not required to have node labels on tips, and the interpretation
 221:     of a comma is dependent on prior state.
 222: 
 223:     The strategy undertaken is to reduce the newick string to only structural
 224:     components. From there, the string is interpreted into tokens of: {"1",
 225:     "0", "10", "100"}, which directly translate into the resulting balanced
 226:     parentheses topology.
 227: 
 228:     It is very likely the case that this parser can be done better with
 229:     improved efficiency.
 230:     """
 231:     cdef:
 232:         Py_ssize_t i, topology_ptr, single_descendent
 233:         Py_UCS4 c, last_c
 234:         np.ndarray[np.uint8_t, ndim=1] topology
 235: 
+236:     potential_single_descendant = False
  __pyx_v_potential_single_descendant = 0;
 237: 
+238:     topology = np.empty(len(data), dtype=np.uint8)
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_np); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 238, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_empty); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 238, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (unlikely(__pyx_v_data == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
    __PYX_ERR(0, 238, __pyx_L1_error)
  }
  __pyx_t_3 = __Pyx_PyUnicode_GET_LENGTH(__pyx_v_data); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(0, 238, __pyx_L1_error)
  __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 238, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 238, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 238, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_np); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 238, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_uint8); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 238, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_dtype, __pyx_t_6) < 0) __PYX_ERR(0, 238, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 238, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_5numpy_ndarray))))) __PYX_ERR(0, 238, __pyx_L1_error)
  __pyx_t_7 = ((PyArrayObject *)__pyx_t_6);
  {
    __Pyx_BufFmt_StackElem __pyx_stack[1];
    __Pyx_SafeReleaseBuffer(&__pyx_pybuffernd_topology.rcbuffer->pybuffer);
    __pyx_t_8 = __Pyx_GetBufferAndValidate(&__pyx_pybuffernd_topology.rcbuffer->pybuffer, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint8_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack);
    if (unlikely(__pyx_t_8 < 0)) {
      PyErr_Fetch(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11);
      if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_pybuffernd_topology.rcbuffer->pybuffer, (PyObject*)__pyx_v_topology, &__Pyx_TypeInfo_nn___pyx_t_5numpy_uint8_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) {
        Py_XDECREF(__pyx_t_9); Py_XDECREF(__pyx_t_10); Py_XDECREF(__pyx_t_11);
        __Pyx_RaiseBufferFallbackError();
      } else {
        PyErr_Restore(__pyx_t_9, __pyx_t_10, __pyx_t_11);
      }
      __pyx_t_9 = __pyx_t_10 = __pyx_t_11 = 0;
    }
    __pyx_pybuffernd_topology.diminfo[0].strides = __pyx_pybuffernd_topology.rcbuffer->pybuffer.strides[0]; __pyx_pybuffernd_topology.diminfo[0].shape = __pyx_pybuffernd_topology.rcbuffer->pybuffer.shape[0];
    if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 238, __pyx_L1_error)
  }
  __pyx_t_7 = 0;
  __pyx_v_topology = ((PyArrayObject *)__pyx_t_6);
  __pyx_t_6 = 0;
+239:     topology_ptr = 0
  __pyx_v_topology_ptr = 0;
+240:     last_c = u'x'
  __pyx_v_last_c = 0x78;
+241:     in_quote = False
  __pyx_v_in_quote = 0;
 242: 
+243:     for i in range(len(data)):
  if (unlikely(__pyx_v_data == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
    __PYX_ERR(0, 243, __pyx_L1_error)
  }
  __pyx_t_3 = __Pyx_PyUnicode_GET_LENGTH(__pyx_v_data); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(0, 243, __pyx_L1_error)
  __pyx_t_12 = __pyx_t_3;
  for (__pyx_t_13 = 0; __pyx_t_13 < __pyx_t_12; __pyx_t_13+=1) {
    __pyx_v_i = __pyx_t_13;
+244:         c = data[i]
    __pyx_t_14 = __Pyx_GetItemInt_Unicode(__pyx_v_data, __pyx_v_i, Py_ssize_t, 1, PyInt_FromSsize_t, 0, 0, 0); if (unlikely(__pyx_t_14 == (Py_UCS4)-1)) __PYX_ERR(0, 244, __pyx_L1_error)
    __pyx_v_c = __pyx_t_14;
+245:         if c == u"'":
    __pyx_t_15 = ((__pyx_v_c == 39) != 0);
    if (__pyx_t_15) {
/* … */
      goto __pyx_L5;
    }
+246:             in_quote = not in_quote
      __pyx_v_in_quote = (!(__pyx_v_in_quote != 0));
 247:         else:
+248:             if in_quote:
    /*else*/ {
      __pyx_t_15 = (__pyx_v_in_quote != 0);
      if (__pyx_t_15) {
/* … */
      }
+249:                 continue
        goto __pyx_L3_continue;
+250:             elif c == u'(':
      __pyx_t_15 = ((__pyx_v_c == 40) != 0);
      if (__pyx_t_15) {
/* … */
        goto __pyx_L6;
      }
 251:                 # opening of a node
+252:                 topology[topology_ptr] = 1
        __pyx_t_16 = __pyx_v_topology_ptr;
        *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_uint8_t *, __pyx_pybuffernd_topology.rcbuffer->pybuffer.buf, __pyx_t_16, __pyx_pybuffernd_topology.diminfo[0].strides) = 1;
+253:                 topology_ptr += 1
        __pyx_v_topology_ptr = (__pyx_v_topology_ptr + 1);
+254:                 last_c = c
        __pyx_v_last_c = __pyx_v_c;
+255:                 potential_single_descendant = True
        __pyx_v_potential_single_descendant = 1;
+256:             elif c == u')':
      __pyx_t_15 = ((__pyx_v_c == 41) != 0);
      if (__pyx_t_15) {
/* … */
        goto __pyx_L6;
      }
 257:                 # closing of a node
+258:                 if potential_single_descendant or last_c == u',':
        __pyx_t_17 = (__pyx_v_potential_single_descendant != 0);
        if (!__pyx_t_17) {
        } else {
          __pyx_t_15 = __pyx_t_17;
          goto __pyx_L8_bool_binop_done;
        }
        __pyx_t_17 = ((__pyx_v_last_c == 44) != 0);
        __pyx_t_15 = __pyx_t_17;
        __pyx_L8_bool_binop_done:;
        if (__pyx_t_15) {
/* … */
          goto __pyx_L7;
        }
 259:                     # we have a single descendant or a last child (i.e., ",)")
+260:                     topology[topology_ptr] = 1
          __pyx_t_16 = __pyx_v_topology_ptr;
          *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_uint8_t *, __pyx_pybuffernd_topology.rcbuffer->pybuffer.buf, __pyx_t_16, __pyx_pybuffernd_topology.diminfo[0].strides) = 1;
+261:                     topology[topology_ptr + 1] = 0
          __pyx_t_16 = (__pyx_v_topology_ptr + 1);
          *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_uint8_t *, __pyx_pybuffernd_topology.rcbuffer->pybuffer.buf, __pyx_t_16, __pyx_pybuffernd_topology.diminfo[0].strides) = 0;
+262:                     topology[topology_ptr + 2] = 0
          __pyx_t_16 = (__pyx_v_topology_ptr + 2);
          *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_uint8_t *, __pyx_pybuffernd_topology.rcbuffer->pybuffer.buf, __pyx_t_16, __pyx_pybuffernd_topology.diminfo[0].strides) = 0;
+263:                     topology_ptr += 3
          __pyx_v_topology_ptr = (__pyx_v_topology_ptr + 3);
+264:                     potential_single_descendant = False
          __pyx_v_potential_single_descendant = 0;
 265:                 else:
 266:                     # it is possible to still have a single descendant in the case
 267:                     # of a multiple single descendant: (...()...)
+268:                     topology[topology_ptr] = 0
        /*else*/ {
          __pyx_t_16 = __pyx_v_topology_ptr;
          *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_uint8_t *, __pyx_pybuffernd_topology.rcbuffer->pybuffer.buf, __pyx_t_16, __pyx_pybuffernd_topology.diminfo[0].strides) = 0;
+269:                     topology_ptr += 1
          __pyx_v_topology_ptr = (__pyx_v_topology_ptr + 1);
        }
        __pyx_L7:;
+270:                 last_c = c
        __pyx_v_last_c = __pyx_v_c;
+271:             elif c == u',':
      __pyx_t_15 = ((__pyx_v_c == 44) != 0);
      if (__pyx_t_15) {
/* … */
        goto __pyx_L6;
      }
+272:                 if last_c != u')':
        __pyx_t_15 = ((__pyx_v_last_c != 41) != 0);
        if (__pyx_t_15) {
/* … */
        }
 273:                     # we have a new tip
+274:                     topology[topology_ptr] = 1
          __pyx_t_16 = __pyx_v_topology_ptr;
          *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_uint8_t *, __pyx_pybuffernd_topology.rcbuffer->pybuffer.buf, __pyx_t_16, __pyx_pybuffernd_topology.diminfo[0].strides) = 1;
+275:                     topology[topology_ptr + 1] = 0
          __pyx_t_16 = (__pyx_v_topology_ptr + 1);
          *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_uint8_t *, __pyx_pybuffernd_topology.rcbuffer->pybuffer.buf, __pyx_t_16, __pyx_pybuffernd_topology.diminfo[0].strides) = 0;
+276:                     topology_ptr += 2
          __pyx_v_topology_ptr = (__pyx_v_topology_ptr + 2);
+277:                 potential_single_descendant = False
        __pyx_v_potential_single_descendant = 0;
+278:                 last_c = c
        __pyx_v_last_c = __pyx_v_c;
 279:             else:
 280:                 # ignore non-structure
+281:                 pass
      /*else*/ {
      }
      __pyx_L6:;
    }
    __pyx_L5:;
    __pyx_L3_continue:;
  }
 282: 
+283:     return BP(topology[:topology_ptr])
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_6 = PyInt_FromSsize_t(__pyx_v_topology_ptr); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 283, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_1 = PySlice_New(Py_None, __pyx_t_6, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 283, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_t_6 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_topology), __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 283, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_2bp_3_bp_BP), __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 283, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;
 284: 
 285: 
+286: cdef inline int _ccheck(Py_UCS4 c):
static CYTHON_INLINE int __pyx_f_2bp_3_io__ccheck(Py_UCS4 __pyx_v_c) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_ccheck", 0);
/* … */
  /* function exit code */
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
 287:     """structure check"""
 288:     cdef:
 289:         Py_ssize_t i
 290: 
+291:     if c == u'(':
  switch (__pyx_v_c) {
    case 40:
/* … */
    break;
    case 41:
+292:         return 1
    __pyx_r = 1;
    goto __pyx_L0;
+293:     elif c == u')':
    break;
    case 44:
+294:         return 1
    __pyx_r = 1;
    goto __pyx_L0;
+295:     elif c == u',':
    break;
    case 59:
+296:         return 1
    __pyx_r = 1;
    goto __pyx_L0;
+297:     elif c == u';':
    break;
    default:
+298:         return 1
    __pyx_r = 1;
    goto __pyx_L0;
 299:     else:
+300:         return 0
    __pyx_r = 0;
    goto __pyx_L0;
    break;
  }
 301: 
 302: 
+303: cdef inline int _is_quote(Py_UCS4 c):
static CYTHON_INLINE int __pyx_f_2bp_3_io__is_quote(Py_UCS4 __pyx_v_c) {
  int __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_is_quote", 0);
/* … */
  /* function exit code */
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
+304:     if c == u'"':
  switch (__pyx_v_c) {
    case 34:
/* … */
    break;
    case 39:
+305:         return 1
    __pyx_r = 1;
    goto __pyx_L0;
+306:     elif c == u"'":
    break;
    default:
+307:         return 1
    __pyx_r = 1;
    goto __pyx_L0;
 308:     else:
+309:         return 0
    __pyx_r = 0;
    goto __pyx_L0;
    break;
  }
 310: 
 311: 
+312: cdef inline Py_ssize_t _ctoken(unicode data, Py_ssize_t datalen, Py_ssize_t start):
static CYTHON_INLINE Py_ssize_t __pyx_f_2bp_3_io__ctoken(PyObject *__pyx_v_data, Py_ssize_t __pyx_v_datalen, Py_ssize_t __pyx_v_start) {
  Py_ssize_t __pyx_v_idx;
  Py_ssize_t __pyx_v_in_quote;
  Py_UCS4 __pyx_v_c;
  Py_ssize_t __pyx_r;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("_ctoken", 0);
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_WriteUnraisable("bp._io._ctoken", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
 313:     cdef:
+314:         Py_ssize_t idx, in_quote = 0
  __pyx_v_in_quote = 0;
 315:         Py_UCS4 c
 316: 
+317:     if start == (datalen - 1):
  __pyx_t_1 = ((__pyx_v_start == (__pyx_v_datalen - 1)) != 0);
  if (__pyx_t_1) {
/* … */
  }
+318:         return start + 1
    __pyx_r = (__pyx_v_start + 1);
    goto __pyx_L0;
 319: 
+320:     for idx in range(start, datalen):
  __pyx_t_2 = __pyx_v_datalen;
  __pyx_t_3 = __pyx_t_2;
  for (__pyx_t_4 = __pyx_v_start; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
    __pyx_v_idx = __pyx_t_4;
+321:         c = data[idx]
    __pyx_t_5 = __Pyx_GetItemInt_Unicode(__pyx_v_data, __pyx_v_idx, Py_ssize_t, 1, PyInt_FromSsize_t, 0, 0, 0); if (unlikely(__pyx_t_5 == (Py_UCS4)-1)) __PYX_ERR(0, 321, __pyx_L1_error)
    __pyx_v_c = __pyx_t_5;
 322: 
+323:         if in_quote:
    __pyx_t_1 = (__pyx_v_in_quote != 0);
    if (__pyx_t_1) {
/* … */
    }
+324:             if _is_quote(c):
      __pyx_t_1 = (__pyx_f_2bp_3_io__is_quote(__pyx_v_c) != 0);
      if (__pyx_t_1) {
/* … */
      }
+325:                 in_quote = 0
        __pyx_v_in_quote = 0;
+326:             continue
      goto __pyx_L4_continue;
 327:         else:
+328:             if _is_quote(c):
    /*else*/ {
      __pyx_t_1 = (__pyx_f_2bp_3_io__is_quote(__pyx_v_c) != 0);
      if (__pyx_t_1) {
/* … */
      }
    }
+329:                 in_quote = 1
        __pyx_v_in_quote = 1;
+330:                 continue
        goto __pyx_L4_continue;
 331: 
+332:         if _ccheck(c):
    __pyx_t_1 = (__pyx_f_2bp_3_io__ccheck(__pyx_v_c) != 0);
    if (__pyx_t_1) {
/* … */
    }
    __pyx_L4_continue:;
  }
+333:             if idx == start:
      __pyx_t_1 = ((__pyx_v_idx == __pyx_v_start) != 0);
      if (__pyx_t_1) {
/* … */
      }
+334:                 return idx + 1
        __pyx_r = (__pyx_v_idx + 1);
        goto __pyx_L0;
 335:             else:
+336:                 return idx
      /*else*/ {
        __pyx_r = __pyx_v_idx;
        goto __pyx_L0;
      }
 337: 
+338:     return idx + 1
  __pyx_r = (__pyx_v_idx + 1);
  goto __pyx_L0;
 339: 
 340: 
+341: def parse_jplace(object data):
/* Python wrapper */
static PyObject *__pyx_pw_2bp_3_io_5parse_jplace(PyObject *__pyx_self, PyObject *__pyx_v_data); /*proto*/
static char __pyx_doc_2bp_3_io_4parse_jplace[] = "Takes a jplace string, returns a DataFrame of placements and the tree\n\n    Implementation specific caveats:\n\n    1) we do not support multiplicities. placements are required to have an \"n\"\n        entry, and we ignore \"nm\"\n    2) Matsen et al (https://journals.plos.org/plosone/article?id=10.1371/journal.pone.0031009) \n        define [] for denoting edge labels and {} for denoting edge numbers. We\n        currently support either [] OR {}, we do not support edges with both.\n        In addition, we REQUIRE the edge labels if specified to be integer.\n\n    If either of these caveats are problems, then we need to modify the code.\n    ";
static PyMethodDef __pyx_mdef_2bp_3_io_5parse_jplace = {"parse_jplace", (PyCFunction)__pyx_pw_2bp_3_io_5parse_jplace, METH_O, __pyx_doc_2bp_3_io_4parse_jplace};
static PyObject *__pyx_pw_2bp_3_io_5parse_jplace(PyObject *__pyx_self, PyObject *__pyx_v_data) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("parse_jplace (wrapper)", 0);
  __pyx_r = __pyx_pf_2bp_3_io_4parse_jplace(__pyx_self, ((PyObject *)__pyx_v_data));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_2bp_3_io_4parse_jplace(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_data) {
  PyObject *__pyx_v_as_json = 0;
  PyObject *__pyx_v_fields = 0;
  PyObject *__pyx_v_placements = 0;
  PyObject *__pyx_v_fragments = 0;
  PyObject *__pyx_v_placement_data = 0;
  PyObject *__pyx_v_placement_inner_data = 0;
  PyObject *__pyx_v_pquery = 0;
  PyObject *__pyx_v_entry = 0;
  PyObject *__pyx_v_frag = 0;
  PyObject *__pyx_v_newick = 0;
  Py_ssize_t __pyx_v_placement_idx;
  Py_ssize_t __pyx_v_placement_inner_idx;
  Py_ssize_t __pyx_v_fragment_idx;
  Py_ssize_t __pyx_v_n_fragments;
  struct __pyx_obj_2bp_3_bp_BP *__pyx_v_tree = 0;
  PyObject *__pyx_v_df = 0;
  PyObject *__pyx_v_edges = 0;
  PyObject *__pyx_v_placement = NULL;
  PyObject *__pyx_7genexpr__pyx_v_i = NULL;
  PyObject *__pyx_7genexpr__pyx_v_v = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("parse_jplace", 0);
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_17);
  __Pyx_AddTraceback("bp._io.parse_jplace", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_as_json);
  __Pyx_XDECREF(__pyx_v_fields);
  __Pyx_XDECREF(__pyx_v_placements);
  __Pyx_XDECREF(__pyx_v_fragments);
  __Pyx_XDECREF(__pyx_v_placement_data);
  __Pyx_XDECREF(__pyx_v_placement_inner_data);
  __Pyx_XDECREF(__pyx_v_pquery);
  __Pyx_XDECREF(__pyx_v_entry);
  __Pyx_XDECREF(__pyx_v_frag);
  __Pyx_XDECREF(__pyx_v_newick);
  __Pyx_XDECREF((PyObject *)__pyx_v_tree);
  __Pyx_XDECREF(__pyx_v_df);
  __Pyx_XDECREF(__pyx_v_edges);
  __Pyx_XDECREF(__pyx_v_placement);
  __Pyx_XDECREF(__pyx_7genexpr__pyx_v_i);
  __Pyx_XDECREF(__pyx_7genexpr__pyx_v_v);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
/* … */
  __pyx_tuple__39 = PyTuple_Pack(22, __pyx_n_s_data, __pyx_n_s_as_json, __pyx_n_s_fields, __pyx_n_s_placements, __pyx_n_s_fragments, __pyx_n_s_p, __pyx_n_s_placement_data, __pyx_n_s_placement_inner_data, __pyx_n_s_pquery, __pyx_n_s_entry, __pyx_n_s_frag, __pyx_n_s_newick, __pyx_n_s_placement_idx, __pyx_n_s_placement_inner_idx, __pyx_n_s_fragment_idx, __pyx_n_s_n_fragments, __pyx_n_s_tree, __pyx_n_s_df, __pyx_n_s_edges, __pyx_n_s_placement, __pyx_n_s_i, __pyx_n_s_v); if (unlikely(!__pyx_tuple__39)) __PYX_ERR(0, 341, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__39);
  __Pyx_GIVEREF(__pyx_tuple__39);
/* … */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_2bp_3_io_5parse_jplace, NULL, __pyx_n_s_bp__io); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 341, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_parse_jplace, __pyx_t_1) < 0) __PYX_ERR(0, 341, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_codeobj__40 = (PyObject*)__Pyx_PyCode_New(1, 0, 22, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__39, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_bp__io_pyx, __pyx_n_s_parse_jplace, 341, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__40)) __PYX_ERR(0, 341, __pyx_L1_error)
 342:     """Takes a jplace string, returns a DataFrame of placements and the tree
 343: 
 344:     Implementation specific caveats:
 345: 
 346:     1) we do not support multiplicities. placements are required to have an "n"
 347:         entry, and we ignore "nm"
 348:     2) Matsen et al (https://journals.plos.org/plosone/article?id=10.1371/journal.pone.0031009) 
 349:         define [] for denoting edge labels and {} for denoting edge numbers. We
 350:         currently support either [] OR {}, we do not support edges with both.
 351:         In addition, we REQUIRE the edge labels if specified to be integer.
 352: 
 353:     If either of these caveats are problems, then we need to modify the code.
 354:     """
 355:     cdef:
 356:         dict as_json
 357:         list fields, placements, fragments, p, placement_data,
 358:         list placement_inner_data, pquery, entry
 359:         unicode frag, newick
 360:         Py_ssize_t placement_idx, placement_inner_idx, fragment_idx,
 361:         Py_ssize_t n_fragments
 362:         BP tree
 363:         object df
 364:         set edges
 365: 
+366:     as_json = json.loads(data)
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_json); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 366, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_loads); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 366, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_2, __pyx_v_data) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_data);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 366, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (!(likely(PyDict_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "dict", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 366, __pyx_L1_error)
  __pyx_v_as_json = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;
+367:     newick = as_json['tree']
  if (unlikely(__pyx_v_as_json == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 367, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_as_json, __pyx_n_s_tree); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 367, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (!(likely(PyUnicode_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 367, __pyx_L1_error)
  __pyx_v_newick = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;
+368:     placement_data = as_json['placements']
  if (unlikely(__pyx_v_as_json == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 368, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_as_json, __pyx_n_s_placements); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 368, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (!(likely(PyList_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 368, __pyx_L1_error)
  __pyx_v_placement_data = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;
 369: 
+370:     fields = as_json['fields']
  if (unlikely(__pyx_v_as_json == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 370, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_as_json, __pyx_n_s_fields); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 370, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (!(likely(PyList_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 370, __pyx_L1_error)
  __pyx_v_fields = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;
+371:     fields = ['fragment', ] + fields
  __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 371, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_n_s_fragment);
  __Pyx_GIVEREF(__pyx_n_s_fragment);
  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_fragment);
  __pyx_t_3 = PyNumber_Add(__pyx_t_1, __pyx_v_fields); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 371, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF_SET(__pyx_v_fields, ((PyObject*)__pyx_t_3));
  __pyx_t_3 = 0;
 372: 
+373:     placements = []
  __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 373, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_v_placements = ((PyObject*)__pyx_t_3);
  __pyx_t_3 = 0;
+374:     for placement_idx in range(len(placement_data)):
  if (unlikely(__pyx_v_placement_data == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
    __PYX_ERR(0, 374, __pyx_L1_error)
  }
  __pyx_t_4 = PyList_GET_SIZE(__pyx_v_placement_data); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 374, __pyx_L1_error)
  __pyx_t_5 = __pyx_t_4;
  for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) {
    __pyx_v_placement_idx = __pyx_t_6;
+375:         placement = placement_data[placement_idx]
    if (unlikely(__pyx_v_placement_data == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 375, __pyx_L1_error)
    }
    __pyx_t_3 = PyList_GET_ITEM(__pyx_v_placement_data, __pyx_v_placement_idx);
    __Pyx_INCREF(__pyx_t_3);
    __Pyx_XDECREF_SET(__pyx_v_placement, __pyx_t_3);
    __pyx_t_3 = 0;
 376: 
+377:         placement_inner_data = placement['p']
    __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_placement, __pyx_n_s_p); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 377, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    if (!(likely(PyList_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_3)->tp_name), 0))) __PYX_ERR(0, 377, __pyx_L1_error)
    __Pyx_XDECREF_SET(__pyx_v_placement_inner_data, ((PyObject*)__pyx_t_3));
    __pyx_t_3 = 0;
 378: 
+379:         if 'n' not in placement:
    __pyx_t_7 = (__Pyx_PySequence_ContainsTF(__pyx_n_s_n, __pyx_v_placement, Py_NE)); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 379, __pyx_L1_error)
    __pyx_t_8 = (__pyx_t_7 != 0);
    if (unlikely(__pyx_t_8)) {
/* … */
    }
+380:             raise KeyError("jplace parsing limited to entries with 'n' keys")
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_KeyError, __pyx_tuple__15, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 380, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_Raise(__pyx_t_3, 0, 0, 0);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __PYX_ERR(0, 380, __pyx_L1_error)
/* … */
  __pyx_tuple__15 = PyTuple_Pack(1, __pyx_kp_s_jplace_parsing_limited_to_entrie); if (unlikely(!__pyx_tuple__15)) __PYX_ERR(0, 380, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__15);
  __Pyx_GIVEREF(__pyx_tuple__15);
 381: 
+382:         fragments = placement['n']
    __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_placement, __pyx_n_s_n); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 382, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    if (!(likely(PyList_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_3)->tp_name), 0))) __PYX_ERR(0, 382, __pyx_L1_error)
    __Pyx_XDECREF_SET(__pyx_v_fragments, ((PyObject*)__pyx_t_3));
    __pyx_t_3 = 0;
+383:         n_fragments = len(fragments)
    if (unlikely(__pyx_v_fragments == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
      __PYX_ERR(0, 383, __pyx_L1_error)
    }
    __pyx_t_9 = PyList_GET_SIZE(__pyx_v_fragments); if (unlikely(__pyx_t_9 == ((Py_ssize_t)-1))) __PYX_ERR(0, 383, __pyx_L1_error)
    __pyx_v_n_fragments = __pyx_t_9;
 384: 
+385:         for placement_inner_idx in range(len(placement_inner_data)):
    if (unlikely(__pyx_v_placement_inner_data == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
      __PYX_ERR(0, 385, __pyx_L1_error)
    }
    __pyx_t_9 = PyList_GET_SIZE(__pyx_v_placement_inner_data); if (unlikely(__pyx_t_9 == ((Py_ssize_t)-1))) __PYX_ERR(0, 385, __pyx_L1_error)
    __pyx_t_10 = __pyx_t_9;
    for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_10; __pyx_t_11+=1) {
      __pyx_v_placement_inner_idx = __pyx_t_11;
+386:             pquery = placement_inner_data[placement_inner_idx]
      if (unlikely(__pyx_v_placement_inner_data == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 386, __pyx_L1_error)
      }
      if (!(likely(PyList_CheckExact(PyList_GET_ITEM(__pyx_v_placement_inner_data, __pyx_v_placement_inner_idx)))||((PyList_GET_ITEM(__pyx_v_placement_inner_data, __pyx_v_placement_inner_idx)) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(PyList_GET_ITEM(__pyx_v_placement_inner_data, __pyx_v_placement_inner_idx))->tp_name), 0))) __PYX_ERR(0, 386, __pyx_L1_error)
      __pyx_t_3 = PyList_GET_ITEM(__pyx_v_placement_inner_data, __pyx_v_placement_inner_idx);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_XDECREF_SET(__pyx_v_pquery, ((PyObject*)__pyx_t_3));
      __pyx_t_3 = 0;
 387: 
+388:             for fragment_idx in range(n_fragments):
      __pyx_t_12 = __pyx_v_n_fragments;
      __pyx_t_13 = __pyx_t_12;
      for (__pyx_t_14 = 0; __pyx_t_14 < __pyx_t_13; __pyx_t_14+=1) {
        __pyx_v_fragment_idx = __pyx_t_14;
+389:                 frag = fragments[fragment_idx]
        if (unlikely(__pyx_v_fragments == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
          __PYX_ERR(0, 389, __pyx_L1_error)
        }
        if (!(likely(PyUnicode_CheckExact(PyList_GET_ITEM(__pyx_v_fragments, __pyx_v_fragment_idx)))||((PyList_GET_ITEM(__pyx_v_fragments, __pyx_v_fragment_idx)) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(PyList_GET_ITEM(__pyx_v_fragments, __pyx_v_fragment_idx))->tp_name), 0))) __PYX_ERR(0, 389, __pyx_L1_error)
        __pyx_t_3 = PyList_GET_ITEM(__pyx_v_fragments, __pyx_v_fragment_idx);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_XDECREF_SET(__pyx_v_frag, ((PyObject*)__pyx_t_3));
        __pyx_t_3 = 0;
+390:                 entry = [frag, ] + pquery
        __pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 390, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_INCREF(__pyx_v_frag);
        __Pyx_GIVEREF(__pyx_v_frag);
        PyList_SET_ITEM(__pyx_t_3, 0, __pyx_v_frag);
        __pyx_t_1 = PyNumber_Add(__pyx_t_3, __pyx_v_pquery); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 390, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_XDECREF_SET(__pyx_v_entry, ((PyObject*)__pyx_t_1));
        __pyx_t_1 = 0;
+391:                 placements.append(entry)
        __pyx_t_15 = __Pyx_PyList_Append(__pyx_v_placements, __pyx_v_entry); if (unlikely(__pyx_t_15 == ((int)-1))) __PYX_ERR(0, 391, __pyx_L1_error)
      }
    }
  }
 392: 
+393:     tree = parse_newick(newick)
  __pyx_t_1 = __pyx_f_2bp_3_io_parse_newick(__pyx_v_newick, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 393, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_2bp_3_bp_BP))))) __PYX_ERR(0, 393, __pyx_L1_error)
  __pyx_v_tree = ((struct __pyx_obj_2bp_3_bp_BP *)__pyx_t_1);
  __pyx_t_1 = 0;
+394:     edges = {tree.edge(i) for i, v in enumerate(tree.B) if v}
  { /* enter inner scope */
    __pyx_t_1 = PySet_New(NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 394, __pyx_L12_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_int_0);
    __pyx_t_3 = __pyx_int_0;
    if (likely(PyList_CheckExact(((PyObject *)__pyx_v_tree->B))) || PyTuple_CheckExact(((PyObject *)__pyx_v_tree->B))) {
      __pyx_t_2 = ((PyObject *)__pyx_v_tree->B); __Pyx_INCREF(__pyx_t_2); __pyx_t_4 = 0;
      __pyx_t_16 = NULL;
    } else {
      __pyx_t_4 = -1; __pyx_t_2 = PyObject_GetIter(((PyObject *)__pyx_v_tree->B)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 394, __pyx_L12_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_16 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 394, __pyx_L12_error)
    }
    for (;;) {
      if (likely(!__pyx_t_16)) {
        if (likely(PyList_CheckExact(__pyx_t_2))) {
          if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_2)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_17 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_17); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 394, __pyx_L12_error)
          #else
          __pyx_t_17 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 394, __pyx_L12_error)
          __Pyx_GOTREF(__pyx_t_17);
          #endif
        } else {
          if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_17 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_17); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 394, __pyx_L12_error)
          #else
          __pyx_t_17 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 394, __pyx_L12_error)
          __Pyx_GOTREF(__pyx_t_17);
          #endif
        }
      } else {
        __pyx_t_17 = __pyx_t_16(__pyx_t_2);
        if (unlikely(!__pyx_t_17)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 394, __pyx_L12_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_17);
      }
      __Pyx_XDECREF_SET(__pyx_7genexpr__pyx_v_v, __pyx_t_17);
      __pyx_t_17 = 0;
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_XDECREF_SET(__pyx_7genexpr__pyx_v_i, __pyx_t_3);
      __pyx_t_17 = __Pyx_PyInt_AddObjC(__pyx_t_3, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 394, __pyx_L12_error)
      __Pyx_GOTREF(__pyx_t_17);
      __Pyx_DECREF(__pyx_t_3);
      __pyx_t_3 = __pyx_t_17;
      __pyx_t_17 = 0;
      __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_7genexpr__pyx_v_v); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 394, __pyx_L12_error)
      if (__pyx_t_8) {
        __pyx_t_18 = __Pyx_PyInt_As_Py_intptr_t(__pyx_7genexpr__pyx_v_i); if (unlikely((__pyx_t_18 == ((npy_intp)-1)) && PyErr_Occurred())) __PYX_ERR(0, 394, __pyx_L12_error)
        __pyx_t_17 = __Pyx_PyInt_From_npy_int32(((struct __pyx_vtabstruct_2bp_3_bp_BP *)__pyx_v_tree->__pyx_vtab)->edge(__pyx_v_tree, __pyx_t_18, 0)); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 394, __pyx_L12_error)
        __Pyx_GOTREF(__pyx_t_17);
        if (unlikely(PySet_Add(__pyx_t_1, (PyObject*)__pyx_t_17))) __PYX_ERR(0, 394, __pyx_L12_error)
        __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
      }
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_XDECREF(__pyx_7genexpr__pyx_v_i); __pyx_7genexpr__pyx_v_i = 0;
    __Pyx_XDECREF(__pyx_7genexpr__pyx_v_v); __pyx_7genexpr__pyx_v_v = 0;
    goto __pyx_L16_exit_scope;
    __pyx_L12_error:;
    __Pyx_XDECREF(__pyx_7genexpr__pyx_v_i); __pyx_7genexpr__pyx_v_i = 0;
    __Pyx_XDECREF(__pyx_7genexpr__pyx_v_v); __pyx_7genexpr__pyx_v_v = 0;
    goto __pyx_L1_error;
    __pyx_L16_exit_scope:;
  } /* exit inner scope */
  __pyx_v_edges = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;
+395:     df = pd.DataFrame(placements, columns=fields)
  __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_pd); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 395, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_DataFrame); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 395, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 395, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_placements);
  __Pyx_GIVEREF(__pyx_v_placements);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_placements);
  __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 395, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_columns, __pyx_v_fields) < 0) __PYX_ERR(0, 395, __pyx_L1_error)
  __pyx_t_17 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 395, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_17);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_df = __pyx_t_17;
  __pyx_t_17 = 0;
+396:     df = df[df['edge_num'].isin(edges)]
  __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_df, __pyx_n_s_edge_num); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 396, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_isin); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 396, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
    }
  }
  __pyx_t_17 = (__pyx_t_2) ? __Pyx_PyObject_Call2Args(__pyx_t_1, __pyx_t_2, __pyx_v_edges) : __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_edges);
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 396, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_17);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_GetItem(__pyx_v_df, __pyx_t_17); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 396, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
  __Pyx_DECREF_SET(__pyx_v_df, __pyx_t_1);
  __pyx_t_1 = 0;
 397: 
+398:     return df, tree
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 398, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_df);
  __Pyx_GIVEREF(__pyx_v_df);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_df);
  __Pyx_INCREF(((PyObject *)__pyx_v_tree));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_tree));
  PyTuple_SET_ITEM(__pyx_t_1, 1, ((PyObject *)__pyx_v_tree));
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;