<commit_before>#!/usr/bin/env bash

koopa::_salmon_index() { # {{{1
    # """
    # Generate salmon index.
    # @note Updated 2020-06-29.
    # """
    local fasta_file index_dir log_file threads
    koopa::assert_has_args "$#"
    koopa::assert_is_installed salmon
    while (("$#"))
    do
        case "$1" in
            --fasta-file=*)
                fasta_file="${1#*=}"
                shift 1
                ;;
            --index-dir=*)
                index_dir="${1#*=}"
                shift 1
                ;;
            *)
                koopa::invalid_arg "$1"
                ;;
        esac
    done
    koopa::assert_is_set fasta_file index_dir
    koopa::assert_is_file "$fasta_file"
    if [[ -d "$index_dir" ]]
    then
        koopa::note "Index exists at '${index_dir}'. Skipping."
        return 0
    fi
    koopa::h2 "Generating salmon index at '${index_dir}'."
    threads="$(koopa::cpu_count)"
    koopa::dl 'Threads' "$threads"
    log_file="$(dirname "$index_dir")/salmon-index.log"
    koopa::mkdir "$index_dir"
    salmon index \
        -k 31 \
        -p "$threads" \
        -i "$index_dir" \
        -t "$fasta_file" \
        2>&1 | tee "$log_file"
    return 0
}

koopa::_salmon_quant() { # {{{1
    # """
    # Run salmon quant.
    # @note Updated 2020-07-07.
    # """
    local bootstraps fastq_r1 fastq_r1_bn fastq_r2 fastq_r2_bn id index_dir \
        log_file output_dir r1_tail r2_tail sample_output_dir threads
    koopa::assert_has_args "$#"
    koopa::assert_is_installed salmon
    while (("$#"))
    do
        case "$1" in
            --fastq-r1=*)
                fastq_r1="${1#*=}"
                shift 1
                ;;
            --fastq-r2=*)
                fastq_r2="${1#*=}"
                shift 1
                ;;
            --index-dir=*)
                index_dir="${1#*=}"
                shift 1
                ;;
            --output-dir=*)
                output_dir="${1#*=}"
                shift 1
                ;;
            --r1-tail=*)
                r1_tail="${1#*=}"
                shift 1
                ;;
            --r2-tail=*)
                r2_tail="${1#*=}"
                shift 1
                ;;
            *)
                koopa::invalid_arg "$1"
                ;;
        esac
    done
    koopa::assert_is_set fastq_r1 fastq_r2 index_dir output_dir r1_tail r2_tail
    koopa::assert_is_file "$fastq_r1" "$fastq_r2"
    fastq_r1_bn="$(basename "$fastq_r1")"
    fastq_r1_bn="${fastq_r1_bn/${r1_tail}/}"
    fastq_r2_bn="$(basename "$fastq_r2")"
    fastq_r2_bn="${fastq_r2_bn/${r2_tail}/}"
    koopa::assert_are_identical "$fastq_r1_bn" "$fastq_r2_bn"
    id="$fastq_r1_bn"
    sample_output_dir="${output_dir}/${id}"
    if [[ -d "$sample_output_dir" ]]
    then
        koopa::note "Skipping '${id}'."
        return 0
    fi
    koopa::h2 "Quantifying '${id}' into '${sample_output_dir}'."
    bootstraps=30
    koopa::dl 'Bootstraps' "$bootstraps"
    threads="$(koopa::cpu_count)"
    koopa::dl 'Threads' "$threads"
    log_file="${sample_output_dir}/salmon-quant.log"
    koopa::mkdir "$sample_output_dir"
    salmon quant \
        --gcBias \
        --index="$index_dir" \
        --libType="A" \
        --mates1="$fastq_r1" \
        --mates2="$fastq_r2" \
        --numBootstraps="$bootstraps" \
        --output="$sample_output_dir" \
        --seqBias \
        --threads="$threads" \
        2>&1 | tee "$log_file"
    return 0
}

koopa::salmon() { # {{{1
    local fastq_dir fastq_r1_files output_dir r1_tail r2_tail
    koopa::assert_has_args "$#"
    fastq_dir='fastq'
    output_dir='salmon'
    r1_tail='_R1_001.fastq.gz'
    r2_tail='_R2_001.fastq.gz'<commit_msg>Add '--posBias' flag<commit_after>#!/usr/bin/env bash

koopa::_salmon_index() { # {{{1
    # """
    # Generate salmon index.
    # @note Updated 2020-06-29.
    # """
    local fasta_file index_dir log_file threads
    koopa::assert_has_args "$#"
    koopa::assert_is_installed salmon
    while (("$#"))
    do
        case "$1" in
            --fasta-file=*)
                fasta_file="${1#*=}"
                shift 1
                ;;
            --index-dir=*)
                index_dir="${1#*=}"
                shift 1
                ;;
            *)
                koopa::invalid_arg "$1"
                ;;
        esac
    done
    koopa::assert_is_set fasta_file index_dir
    koopa::assert_is_file "$fasta_file"
    if [[ -d "$index_dir" ]]
    then
        koopa::note "Index exists at '${index_dir}'. Skipping."
        return 0
    fi
    koopa::h2 "Generating salmon index at '${index_dir}'."
    threads="$(koopa::cpu_count)"
    koopa::dl 'Threads' "$threads"
    log_file="$(dirname "$index_dir")/salmon-index.log"
    koopa::mkdir "$index_dir"
    salmon index \
        -k 31 \
        -p "$threads" \
        -i "$index_dir" \
        -t "$fasta_file" \
        2>&1 | tee "$log_file"
    return 0
}

koopa::_salmon_quant() { # {{{1
    # """
    # Run salmon quant.
    # @note Updated 2020-07-07.
    # """
    local bootstraps fastq_r1 fastq_r1_bn fastq_r2 fastq_r2_bn id index_dir \
        log_file output_dir r1_tail r2_tail sample_output_dir threads
    koopa::assert_has_args "$#"
    koopa::assert_is_installed salmon
    while (("$#"))
    do
        case "$1" in
            --fastq-r1=*)
                fastq_r1="${1#*=}"
                shift 1
                ;;
            --fastq-r2=*)
                fastq_r2="${1#*=}"
                shift 1
                ;;
            --index-dir=*)
                index_dir="${1#*=}"
                shift 1
                ;;
            --output-dir=*)
                output_dir="${1#*=}"
                shift 1
                ;;
            --r1-tail=*)
                r1_tail="${1#*=}"
                shift 1
                ;;
            --r2-tail=*)
                r2_tail="${1#*=}"
                shift 1
                ;;
            *)
                koopa::invalid_arg "$1"
                ;;
        esac
    done
    koopa::assert_is_set fastq_r1 fastq_r2 index_dir output_dir r1_tail r2_tail
    koopa::assert_is_file "$fastq_r1" "$fastq_r2"
    fastq_r1_bn="$(basename "$fastq_r1")"
    fastq_r1_bn="${fastq_r1_bn/${r1_tail}/}"
    fastq_r2_bn="$(basename "$fastq_r2")"
    fastq_r2_bn="${fastq_r2_bn/${r2_tail}/}"
    koopa::assert_are_identical "$fastq_r1_bn" "$fastq_r2_bn"
    id="$fastq_r1_bn"
    sample_output_dir="${output_dir}/${id}"
    if [[ -d "$sample_output_dir" ]]
    then
        koopa::note "Skipping '${id}'."
        return 0
    fi
    koopa::h2 "Quantifying '${id}' into '${sample_output_dir}'."
    bootstraps=30
    koopa::dl 'Bootstraps' "$bootstraps"
    threads="$(koopa::cpu_count)"
    koopa::dl 'Threads' "$threads"
    log_file="${sample_output_dir}/salmon-quant.log"
    koopa::mkdir "$sample_output_dir"
    salmon quant \
        --gcBias \
        --index="$index_dir" \
        --libType='A' \
        --mates1="$fastq_r1" \
        --mates2="$fastq_r2" \
        --numBootstraps="$bootstraps" \
        --output="$sample_output_dir" \
        --posBias \
        --seqBias \
        --threads="$threads" \
        2>&1 | tee "$log_file"
    return 0
}

koopa::salmon() { # {{{1
    local fastq_dir fastq_r1_files output_dir r1_tail r2_tail
    koopa::assert_has_args "$#"
    fastq_dir='fastq'
    output_dir='salmon'
    r1_tail='_R1_001.fastq.gz'
    r2_tail='_R2_001.fastq.gz'
{'fraction_non_alphanumeric': 0.15627944541661057, 'fraction_numerical': 0.02772916947099206, 'mean_word_length': 1.6978939724037763, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '1346406', 'n_tokens_mistral': 2843, 'n_tokens_neox': 2610, 'n_words': 434}