parameters: (graph, anchor_segments)
return_statement: return bridges
docstring: Builds graph bridges using the SPAdes contig paths.
docstring_summary: Builds graph bridges using the SPAdes contig paths.
docstring_tokens: Builds graph bridges using the SPAdes contig paths .
function: def create_spades_contig_bridges(graph, anchor_segments):
      """
      Builds graph bridges using the SPAdes contig paths.
      """
      log.log_section_header('Creating SPAdes contig bridges')
      log.log_explanation('SPAdes uses paired-end information to perform repeat resolution (RR) and '
                          'produce contigs from the assembly graph. SPAdes saves the graph paths '
                          'corresponding to these contigs in the contigs.paths file. When one of '
                          'these paths contains two or more anchor contigs, Unicycler can '
                          'create a bridge from the path.', verbosity=1)
  
      bridge_path_set = set()
      single_copy_numbers = [x.number for x in anchor_segments]
      for segment in anchor_segments:
          for path in graph.paths.values():
              flipped_path = [-x for x in reversed(path)]
              contig_bridges = find_contig_bridges(segment.number, path, single_copy_numbers)
              contig_bridges += find_contig_bridges(segment.number, flipped_path, single_copy_numbers)
              for contig_bridge in contig_bridges:
                  flipped_contig_bridge = [-x for x in reversed(contig_bridge)]
                  contig_bridge_str = ','.join([str(x) for x in contig_bridge])
                  flipped_contig_bridge_str = ','.join([str(x) for x in flipped_contig_bridge])
                  if contig_bridge_str not in bridge_path_set and \
                          flipped_contig_bridge_str not in bridge_path_set:
                      if contig_bridge[0] < 0 and contig_bridge[-1] < 0:
                          bridge_path_set.add(flipped_contig_bridge_str)
                      else:
                          bridge_path_set.add(contig_bridge_str)
  
      bridge_path_list = sorted(list([[int(y) for y in x.split(',')] for x in bridge_path_set]))
  
      # If multiple bridge paths start with or end with the same segment, that implies a conflict
      # between SPADes' paths and our single copy determination. Throw these bridges out.
      bridge_paths_by_start = {}
      bridge_paths_by_end = {}
      for path in bridge_path_list:
          start = path[0]
          end = path[-1]
          if start not in bridge_paths_by_start:
              bridge_paths_by_start[start] = []
          if end not in bridge_paths_by_end:
              bridge_paths_by_end[end] = []
          if -end not in bridge_paths_by_start:
              bridge_paths_by_start[-end] = []
          if -start not in bridge_paths_by_end:
              bridge_paths_by_end[-start] = []
          bridge_paths_by_start[start].append(path)
          bridge_paths_by_end[end].append(path)
          bridge_paths_by_start[-end].append(path)
          bridge_paths_by_end[-start].append(path)
      conflicting_paths = []
      for grouped_paths in bridge_paths_by_start.values():
          if len(grouped_paths) > 1:
              conflicting_paths += grouped_paths
      for grouped_paths in bridge_paths_by_end.values():
          if len(grouped_paths) > 1:
              conflicting_paths += grouped_paths
      conflicting_paths_no_dupes = []
      for path in conflicting_paths:
          if path not in conflicting_paths_no_dupes:
              conflicting_paths_no_dupes.append(path)
      conflicting_paths = conflicting_paths_no_dupes
      final_bridge_paths = [x for x in bridge_path_list if x not in conflicting_paths]
  
      bridges = [SpadesContigBridge(spades_contig_path=x, graph=graph) for x in final_bridge_paths]
  
      if bridges:
          bridge_table = [['Start', 'Path', 'End', 'Bridge quality']]
          spaded_arrow = ' ' + get_right_arrow() + ' '
          max_path_str_len = 5
          for bridge in bridges:
              path_str = spaded_arrow.join(str(seg) for seg in bridge.graph_path)
              max_path_str_len = max(max_path_str_len, len(path_str))
              bridge_table.append([str(bridge.start_segment), path_str, str(bridge.end_segment),
                                   float_to_str(bridge.quality, 1)])
          print_table(bridge_table, alignments='RCLR', left_align_header=False, indent=0,
                      fixed_col_widths=[5, max_path_str_len, 5, 7])
      else:
          log.log('No SPAdes contig bridges')
  
      return bridges
function_tokens: def create_spades_contig_bridges ( graph , anchor_segments ) : log . log_section_header ( 'Creating SPAdes contig bridges' ) log . log_explanation ( 'SPAdes uses paired-end information to perform repeat resolution (RR) and ' 'produce contigs from the assembly graph. SPAdes saves the graph paths ' 'corresponding to these contigs in the contigs.paths file. When one of ' 'these paths contains two or more anchor contigs, Unicycler can ' 'create a bridge from the path.' , verbosity = 1 ) bridge_path_set = set ( ) single_copy_numbers = [ x . number for x in anchor_segments ] for segment in anchor_segments : for path in graph . paths . values ( ) : flipped_path = [ - x for x in reversed ( path ) ] contig_bridges = find_contig_bridges ( segment . number , path , single_copy_numbers ) contig_bridges += find_contig_bridges ( segment . number , flipped_path , single_copy_numbers ) for contig_bridge in contig_bridges : flipped_contig_bridge = [ - x for x in reversed ( contig_bridge ) ] contig_bridge_str = ',' . join ( [ str ( x ) for x in contig_bridge ] ) flipped_contig_bridge_str = ',' . join ( [ str ( x ) for x in flipped_contig_bridge ] ) if contig_bridge_str not in bridge_path_set and flipped_contig_bridge_str not in bridge_path_set : if contig_bridge [ 0 ] < 0 and contig_bridge [ - 1 ] < 0 : bridge_path_set . add ( flipped_contig_bridge_str ) else : bridge_path_set . add ( contig_bridge_str ) bridge_path_list = sorted ( list ( [ [ int ( y ) for y in x . split ( ',' ) ] for x in bridge_path_set ] ) ) # If multiple bridge paths start with or end with the same segment, that implies a conflict # between SPADes' paths and our single copy determination. Throw these bridges out. bridge_paths_by_start = { } bridge_paths_by_end = { } for path in bridge_path_list : start = path [ 0 ] end = path [ - 1 ] if start not in bridge_paths_by_start : bridge_paths_by_start [ start ] = [ ] if end not in bridge_paths_by_end : bridge_paths_by_end [ end ] = [ ] if - end not in bridge_paths_by_start : bridge_paths_by_start [ - end ] = [ ] if - start not in bridge_paths_by_end : bridge_paths_by_end [ - start ] = [ ] bridge_paths_by_start [ start ] . append ( path ) bridge_paths_by_end [ end ] . append ( path ) bridge_paths_by_start [ - end ] . append ( path ) bridge_paths_by_end [ - start ] . append ( path ) conflicting_paths = [ ] for grouped_paths in bridge_paths_by_start . values ( ) : if len ( grouped_paths ) > 1 : conflicting_paths += grouped_paths for grouped_paths in bridge_paths_by_end . values ( ) : if len ( grouped_paths ) > 1 : conflicting_paths += grouped_paths conflicting_paths_no_dupes = [ ] for path in conflicting_paths : if path not in conflicting_paths_no_dupes : conflicting_paths_no_dupes . append ( path ) conflicting_paths = conflicting_paths_no_dupes final_bridge_paths = [ x for x in bridge_path_list if x not in conflicting_paths ] bridges = [ SpadesContigBridge ( spades_contig_path = x , graph = graph ) for x in final_bridge_paths ] if bridges : bridge_table = [ [ 'Start' , 'Path' , 'End' , 'Bridge quality' ] ] spaded_arrow = ' ' + get_right_arrow ( ) + ' ' max_path_str_len = 5 for bridge in bridges : path_str = spaded_arrow . join ( str ( seg ) for seg in bridge . graph_path ) max_path_str_len = max ( max_path_str_len , len ( path_str ) ) bridge_table . append ( [ str ( bridge . start_segment ) , path_str , str ( bridge . end_segment ) , float_to_str ( bridge . quality , 1 ) ] ) print_table ( bridge_table , alignments = 'RCLR' , left_align_header = False , indent = 0 , fixed_col_widths = [ 5 , max_path_str_len , 5 , 7 ] ) else : log . log ( 'No SPAdes contig bridges' ) return bridges