<commit_before>#!/usr/bin/env ruby
require 'optparse'
require 'logger'
require 'spreadsheet'
require 'set'

$logger = Logger.new(STDERR)
$index_file = ""

# Initialize logger
def setup_logger(loglevel)
  case loglevel
  when "debug"
    $logger.level = Logger::DEBUG
  when "warn"
    $logger.level = Logger::WARN
  when "info"
    $logger.level = Logger::INFO
  else
    $logger.level = Logger::ERROR
  end
end

def setup_options(args)
  options = {:out_file =>  "merged_table.xls", :cut_off => 0,
    :junction_files => ""}

  opt_parser = OptionParser.new do |opts|
    opts.banner = "Usage: #{$0} [options] real.xls sim.xls index_file"
    opts.separator ""
    opts.separator "xls files produced by fusion_table.rb."

    opts.separator ""
    opts.on("-o", "--out_file [OUT_FILE]",
      :REQUIRED,String,
      "File for the output, Default: merged_table.xls") do |anno_file|
      options[:out_file] = anno_file
    end

    opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
      options[:log_level] = "info"
    end

    opts.on("-d", "--debug", "Run in debug mode") do |v|
      options[:log_level] = "debug"
    end

    opts.on("-c", "--cut_off",Integer, "Set cut_off default is no cut off") do |v|
      options[:cut_off] = v
    end

    #opts.on("-j", "--junction_files",:REQUIRED,String, "Comma separated junction list") do |v|
    #  options[:junction_files] = v
    #end
  end

  args = ["-h"] if args.length < 3
  opt_parser.parse!(args)
  raise "Please specify the sam files" if args.length == 0
  options
end

def run_bl2seq(gene1,gene2)
  gene1 = "hg19_refGene_#{gene1}"
  gene2 = "hg19_refGene_#{gene2}"
  `samtools faidx #{$index_file} #{gene1}> tmp1.fa`
  `samtools faidx #{$index_file} #{gene2}> tmp2.fa`
  out = `bl2seq -i tmp1.fa -j tmp2.fa -p blastn -D 1`
  score = ""
  identities = ""
  expect = ""
  alignment_length = ""
  out.split("\n").each do |line|
    line.chomp!
    next if line =~ /^#/
    fields = line.split("\t")
    score = fields[-1].to_f
    identities = fields[2].to_f
    expect = fields[-2].to_f
    alignment_length = fields[3].to_i
    break
  end
  [expect, identities,score,  alignment_length]<commit_msg>hitting the pause button<commit_after>#!/usr/bin/env ruby
require 'optparse'
require 'logger'
require 'spreadsheet'
require 'set'

$logger = Logger.new(STDERR)
$index_file = ""

# Initialize logger
def setup_logger(loglevel)
  case loglevel
  when "debug"
    $logger.level = Logger::DEBUG
  when "warn"
    $logger.level = Logger::WARN
  when "info"
    $logger.level = Logger::INFO
  else
    $logger.level = Logger::ERROR
  end
end

def setup_options(args)
  options = {:out_file =>  "merged_table.xls", :cut_off => 0,
    :junction_files => ""}

  opt_parser = OptionParser.new do |opts|
    opts.banner = "Usage: #{$0} [options] real.xls sim.xls index_file"
    opts.separator ""
    opts.separator "xls files produced by fusion_table.rb."

    opts.separator ""
    opts.on("-o", "--out_file [OUT_FILE]",
      :REQUIRED,String,
      "File for the output, Default: merged_table.xls") do |anno_file|
      options[:out_file] = anno_file
    end

    opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
      options[:log_level] = "info"
    end

    opts.on("-d", "--debug", "Run in debug mode") do |v|
      options[:log_level] = "debug"
    end

    opts.on("-c", "--cut_off",Integer, "Set cut_off default is no cut off") do |v|
      options[:cut_off] = v
    end

    #opts.on("-j", "--junction_files",:REQUIRED,String, "Comma separated junction list") do |v|
    #  options[:junction_files] = v
    #end
  end

  args = ["-h"] if args.length < 3
  opt_parser.parse!(args)
  raise "Please specify the sam files" if args.length == 0
  options
end

def run_bl2seq(gene1,gene2)
  gene1 = "hg19_refGene_#{gene1}"
  gene2 = "hg19_refGene_#{gene2}"
  `samtools faidx #{$index_file} #{gene1}> tmp1.fa`
  `samtools faidx #{$index_file} #{gene2}> tmp2.fa`
  out = `bl2seq -F F -i tmp1.fa -j tmp2.fa -p blastn -D 1`
  score = ""
  identities = ""
  expect = ""
  alignment_length = ""
  out.split("\n").each do |line|
    line.chomp!
    next if line =~ /^#/
    fields = line.split("\t")
    score = fields[-1].to_f
    identities = fields[2].to_f
    expect = fields[-2].to_f
    alignment_length = fields[3].to_i
    break
  end
  [expect, identities,score,  alignment_length]
{'fraction_non_alphanumeric': 0.15977011494252874, 'fraction_numerical': 0.012413793103448275, 'mean_word_length': 3.203864734299517, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '615015', 'n_tokens_mistral': 1655, 'n_tokens_neox': 1594, 'n_words': 390}