<commit_before>/* -*- Mode: js2; indent-tabs-mode: nil; js2-basic-offset: 2; -*- */
/* global $, Blob, saveAs, CSV, d3, JSZip, _ */
// CSV: https://github.com/knrz/CSV.js/

var data = [
  { label: 'Creator (Name)',
    id: 'creator',
    required: true,
    type: 'input',
    example: '<NAME>' },
  { label: 'Creator Email',
    id: 'creator-email',
    required: true,
    type: 'input',
    example: '<EMAIL>' },
  { label: 'Project Name',
    id: 'project',
    required: true,
    type: 'input' },
  { label: 'Data Type',
    id: 'data-type',
    type: 'dropdown',
    custom: true,
    default: 'DNA-seq',
    options: ['DNA-seq', 'RNA-seq', 'ChIP-seq', 'ChIP-exo', 'Ribo-seq'] },
  { label: 'Experiment Date (YYYY-MM-DD)',
    id: 'run-date',
    required: true,
    type: 'date',
    description: 'For sequencing experiments, use the date the sample was run.'},
  { label: 'NCBI Taxonomy ID for Strain',
    id: 'taxonomy-id',
    type: 'dropdown',
    custom: true,
    required: true,
    options_function: function(callback) {
      $.getJSON('ncbi_taxon_ids.json')
        .success(function(d) { callback(Object.keys(d), d) })
        .fail(function(e) { console.log(e) })
    } },
  { label: 'Strain description',
    id: 'strain-description',
    description: ('Provide provide a full description of the strain. ' +
                  'Guidelines for describing mutations can be found ' +
                  '<a href="http://www.hgvs.org/mutnomen/recs.html" target="_blank" tabindex="-1">here</a>.'),
    required: true,
    example: 'e.g. Keio-crp, 76A>T, D111E, ΔF508, BOP8900(ΔadhE)' },
  { label: 'Growth Stage',
    id: 'growth-stage',
    example: 'mid-log' },
  { label: 'Sample Time',
    id: 'sample-time',
    type: 'time-minutes',
    description: 'Minutes from start of experiment.'},
  { label: 'Antibody',
    id: 'antibody',
    example: 'anti-CRP' },
  { label: 'Temperature',
    description: 'Temperature in Celcius',
    id: 'temperature',
    example: '37',
    form: 'ALE'},
  { label: 'Base Media',
    id: 'base-media',
    type: 'dropdown',
    required: true,
    custom: true,
    options: ['M9', 'LB'] },
  { label: 'Isolate  Type',
    id: 'isolate-type',
    type: 'dropdown',
    required: true,
    custom: true,
    options: ['clonal', 'population'] },
  { label: 'Carbon Source(s)',
    id: 'carbon-source',
    type: 'dropdown',
    multiple: true,
    custom: true,
    concentration_with_default: 2,
    options: ['Glucose', 'Fructose', 'Acetate', 'Galactose'] },
  { label: 'Nitrogen Source(s)',
    id: 'nitrogen-source',
    type: 'dropdown',
    multiple: true,
    custom: true,
    concentration_with_default: 1,
    options: ['NH4Cl', 'Glutamine', 'Glutamate'] },
  { label: 'Phosphorous Source(s)',
    id: 'phosphorous-source',
    type: 'dropdown',
    multiple: true,
    custom: true,
    concentration_with_default: 3,
    options: ['KH2PO4'] },
  { label: 'Sulfur Source(s)',
    id: 'Sulfur-source',
    type: 'dropdown',
    multiple: true,
    custom: true,
    concentration_with_default: 0.24,
    options: ['MgSO4'] },
  { label: 'Electron acceptor(s)',
    id: 'electron-acceptor',
    type: 'dropdown',
    options: ['O2', 'NO3', 'SO4'],
    concentration_with_default: 0,
    multiple: true,
    custom: true },
  { label: 'Other supplement(s)',
    id: 'supplement',
    type: 'dropdown',
    options: [],
    concentration_with_default: 1,
    multiple: true,
    custom: true },
  { label: 'Antibiotic(s) added',
    id: 'antibiotic',
    type: 'dropdown',
    custom: true,
    multiple: true,
    concentration_with_default: 1,
    options: ['Kanamycin', 'Spectinomycin', 'Streptomycin', 'Ampicillin',
              'Carbenicillin', 'Bleomycin', 'Erythromycin', 'Polymyxin B',
              'Tetracycline', 'Chloramphenicol'] },
  { label: 'ALE number',
    id: 'ALE-number',
    type: 'number',
    default: 1,
    min: 1,
    max: 100,
    form: 'ALE'},
  { label: 'Flask number',
    id: 'Flask-number',
    type: 'number',
    default: 1,
    min: 1,
    max: 100,
    form: 'ALE'},
  { label: 'Isolate number',
    id: 'Isolate-number',
    type: 'number',
    default: 1,
    min: 1,
    max: 100,
    form: 'ALE'},
  { label: 'Technical replicate number',
    id: 'technical-replicate-number',
    type: 'number',
    default: 1,
    min: 1,
    max: 100,
    form: 'ALE'},
  { label: 'Machine',
    id: 'machine',
    type: 'dropdown',
    custom: true,
    options: ['MiSeq', 'NextSeq', 'HiSeq'] },
  { label: 'Library Prep Kit Manufacturer',
    id: 'library-prep-kit-manufacturer',
    type: 'dropdown',
    custom: true,
    options: ['Illumina', 'Kapa'] },
  { label: 'Library Prep Kit Cycles',
    id: 'library-prep-kit-cycles',
    type: 'dropdown',
    custom: true,
    options: ['50 Cycle', '150 Cycle', '300 Cycle', '500 Cycle', '600 Cycle'] },
  { label: 'Single- or paired-end reads',
    id: 'read-type',
    type: 'dropdown',
    options: ['Single-end reads', 'Paired-end reads'] },
  { label: 'Read Length',
    id: 'read-length',
    type: 'dropdown',
    options: ['31', '36', '50', '62', '76', '100', '151', '301'],
    custom: true },
  { label: 'Sample Preparation and Experiment Details',
    id: 'experiment-details',
    type: 'textarea' },
  { label: 'Environment',
    description: 'Describe any other environmental parameters.',
    id: 'environment',
    form: 'Generic'},
  { label: 'Biological replicates',
    id: 'biological-replicates',
    type: 'number',
    default: 1,
    min: 1,
    max: 100,
    form: 'Generic'},
  { label: 'Technical replicates',
    id: 'technical-replicates',
    type: 'number',
    default: 1,
    min: 1,
    max: 100,
    form: 'Generic'}
]

var data_as_object = {}
data.forEach(function(d) { data_as_object[d.id] = d })
var workflow = 'Generic'


$(document).ready(function(){

  // add the uploader
  create_uploaders()

  create_form('Generic')

  // submit
  $('#submit').click(function(){
    if (!check_required()) return
    var data_array = get_data_array()
    if (workflow == 'Generic') {
      save_generic_metadata(data_array)
    } else {
      save_ale_metadata(data_array)
    }
  })

  $('#download_example').click(function(){
    var output_file_name = "ale_sample_names",
        example_output = [["1","1","0","1"],["\n1","1","1","1"],["\n1","1","2","1"]],
        file = new Blob(example_output, { type: 'text/plain;charset=utf-8' })
    saveAs(file, output_file_name + '.csv')
  })

})

function create_form(form_type) {

  workflow = form_type

  var center_column = $('#center-column')

  // Remove all child elements of center-column to start with blank sheet.
  while (center_column[0].firstChild) {
    center_column[0].removeChild(center_column[0].firstChild)
  }

  // Hide/show the Optional: Ale Specific Drag and drop CSV box
  if(form_type == 'Generic') {
    document.getElementById('csv_drag_and_drop').style.display = 'none'
    document.getElementById('generic_instructions').style.display = 'block'
    document.getElementById('folder-name-panel').style.display = 'block'
  } else {
    document.getElementById('csv_drag_and_drop').style.display = 'block'
    document.getElementById('generic_instructions').style.display = 'none'
    document.getElementById('folder-name-panel').style.display = 'none'
  }

  // add the form
  for(var i = 0; i < data.length; i++) {
    // add the input
    if (data[i]['form'] == form_type || data[i]['form'] == undefined) {
      create_input(data[i], center_column, i === 0)
    }
  }
}

function get_data_array() {
  var data_array = []
  for(var i = 0; i < data.length; i++){
    var val = get_value(data[i]['id'])
    data_array.push([data[i]['id'], val])
  }
  return data_array
}

function check_required() {
  if ($('.required.alert-danger').length !== 0) {
    $('#submit').get(0).disabled = true
    $('#required-to-submit').show()
    return false
  } else {
    $('#submit').get(0).disabled = false
    $('#required-to-submit').hide()
    return true
  }
}

function create_uploaders() {
  $('#file-upload').fileReaderJS({
    dragClass: 'drag',
    readAsDefault: 'Text',
    on: {
      load: handle_upload
    }
  });
  $('#name-file-upload').fileReaderJS({
    dragClass: 'drag',
    readAsDefault: 'Text',
    on: {
      load: handle_name_upload
    }
  })
}

function handle_upload(e, file) {
  var csv_data = e.target.result,
      arrays = new CSV(csv_data).parse()
  for (var i = 0; i < arrays.length; i++)
    set_value(arrays[i][0], arrays[i][1])
  check_required()
}


function get_zip_name() {

  return file_name = get_value('project').toString()
    + '_' + folder_name()
}


function get_file_name() {
  lib_prep = get_lib_prep_code(get_value('library-prep-kit-manufacturer').toString())
  if (lib_prep != '')
    lib_prep = '_' + lib_prep

  return file_name = get_value('project').toString()
    + lib_prep
    + '_'
    + get_value('ALE-number').toString()
    + '-' + get_value('Flask-number').toString()
    + '-' + get_value('Isolate-number').toString()
    + '-' + get_value('technical-replicate-number').toString()
}


const ALE_NUMBER_IDX = 0
const FLASK_NUMBER_IDX = 1
const ISOLATE_NUMBER_IDX = 2
const TECHNICAL_REPLICATE_IDX = 3

function handle_name_upload(e, file) {

  // fast fail
  if (!check_required())
    return

  var input_csv_data = e.target.result,
      variable_file_name_array = new CSV(input_csv_data).parse()

  var output_sample_name_array = []

  var zip = new JSZip()

  for (var name_idx = 0; name_idx < variable_file_name_array.length; name_idx++) {
    set_value('ALE-number', variable_file_name_array[name_idx][ALE_NUMBER_IDX])
    set_value('Flask-number', variable_file_name_array[name_idx][FLASK_NUMBER_IDX])
    set_value('Isolate-number', variable_file_name_array[name_idx][ISOLATE_NUMBER_IDX])
    set_value('technical-replicate-number',variable_file_name_array[name_idx][TECHNICAL_REPLICATE_IDX])

    file_name = get_file_name() + '.csv'
    output_sample_name_array.push([file_name])

    var output_sample_csv_data = [new CSV(get_data_array()).encode()]
    var output_sample_metadata_file = new Blob(output_sample_csv_data, { type: 'text/plain;charset=utf-8' })
    zip.folder("samples").file(file_name, output_sample_metadata_file)
  }

  var output_sample_name_csv_data = [new CSV(output_sample_name_array, {header: ["samples"]}).encode()]
  var output_sample_name_file = new Blob(output_sample_name_csv_data, { type: 'text/plain;charset=utf-8' })
  zip.file('samples.csv', output_sample_name_file)

  zip.generateAsync({type:"blob"})
    .then(function (blob) {
      saveAs(blob, get_zip_name() + '.zip')
    })
}


function folder_name() {
  var l = ['run-date', 'data-type'].map(function(el) {
    return get_value(el).replace(' ', '').replace(/\//g, '-')
  })
  return _.every(l) ? l.join('_') : ''
}


function update_folder_name() {
  $('#folder-name').val(folder_name())
}


function get_lib_prep_code(lib_prep_manufacturer) {
  lib_prep_code = ''
  if (lib_prep_manufacturer == 'Kapa')
    lib_prep_code = 'KHP'
  else if (lib_prep_manufacturer == 'Illumina')
    lib_prep_code = 'NXT'
  return lib_prep_code
}


function save_ale_metadata(array) {
  file_name = get_file_name()
  var csv_data = [new CSV(array).encode()]
  var file = new Blob(csv_data, {type: 'text/plain;charset=utf-8'})
  saveAs(file, file_name + '.csv')
}


function save_generic_metadata(array) {
  var label = folder_name(),
    csv = [new CSV(array).encode()],
    file = new Blob(csv, {type: 'text/plain;charset=utf-8'})
  saveAs(file, label + '.csv')
}


function get_value(id, input_only) {
  /** Get the value for the given input id */

  if (_.isUndefined(input_only))
    input_only = false

  // try to get concentrations
  var concentrations = {}
  $('#' + id).parent().find('.concentration-input>input').each(function() {
    var el = $(this),<commit_msg>Added library-prep-kit field and prep kit name acronym (#17)<commit_after>/* -*- Mode: js2; indent-tabs-mode: nil; js2-basic-offset: 2; -*- */
/* global $, Blob, saveAs, CSV, d3, JSZip, _ */
// CSV: https://github.com/knrz/CSV.js/

var data = [
  { label: 'Creator (Name)',
    id: 'creator',
    required: true,
    type: 'input',
    example: '<NAME>' },
  { label: 'Creator Email',
    id: 'creator-email',
    required: true,
    type: 'input',
    example: '<EMAIL>' },
  { label: 'Project Name',
    id: 'project',
    required: true,
    type: 'input' },
  { label: 'Data Type',
    id: 'data-type',
    type: 'dropdown',
    custom: true,
    default: 'DNA-seq',
    options: ['DNA-seq', 'RNA-seq', 'ChIP-seq', 'ChIP-exo', 'Ribo-seq'] },
  { label: 'Experiment Date (YYYY-MM-DD)',
    id: 'run-date',
    required: true,
    type: 'date',
    description: 'For sequencing experiments, use the date the sample was run.'},
  { label: 'NCBI Taxonomy ID for Strain',
    id: 'taxonomy-id',
    type: 'dropdown',
    custom: true,
    required: true,
    options_function: function(callback) {
      $.getJSON('ncbi_taxon_ids.json')
        .success(function(d) { callback(Object.keys(d), d) })
        .fail(function(e) { console.log(e) })
    } },
  { label: 'Strain description',
    id: 'strain-description',
    description: ('Provide provide a full description of the strain. ' +
                  'Guidelines for describing mutations can be found ' +
                  '<a href="http://www.hgvs.org/mutnomen/recs.html" target="_blank" tabindex="-1">here</a>.'),
    required: true,
    example: 'e.g. Keio-crp, 76A>T, D111E, ΔF508, BOP8900(ΔadhE)' },
  { label: 'Growth Stage',
    id: 'growth-stage',
    example: 'mid-log' },
  { label: 'Sample Time',
    id: 'sample-time',
    type: 'time-minutes',
    description: 'Minutes from start of experiment.'},
  { label: 'Antibody',
    id: 'antibody',
    example: 'anti-CRP' },
  { label: 'Temperature',
    description: 'Temperature in Celcius',
    id: 'temperature',
    example: '37',
    form: 'ALE'},
  { label: 'Base Media',
    id: 'base-media',
    type: 'dropdown',
    required: true,
    custom: true,
    options: ['M9', 'LB'] },
  { label: 'Isolate  Type',
    id: 'isolate-type',
    type: 'dropdown',
    required: true,
    custom: true,
    options: ['clonal', 'population'] },
  { label: 'Carbon Source(s)',
    id: 'carbon-source',
    type: 'dropdown',
    multiple: true,
    custom: true,
    concentration_with_default: 2,
    options: ['Glucose', 'Fructose', 'Acetate', 'Galactose'] },
  { label: 'Nitrogen Source(s)',
    id: 'nitrogen-source',
    type: 'dropdown',
    multiple: true,
    custom: true,
    concentration_with_default: 1,
    options: ['NH4Cl', 'Glutamine', 'Glutamate'] },
  { label: 'Phosphorous Source(s)',
    id: 'phosphorous-source',
    type: 'dropdown',
    multiple: true,
    custom: true,
    concentration_with_default: 3,
    options: ['KH2PO4'] },
  { label: 'Sulfur Source(s)',
    id: 'Sulfur-source',
    type: 'dropdown',
    multiple: true,
    custom: true,
    concentration_with_default: 0.24,
    options: ['MgSO4'] },
  { label: 'Electron acceptor(s)',
    id: 'electron-acceptor',
    type: 'dropdown',
    options: ['O2', 'NO3', 'SO4'],
    concentration_with_default: 0,
    multiple: true,
    custom: true },
  { label: 'Other supplement(s)',
    id: 'supplement',
    type: 'dropdown',
    options: [],
    concentration_with_default: 1,
    multiple: true,
    custom: true },
  { label: 'Antibiotic(s) added',
    id: 'antibiotic',
    type: 'dropdown',
    custom: true,
    multiple: true,
    concentration_with_default: 1,
    options: ['Kanamycin', 'Spectinomycin', 'Streptomycin', 'Ampicillin',
              'Carbenicillin', 'Bleomycin', 'Erythromycin', 'Polymyxin B',
              'Tetracycline', 'Chloramphenicol'] },
  { label: 'ALE number',
    id: 'ALE-number',
    type: 'number',
    default: 1,
    min: 1,
    max: 100,
    form: 'ALE'},
  { label: 'Flask number',
    id: 'Flask-number',
    type: 'number',
    default: 1,
    min: 1,
    max: 100,
    form: 'ALE'},
  { label: 'Isolate number',
    id: 'Isolate-number',
    type: 'number',
    default: 1,
    min: 1,
    max: 100,
    form: 'ALE'},
  { label: 'Technical replicate number',
    id: 'technical-replicate-number',
    type: 'number',
    default: 1,
    min: 1,
    max: 100,
    form: 'ALE'},
  { label: 'Machine',
    id: 'machine',
    type: 'dropdown',
    custom: true,
    options: ['MiSeq', 'NextSeq', 'HiSeq'] },
  { label: 'Library Prep Kit Manufacturer',
    id: 'library-prep-kit-manufacturer',
    type: 'dropdown',
    custom: true,
    options: ['Illumina', 'Kapa'] },
  { label: 'Library Prep Kit',
    id: 'library-prep-kit',
    type: 'dropdown',
    custom: true,
    options: ['Nextera XT', 'KAPA HyperPlus', 'KAPA Stranded RNA-seq'] },
  { label: 'Library Prep Kit Cycles',
    id: 'library-prep-kit-cycles',
    type: 'dropdown',
    custom: true,
    options: ['50 Cycle', '150 Cycle', '300 Cycle', '500 Cycle', '600 Cycle'] },
  { label: 'Single- or paired-end reads',
    id: 'read-type',
    type: 'dropdown',
    options: ['Single-end reads', 'Paired-end reads'] },
  { label: 'Read Length',
    id: 'read-length',
    type: 'dropdown',
    options: ['31', '36', '50', '62', '76', '100', '151', '301'],
    custom: true },
  { label: 'Sample Preparation and Experiment Details',
    id: 'experiment-details',
    type: 'textarea' },
  { label: 'Environment',
    description: 'Describe any other environmental parameters.',
    id: 'environment',
    form: 'Generic'},
  { label: 'Biological replicates',
    id: 'biological-replicates',
    type: 'number',
    default: 1,
    min: 1,
    max: 100,
    form: 'Generic'},
  { label: 'Technical replicates',
    id: 'technical-replicates',
    type: 'number',
    default: 1,
    min: 1,
    max: 100,
    form: 'Generic'}
]

var data_as_object = {}
data.forEach(function(d) { data_as_object[d.id] = d })
var workflow = 'Generic'


$(document).ready(function(){

  // add the uploader
  create_uploaders()

  create_form('Generic')

  // submit
  $('#submit').click(function(){
    if (!check_required()) return
    var data_array = get_data_array()
    if (workflow == 'Generic') {
      save_generic_metadata(data_array)
    } else {
      save_ale_metadata(data_array)
    }
  })

  $('#download_example').click(function(){
    var output_file_name = "ale_sample_names",
        example_output = [["1","1","0","1"],["\n1","1","1","1"],["\n1","1","2","1"]],
        file = new Blob(example_output, { type: 'text/plain;charset=utf-8' })
    saveAs(file, output_file_name + '.csv')
  })

})

function create_form(form_type) {

  workflow = form_type

  var center_column = $('#center-column')

  // Remove all child elements of center-column to start with blank sheet.
  while (center_column[0].firstChild) {
    center_column[0].removeChild(center_column[0].firstChild)
  }

  // Hide/show the Optional: Ale Specific Drag and drop CSV box
  if(form_type == 'Generic') {
    document.getElementById('csv_drag_and_drop').style.display = 'none'
    document.getElementById('generic_instructions').style.display = 'block'
    document.getElementById('folder-name-panel').style.display = 'block'
  } else {
    document.getElementById('csv_drag_and_drop').style.display = 'block'
    document.getElementById('generic_instructions').style.display = 'none'
    document.getElementById('folder-name-panel').style.display = 'none'
  }

  // add the form
  for(var i = 0; i < data.length; i++) {
    // add the input
    if (data[i]['form'] == form_type || data[i]['form'] == undefined) {
      create_input(data[i], center_column, i === 0)
    }
  }
}

function get_data_array() {
  var data_array = []
  for(var i = 0; i < data.length; i++){
    var val = get_value(data[i]['id'])
    data_array.push([data[i]['id'], val])
  }
  return data_array
}

function check_required() {
  if ($('.required.alert-danger').length !== 0) {
    $('#submit').get(0).disabled = true
    $('#required-to-submit').show()
    return false
  } else {
    $('#submit').get(0).disabled = false
    $('#required-to-submit').hide()
    return true
  }
}

function create_uploaders() {
  $('#file-upload').fileReaderJS({
    dragClass: 'drag',
    readAsDefault: 'Text',
    on: {
      load: handle_upload
    }
  });
  $('#name-file-upload').fileReaderJS({
    dragClass: 'drag',
    readAsDefault: 'Text',
    on: {
      load: handle_name_upload
    }
  })
}

function handle_upload(e, file) {
  var csv_data = e.target.result,
      arrays = new CSV(csv_data).parse()
  for (var i = 0; i < arrays.length; i++)
    set_value(arrays[i][0], arrays[i][1])
  check_required()
}


function get_zip_name() {

  return file_name = get_value('project').toString()
    + '_' + folder_name()
}


function get_file_name() {
  lib_prep = get_lib_prep_code(get_value('library-prep-kit').toString())
  if (lib_prep != '')
    lib_prep = '_' + lib_prep

  return file_name = get_value('project').toString()
    + lib_prep
    + '_'
    + get_value('ALE-number').toString()
    + '-' + get_value('Flask-number').toString()
    + '-' + get_value('Isolate-number').toString()
    + '-' + get_value('technical-replicate-number').toString()
}


const ALE_NUMBER_IDX = 0
const FLASK_NUMBER_IDX = 1
const ISOLATE_NUMBER_IDX = 2
const TECHNICAL_REPLICATE_IDX = 3

function handle_name_upload(e, file) {

  // fast fail
  if (!check_required())
    return

  var input_csv_data = e.target.result,
      variable_file_name_array = new CSV(input_csv_data).parse()

  var output_sample_name_array = []

  var zip = new JSZip()

  for (var name_idx = 0; name_idx < variable_file_name_array.length; name_idx++) {
    set_value('ALE-number', variable_file_name_array[name_idx][ALE_NUMBER_IDX])
    set_value('Flask-number', variable_file_name_array[name_idx][FLASK_NUMBER_IDX])
    set_value('Isolate-number', variable_file_name_array[name_idx][ISOLATE_NUMBER_IDX])
    set_value('technical-replicate-number',variable_file_name_array[name_idx][TECHNICAL_REPLICATE_IDX])

    file_name = get_file_name() + '.csv'
    output_sample_name_array.push([file_name])

    var output_sample_csv_data = [new CSV(get_data_array()).encode()]
    var output_sample_metadata_file = new Blob(output_sample_csv_data, { type: 'text/plain;charset=utf-8' })
    zip.folder("samples").file(file_name, output_sample_metadata_file)
  }

  var output_sample_name_csv_data = [new CSV(output_sample_name_array, {header: ["samples"]}).encode()]
  var output_sample_name_file = new Blob(output_sample_name_csv_data, { type: 'text/plain;charset=utf-8' })
  zip.file('samples.csv', output_sample_name_file)

  zip.generateAsync({type:"blob"})
    .then(function (blob) {
      saveAs(blob, get_zip_name() + '.zip')
    })
}


function folder_name() {
  var l = ['run-date', 'data-type'].map(function(el) {
    return get_value(el).replace(' ', '').replace(/\//g, '-')
  })
  return _.every(l) ? l.join('_') : ''
}


function update_folder_name() {
  $('#folder-name').val(folder_name())
}


function get_lib_prep_code(lib_prep_kit) {
  lib_prep_code = ''
  if (lib_prep_kit == 'Nextera XT')
    lib_prep_code = 'NXT'
  else if (lib_prep_kit == 'KAPA HyperPlus')
    lib_prep_code = 'KHP'
  else if (lib_prep_kit == 'KAPA Stranded RNA-seq')
    lib_prep_code = 'KSR'
  return lib_prep_code
}


function save_ale_metadata(array) {
  file_name = get_file_name()
  var csv_data = [new CSV(array).encode()]
  var file = new Blob(csv_data, {type: 'text/plain;charset=utf-8'})
  saveAs(file, file_name + '.csv')
}


function save_generic_metadata(array) {
  var label = folder_name(),
    csv = [new CSV(array).encode()],
    file = new Blob(csv, {type: 'text/plain;charset=utf-8'})
  saveAs(file, label + '.csv')
}


function get_value(id, input_only) {
  /** Get the value for the given input id */

  if (_.isUndefined(input_only))
    input_only = false

  // try to get concentrations
  var concentrations = {}
  $('#' + id).parent().find('.concentration-input>input').each(function() {
    var el = $(this),
{'fraction_non_alphanumeric': 0.17263395092638958, 'fraction_numerical': 0.011183441829410784, 'mean_word_length': 3.4478470675575354, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 15, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6084132', 'n_tokens_mistral': 8757, 'n_tokens_neox': 8309, 'n_words': 1823}