parameters: (graph)
docstring: Assigns a copy depth to each segment in the graph.
docstring_summary: Assigns a copy depth to each segment in the graph.
docstring_tokens: Assigns a copy depth to each segment in the graph .
function: def determine_copy_depth(graph):
      """
      Assigns a copy depth to each segment in the graph.
      """
      # Reset any existing copy depths.
      graph.copy_depths = {}
  
      log.log_section_header('Determining graph multiplicity')
      log.log_explanation('Multiplicity is the number of times a '
                          'sequence occurs in the underlying sequence. Single-copy contigs '
                          '(those with a multiplicity of one, occurring only once in the underlying '
                          'sequence) are particularly useful.',
                          verbosity=1, extra_empty_lines_after=0)
  
      log.log_explanation('Multiplicity determination begins by identifying contigs which are '
                          'clearly single-copy because they are of low depth and do not have more '
                          'than one link per side.',
                          verbosity=2)
  
      single_copy_depth = graph.get_single_copy_depth()
  
      # Assign single copy status to segments within the tolerance of the single copy depth.
      # Also, if the graph has manually set multiplicity values (using the ML tag), we also use them
      # to assign single copy status.
      max_depth = single_copy_depth + settings.INITIAL_SINGLE_COPY_TOLERANCE
      initial_single_copy_segments = []
      for segment in sorted([x for x in graph.segments.values()],
                            key=lambda x: x.get_length(), reverse=True):
          num = segment.number
          depth = segment.depth
          if (depth <= max_depth and okay_for_initial_single_copy(graph, segment)) or \
                  (num in graph.manual_multiplicity and graph.manual_multiplicity[num] == 1):
              graph.copy_depths[segment.number] = [segment.depth]
              initial_single_copy_segments.append(segment.number)
  
      if initial_single_copy_segments:
          log.log('\nInitial single copy segments:', 2)
          log.log_number_list(initial_single_copy_segments, 2)
      else:
          log.log('Initial single copy segments: none', 2)
  
      log.log('', verbosity=2)
      log.log_explanation('Unicycler now uses a greedy algorithm to propagate multiplicity '
                          'through the graph. For example, if two single-copy contigs merge '
                          'together, the resulting contig will get a multiplicity of two. '
                          'When no more propagation is possible, additional single-copy contigs '
                          'are added and the process is repeated. This allows for multiplicity to be '
                          'correctly assigned to the chromosome (at the median depth) but also for '
                          'plasmids (which may be higher or lower in depth).',
                          verbosity=2)
  
      # Propagate copy depth as much as possible using those initial assignments.
      copy_depth_table = [['Input', '', 'Output']]
      determine_copy_depth_part_2(graph, settings.COPY_PROPAGATION_TOLERANCE, copy_depth_table)
  
      # Assign single copy to the largest available segment, propagate and repeat.
      while True:
          assignments = assign_single_copy_depth(graph, settings.MIN_SINGLE_COPY_LENGTH,
                                                 copy_depth_table)
          determine_copy_depth_part_2(graph, settings.COPY_PROPAGATION_TOLERANCE, copy_depth_table)
          if not assignments:
              break
  
      # Now propagate with no tolerance threshold to complete the remaining segments.
      if log.logger.stdout_verbosity_level >= 3:
          copy_depth_table.append(['REMOVING PROPAGATION TOLERANCE', '', ''])
      determine_copy_depth_part_2(graph, 1.0, copy_depth_table)
  
      print_table(copy_depth_table, alignments='RLL', max_col_width=999, hide_header=True,
                  indent=0, col_separation=1, verbosity=2)
function_tokens: def determine_copy_depth ( graph ) : # Reset any existing copy depths. graph . copy_depths = { } log . log_section_header ( 'Determining graph multiplicity' ) log . log_explanation ( 'Multiplicity is the number of times a ' 'sequence occurs in the underlying sequence. Single-copy contigs ' '(those with a multiplicity of one, occurring only once in the underlying ' 'sequence) are particularly useful.' , verbosity = 1 , extra_empty_lines_after = 0 ) log . log_explanation ( 'Multiplicity determination begins by identifying contigs which are ' 'clearly single-copy because they are of low depth and do not have more ' 'than one link per side.' , verbosity = 2 ) single_copy_depth = graph . get_single_copy_depth ( ) # Assign single copy status to segments within the tolerance of the single copy depth. # Also, if the graph has manually set multiplicity values (using the ML tag), we also use them # to assign single copy status. max_depth = single_copy_depth + settings . INITIAL_SINGLE_COPY_TOLERANCE initial_single_copy_segments = [ ] for segment in sorted ( [ x for x in graph . segments . values ( ) ] , key = lambda x : x . get_length ( ) , reverse = True ) : num = segment . number depth = segment . depth if ( depth <= max_depth and okay_for_initial_single_copy ( graph , segment ) ) or ( num in graph . manual_multiplicity and graph . manual_multiplicity [ num ] == 1 ) : graph . copy_depths [ segment . number ] = [ segment . depth ] initial_single_copy_segments . append ( segment . number ) if initial_single_copy_segments : log . log ( '\nInitial single copy segments:' , 2 ) log . log_number_list ( initial_single_copy_segments , 2 ) else : log . log ( 'Initial single copy segments: none' , 2 ) log . log ( '' , verbosity = 2 ) log . log_explanation ( 'Unicycler now uses a greedy algorithm to propagate multiplicity ' 'through the graph. For example, if two single-copy contigs merge ' 'together, the resulting contig will get a multiplicity of two. ' 'When no more propagation is possible, additional single-copy contigs ' 'are added and the process is repeated. This allows for multiplicity to be ' 'correctly assigned to the chromosome (at the median depth) but also for ' 'plasmids (which may be higher or lower in depth).' , verbosity = 2 ) # Propagate copy depth as much as possible using those initial assignments. copy_depth_table = [ [ 'Input' , '' , 'Output' ] ] determine_copy_depth_part_2 ( graph , settings . COPY_PROPAGATION_TOLERANCE , copy_depth_table ) # Assign single copy to the largest available segment, propagate and repeat. while True : assignments = assign_single_copy_depth ( graph , settings . MIN_SINGLE_COPY_LENGTH , copy_depth_table ) determine_copy_depth_part_2 ( graph , settings . COPY_PROPAGATION_TOLERANCE , copy_depth_table ) if not assignments : break # Now propagate with no tolerance threshold to complete the remaining segments. if log . logger . stdout_verbosity_level >= 3 : copy_depth_table . append ( [ 'REMOVING PROPAGATION TOLERANCE' , '' , '' ] ) determine_copy_depth_part_2 ( graph , 1.0 , copy_depth_table ) print_table ( copy_depth_table , alignments = 'RLL' , max_col_width = 999 , hide_header = True , indent = 0 , col_separation = 1 , verbosity = 2 )