<commit_before># Copyright (c) 2014, <NAME>, OMRF
# Distributed under a BSD 3-Clause
# Full license available in LICENSE.txt distributed with this software

class Optical::PeakCaller::Macs < Optical::PeakCaller
  MACS_OUTPUT_SUFFICES = {control_bdg:"_control_lambda.bdg", model_r:"_model.r", model_pdf:"_model.pdf",
    peak_bed:"_peaks.bed", encode_peak:"_peaks.encodePeak", peak_xls:"_peaks.xls",
    summit_bed:"_summits.bed", pileup:"_treat_pileup.bdg"}

  attr_reader :control_bdg_path, :peak_bed_path, :encode_peak_path, :peak_xls_path, :summit_bed_path,
    :pileup_path, :model_pdf_path

  def find_peaks(output_base,conf)
    full_output_base = File.join(output_base,safe_name)
    @pair.each do |s|
      unless sample_ready?(s)
        @errors << "The sample #{s} is not ready, the bam is missing"
        return false
      end
    end
    if run_macs(output_base,conf)
      @control_bdg_path = full_output_base + MACS_OUTPUT_SUFFICES[:control_bdg]
      @peak_bed_path = full_output_base + MACS_OUTPUT_SUFFICES[:peak_bed]
      @encode_peak_path = full_output_base + MACS_OUTPUT_SUFFICES[:encode_peak]
      @peak_xls_path = full_output_base + MACS_OUTPUT_SUFFICES[:peak_xls]
      @summit_bed_path = full_output_base + MACS_OUTPUT_SUFFICES[:summit_bed]
      @pileup_path = full_output_base + MACS_OUTPUT_SUFFICES[:pileup]

      return model_to_pdf(full_output_base,conf) &&
        strip_name_prefix_from_peak_names(conf)
    end
    return false
  end
  private<commit_msg>Add step to prepend a track header to a bed<commit_after># Copyright (c) 2014, <NAME>, OMRF
# Distributed under a BSD 3-Clause
# Full license available in LICENSE.txt distributed with this software

class Optical::PeakCaller::Macs < Optical::PeakCaller
  MACS_OUTPUT_SUFFICES = {control_bdg:"_control_lambda.bdg", model_r:"_model.r", model_pdf:"_model.pdf",
    peak_bed:"_peaks.bed", encode_peak:"_peaks.encodePeak", peak_xls:"_peaks.xls",
    summit_bed:"_summits.bed", pileup:"_treat_pileup.bdg"}

  attr_reader :control_bdg_path, :peak_bed_path, :encode_peak_path, :peak_xls_path, :summit_bed_path,
    :pileup_path, :model_pdf_path

  def find_peaks(output_base,conf)
    full_output_base = File.join(output_base,safe_name)
    @pair.each do |s|
      unless sample_ready?(s)
        @errors << "The sample #{s} is not ready, the bam is missing"
        return false
      end
    end
    if run_macs(output_base,conf)
      @control_bdg_path = full_output_base + MACS_OUTPUT_SUFFICES[:control_bdg]
      @peak_bed_path = full_output_base + MACS_OUTPUT_SUFFICES[:peak_bed]
      @encode_peak_path = full_output_base + MACS_OUTPUT_SUFFICES[:encode_peak]
      @peak_xls_path = full_output_base + MACS_OUTPUT_SUFFICES[:peak_xls]
      @summit_bed_path = full_output_base + MACS_OUTPUT_SUFFICES[:summit_bed]
      @pileup_path = full_output_base + MACS_OUTPUT_SUFFICES[:pileup]

      return model_to_pdf(full_output_base,conf) &&
        strip_name_prefix_from_peak_names(conf) &&
        add_track_header_to_file(@peak_bed_path,conf)
    end
    return false
  end
  private

  def add_track_header_to_file(path,conf)
    name=File.basename(path)
    header=<<-EOF
track name="#{name}" description="#{name}" visibility=full color="#{conf.random_visualization_color()}"
    EOF
    cmd = conf.cluster_cmd_prefix(free:1, max:1, sync:true, name:"trackname_#{safe_name()}") +
      %W(sed -i '1i#{header.chomp}' #{path})

    unless !conf.skip_peak_calling
      puts cmd.join(" ") if conf.verbose
      unless system(*cmd)
        @errors << "Failed to add track header for #{self}: #{$?.exitstatus}"
        return false
      end
    end
    return true
  end
{'fraction_non_alphanumeric': 0.10648781823159047, 'fraction_numerical': 0.0035587188612099642, 'mean_word_length': 4.612903225806452, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '646669', 'n_tokens_mistral': 1363, 'n_tokens_neox': 1310, 'n_words': 236}