<commit_before>get '/css/:filename.css' do
  scss :"sass/#{params[:filename]}"
end

get '/' do
  haml :home
end

get '/blast' do
  haml :blast
end

post '/blast' do
  haml :blast_result
#   program = params[:program]
#   file = params[:seqfile]
#   @seq = file ? seq_from_file(file) : params[:sequence]
#   from_query = params[:from_query]
#   to_query = params[:to_query]
#   blast = Seabase::Blast.new(program)
#   @blast_result = @seq.to_s != '' ? blast.search(@seq) : nil
#   if @blast_result
#     haml :blast_result
#   else
#     redirect '/blast' 
#   end
end

get '/search.?:format?' do
  opts = {
    format: params[:format],
    scientific_name: params[:scientific_name],
    term: params[:term],
    limit: (params[:batch_size] || 100),
    exact_search: (params[:exact_search] == 'true'),
    callback: params[:callback]
  }
  @external_names = perform_search(opts)
  format_search_results(opts)
end

get '/external_names/:id' do
  @en = ExternalName.find(params[:id])
  @table_data = @en.table_items.unshift(Replicate.all_stages)
  @chart_title = "Sum of transcription levels for %s homologs" % @en.gene_name
  haml :external_name
end

get '/transcript/:id' do
  @en = ExternalName.find(params[:external_name_id])
  @tr = Transcript.find(params[:id])
  @chart_title = "Transcription levels for %s" % @tr.name
  @table_data = @tr.table_items.unshift(Replicate.all_stages)
  @name = "Transcript #{@tr.name}"
  haml :transcript
end

get '/transcript' do
  @tr = Transcript.find_by_name(params[:name])
  @chart_title = "Transcription levels for %s" % @tr.name
  @table_data = @tr.table_items.unshift(Replicate.all_stages)
  @name = "Transcript #{@tr.name}"
  haml :transcript
end

private

def perform_search(opts)
  if opts[:exact_search]
    opts[:term].gsub!(/:[^:]*:.*/, '')
    ExternalName.exact_search(opts)
  else
    ExternalName.like_search(opts)
  end
end

def format_search_json(opts)
  content_type 'application/json', charset: 'utf-8'
  names_json = @external_names.to_json
  if opts[:callback]
    names_json = "%s(%s)" % [opts[:callback], names_json]
  end
  names_json
end
<commit_msg>removed duplication frm transcript route<commit_after>get '/css/:filename.css' do
  scss :"sass/#{params[:filename]}"
end

get '/' do
  haml :home
end

get '/blast' do
  haml :blast
end

post '/blast' do
  #heavy lifing is done by Rack::Blast
  haml :blast_result
end

get '/search.?:format?' do
  opts = {
    format: params[:format],
    scientific_name: params[:scientific_name],
    term: params[:term],
    limit: (params[:batch_size] || 100),
    exact_search: (params[:exact_search] == 'true'),
    callback: params[:callback]
  }
  @external_names = perform_search(opts)
  format_search_results(opts)
end

get '/external_names/:id' do
  @en = ExternalName.find(params[:id])
  @table_data = @en.table_items.unshift(Replicate.all_stages)
  @chart_title = "Sum of transcription levels for %s homologs" % @en.gene_name
  haml :external_name
end

get '/transcript/?:id?' do
  @tr = Transcript.find_by_name(params[:name]) if params[:name]
  @tr = Transcript.find(params[:id]) if params[:id]
  @en = ExternalName.find(params[:external_name_id])
  @chart_title = "Transcription levels for %s" % @tr.name
  @table_data = @tr.table_items.unshift(Replicate.all_stages)
  @name = "Transcript #{@tr.name}"
  haml :transcript
end

private

def perform_search(opts)
  if opts[:exact_search]
    opts[:term].gsub!(/:[^:]*:.*/, '')
    ExternalName.exact_search(opts)
  else
    ExternalName.like_search(opts)
  end
end

def format_search_json(opts)
  content_type 'application/json', charset: 'utf-8'
  names_json = @external_names.to_json
  if opts[:callback]
    names_json = "%s(%s)" % [opts[:callback], names_json]
  end
  names_json
end

{'fraction_non_alphanumeric': 0.15162840363053925, 'fraction_numerical': 0.002135611318739989, 'mean_word_length': 4.454148471615721, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6973522', 'n_tokens_mistral': 1401, 'n_tokens_neox': 1345, 'n_words': 287}