parameters: (args, stats_in, contigs_in, stats_out, contigs_out)
docstring: Filters out contigs with low coverage
docstring_summary: Filters out contigs with low coverage
docstring_tokens: Filters out contigs with low coverage
function: def filter_by_coverage(args, stats_in, contigs_in, stats_out, contigs_out):
      """
      Filters out contigs with low coverage
      """
      SUBASM_MIN_COVERAGE = 1
      HARD_MIN_COVERAGE = cfg.vals["hard_minimum_coverage"]
      RELATIVE_MIN_COVERAGE = cfg.vals["relative_minimum_coverage"]
  
      ctg_stats = {}
      sum_cov = 0
      sum_length = 0
  
      with open(stats_in, "r") as f:
          for line in f:
              if line.startswith("#"): continue
              tokens = line.split("\t")
              ctg_id, ctg_len, ctg_cov = tokens[0], int(tokens[1]), int(tokens[2])
              ctg_stats[ctg_id] = (ctg_len, ctg_cov)
              sum_cov += ctg_cov * ctg_len
              sum_length += ctg_len
  
      mean_coverage = int(sum_cov / sum_length)
      coverage_threshold = None
      if args.read_type == "subasm":
          coverage_threshold = SUBASM_MIN_COVERAGE
      elif args.meta:
          coverage_threshold = HARD_MIN_COVERAGE
      else:
          coverage_threshold = int(round(mean_coverage /
                                         RELATIVE_MIN_COVERAGE))
          coverage_threshold = max(HARD_MIN_COVERAGE, coverage_threshold)
      logger.debug("Mean contig coverage: %d, selected threshold: %d",
                   mean_coverage, coverage_threshold)
  
      filtered_num = 0
      filtered_seq = 0
      good_fasta = {}
      for hdr, seq in fp.stream_sequence(contigs_in):
          if ctg_stats[hdr][1] >= coverage_threshold:
              good_fasta[hdr] = seq
          else:
              filtered_num += 1
              filtered_seq += ctg_stats[hdr][0]
      logger.debug("Filtered %d contigs of total length %d",
                   filtered_num, filtered_seq)
  
      fp.write_fasta_dict(good_fasta, contigs_out)
      with open(stats_out, "w") as f:
          f.write("#seq_name\tlength\tcoverage\n")
          for ctg_id in good_fasta:
              f.write("{0}\t{1}\t{2}\n".format(ctg_id,
                      ctg_stats[ctg_id][0], ctg_stats[ctg_id][1]))
function_tokens: def filter_by_coverage ( args , stats_in , contigs_in , stats_out , contigs_out ) : SUBASM_MIN_COVERAGE = 1 HARD_MIN_COVERAGE = cfg . vals [ "hard_minimum_coverage" ] RELATIVE_MIN_COVERAGE = cfg . vals [ "relative_minimum_coverage" ] ctg_stats = { } sum_cov = 0 sum_length = 0 with open ( stats_in , "r" ) as f : for line in f : if line . startswith ( "#" ) : continue tokens = line . split ( "\t" ) ctg_id , ctg_len , ctg_cov = tokens [ 0 ] , int ( tokens [ 1 ] ) , int ( tokens [ 2 ] ) ctg_stats [ ctg_id ] = ( ctg_len , ctg_cov ) sum_cov += ctg_cov * ctg_len sum_length += ctg_len mean_coverage = int ( sum_cov / sum_length ) coverage_threshold = None if args . read_type == "subasm" : coverage_threshold = SUBASM_MIN_COVERAGE elif args . meta : coverage_threshold = HARD_MIN_COVERAGE else : coverage_threshold = int ( round ( mean_coverage / RELATIVE_MIN_COVERAGE ) ) coverage_threshold = max ( HARD_MIN_COVERAGE , coverage_threshold ) logger . debug ( "Mean contig coverage: %d, selected threshold: %d" , mean_coverage , coverage_threshold ) filtered_num = 0 filtered_seq = 0 good_fasta = { } for hdr , seq in fp . stream_sequence ( contigs_in ) : if ctg_stats [ hdr ] [ 1 ] >= coverage_threshold : good_fasta [ hdr ] = seq else : filtered_num += 1 filtered_seq += ctg_stats [ hdr ] [ 0 ] logger . debug ( "Filtered %d contigs of total length %d" , filtered_num , filtered_seq ) fp . write_fasta_dict ( good_fasta , contigs_out ) with open ( stats_out , "w" ) as f : f . write ( "#seq_name\tlength\tcoverage\n" ) for ctg_id in good_fasta : f . write ( "{0}\t{1}\t{2}\n" . format ( ctg_id , ctg_stats [ ctg_id ] [ 0 ] , ctg_stats [ ctg_id ] [ 1 ] ) )