code: def construct_umls_tree_from_tsv(
      filepath: str,
  ) -> UmlsSemanticTypeTree:
      """
      Reads in a tsv file which is formatted as a depth first traversal of
      a hierarchy tree, where nodes are of the format:
  
      Name TAB UMLS Semantic Type TAB Tree Depth
  
      Event    T051    1
        Activity    T052    2
          Behavior    T053    3
            Social Behavior    T054    4
            Individual Behavior    T055    4
          Daily or Recreational Activity    T056    3
      """
  
      node_stack: Deque[SemanticTypeNode] = deque()
      for line in open(cached_path(filepath), "r"):
          name, type_id, level = line.split("\t")
          name = name.strip()
          int_level = int(level.strip())
          node = SemanticTypeNode(type_id, name, [], int_level)
  
          node_stack.append(node)
  
      def attach_children(
          node: SemanticTypeNode, stack: Deque[SemanticTypeNode]
      ):
          while stack and stack[0].level > node.level:
              popped = stack.popleft()
              attach_children(popped, stack)
              node.children.append(popped)
  
      first = node_stack.popleft()
      attach_children(first, node_stack)
  
      return UmlsSemanticTypeTree(first)
  
file_path: scispacy/scispacy/umls_semantic_type_tree.py
imports: from typing import NamedTuple, List, Dict, Deque, Any, Optional
  from collections import deque
  from scispacy.file_cache import cached_path
label_desc: Use image node_id 1 for calling a global function with example usage: construct_umls_tree_from_tsv(filepath) and returns: UmlsSemanticTypeTree