text: import json
  import networkx as nx
  from pathlib import Path
  from datetime import datetime
  from collections import OrderedDict
  
  
  
  def custom_cat(x, y):
      import torch
      n = y.size(0)
      x = x.reshape(n, -1)
      c = torch.cat((y.view(-1, 1), x), dim=1)
      return c.flatten()
  
  
  def ensure_dir(dirname):
      dirname = Path(dirname)
      if not dirname.is_dir():
          dirname.mkdir(parents=True, exist_ok=False)
  
  def read_json(fname):
      with fname.open('rt') as handle:
          return json.load(handle, object_hook=OrderedDict)
  
  def write_json(content, fname):
      with fname.open('wt') as handle:
          json.dump(content, handle, indent=4, sort_keys=False)
  
  class Timer:
      def __init__(self):
          self.cache = datetime.now()
  
      def check(self):
          now = datetime.now()
          duration = now - self.cache
          self.cache = now
          return duration.total_seconds()
  
      def reset(self):
          self.cache = datetime.now()
  
  class Taxon(object):
      def __init__(self, tx_id, rank=-1, norm_name="none", display_name="None", main_type="", level="-100", p_count=0, c_count=0, create_date="None"):
          self.tx_id = int(tx_id)
          self.rank = int(rank)
          self.norm_name = norm_name
          self.display_name = display_name
          self.main_type = main_type
          self.level = int(level)
          self.p_count = int(p_count)
          self.c_count = int(c_count)
          self.create_date = create_date
          
      def __str__(self):
          return "Taxon {} (name: {}, level: {})".format(self.tx_id, self.norm_name, self.level)
          
      def __lt__(self, another_taxon):
          if self.level < another_taxon.level:
              return True
          else:
              return self.rank < another_taxon.rank
  
  def Taxonomy(object):
      def __init__(self, name="", node_list=[], edge_list=[]):
          self.name = name
          self.taxonomy = nx.DiGraph()
  
      def add_nodes_from(self, node_list):
          self.taxonomy.add_nodes_from(node_list)
  
      def add_edges_from(self, edge_list):
          self.taxonomy.add_edges_from(edge_list)
  