original_docstring: 
      Loads a phylogeny in standards format (in csv or json) from the file
      specified by the filename parameter. Returns the phylogeny as a
      dendropy tree.
  
      Special ancestor values are encoded in an "origin" field within nodes.
      Example: `my_phylogeny.nodes["A"]["origin"]` would return the origin of
      node "A"
      
docstring: Loads a phylogeny in standards format (in csv or json) from the file
  specified by the filename parameter. Returns the phylogeny as a
  dendropy tree.
  
  Special ancestor values are encoded in an "origin" field within nodes.
docstring_tokens: Loads a phylogeny in standards format ( in csv or json ) from the file specified by the filename parameter . Returns the phylogeny as a dendropy tree . Special ancestor values are encoded in an " origin " field within nodes .
code: def load_phylogeny_to_dendropy(filename):
      """
      Loads a phylogeny in standards format (in csv or json) from the file
      specified by the filename parameter. Returns the phylogeny as a
      dendropy tree.
  
      Special ancestor values are encoded in an "origin" field within nodes.
      Example: `my_phylogeny.nodes["A"]["origin"]` would return the origin of
      node "A"
      """
  
      if filename.endswith(".csv"):  # Handle CSV files
          data = pd.read_csv(filename)
          # The ancestor_list column contains a string of lists of strings
          # Let's turn it into an actual list of strings
          data.loc[:, "ancestor_list"] = \
              data.loc[:, "ancestor_list"].apply(ast.literal_eval)
          data.set_index("id", inplace=True)
      elif filename.endswith(".json"):  # Handle JSON files
          data = pd.read_json(filename, orient="index", convert_dates=False)
  
      # Have to do this in two passes, (one to add nodes, one to
      # add eges) because order in file is not required/guaranteed
  
      taxon_namespace = dendropy.TaxonNamespace(data.index)
      phylogeny = dendropy.Tree(taxon_namespace=taxon_namespace)
  
      # Add nodes
      # for taxon_id in data.index:
      #     phylogeny.add_node(taxon_id)
      #     for col in data:
      #         if col == "id":
      #             continue
      #         phylogeny.nodes[taxon_id][col] = data.loc[taxon_id, col]
  
      # # Add edges
      # for taxon_id in data.index:
  
      #     for ancestor in data.loc[taxon_id, "ancestor_list"]:
      #         try:  # Conversion to int will fail if its a special value
      #             ancestor = int(ancestor)
      #             if phylogeny.has_node(ancestor):
      #                 phylogeny.add_edge(ancestor, taxon_id)
      #             else:
      #                 raise Exception(f"{taxon_id}'s ancestor, {ancestor}, is not in this file.")
  
      #         except ValueError:  # Handle special values
      #             phylogeny.nodes[taxon_id]["origin"] = ancestor
  
      # return phylogeny
code_tokens: def load_phylogeny_to_dendropy ( filename ) : if filename . endswith ( ".csv" ) : data = pd . read_csv ( filename ) data . loc [ : , "ancestor_list" ] = data . loc [ : , "ancestor_list" ] . apply ( ast . literal_eval ) data . set_index ( "id" , inplace = True ) elif filename . endswith ( ".json" ) : data = pd . read_json ( filename , orient = "index" , convert_dates = False ) taxon_namespace = dendropy . TaxonNamespace ( data . index ) phylogeny = dendropy . Tree ( taxon_namespace = taxon_namespace )
short_docstring: Loads a phylogeny in standards format (in csv or json) from the file
  specified by the filename parameter.
short_docstring_tokens: Loads a phylogeny in standards format ( in csv or json ) from the file specified by the filename parameter .
comment: """
      Loads a phylogeny in standards format (in csv or json) from the file
      specified by the filename parameter. Returns the phylogeny as a
      dendropy tree.
  
      Special ancestor values are encoded in an "origin" field within nodes.
      Example: `my_phylogeny.nodes["A"]["origin"]` would return the origin of
      node "A"
      """$SEP$# Handle CSV files$SEP$# The ancestor_list column contains a string of lists of strings$SEP$# Let's turn it into an actual list of strings$SEP$# Handle JSON files$SEP$# Have to do this in two passes, (one to add nodes, one to$SEP$# add eges) because order in file is not required/guaranteed$SEP$# Add nodes$SEP$# for taxon_id in data.index:$SEP$#     phylogeny.add_node(taxon_id)$SEP$#     for col in data:$SEP$#         if col == "id":$SEP$#             continue$SEP$#         phylogeny.nodes[taxon_id][col] = data.loc[taxon_id, col]$SEP$# # Add edges$SEP$# for taxon_id in data.index:$SEP$#     for ancestor in data.loc[taxon_id, "ancestor_list"]:$SEP$#         try:  # Conversion to int will fail if its a special value$SEP$#             ancestor = int(ancestor)$SEP$#             if phylogeny.has_node(ancestor):$SEP$#                 phylogeny.add_edge(ancestor, taxon_id)$SEP$#             else:$SEP$#                 raise Exception(f"{taxon_id}'s ancestor, {ancestor}, is not in this file.")$SEP$#         except ValueError:  # Handle special values$SEP$#             phylogeny.nodes[taxon_id]["origin"] = ancestor$SEP$# return phylogeny