<commit_before>#!/usr/bin/env bash
#BSUB -J coverage[1-5]%5
#BSUB -e logs/coverage_%J.log
#BSUB -o logs/coverage_%J.out
#BSUB -R "select[mem>40] rusage[mem=40]"
#BSUB -q normal
#BSUB -P Sikela

# catch unset variables, non-zero exits in pipes and calls, enable x-trace.
set -o nounset -o pipefail -o errexit -x

source code/config.sh

# LSB_JOBINDEX is the job array position
sample=${SAMPLES[$(($LSB_JOBINDEX - 1))]}

bam_file=$alignment_dir/${sample}
bed_file=$bed_dir/$sample

## Convert alignment file to a bed format
samtools sort -n -@ 5 -m 5G $bam_file.bam ${bam_file}_sorted
bedtools bamtobed -bedpe -split -i ${bam_file}_sorted.bam > $bed_file.bed

# remove alignment files if bed has correct number of reads
code/clean_files.pl -a $alignment_dir -b $bed_dir --rm_fastq $sample

# Merge reads into fragments
code/parse_bed.pl $bed_file.bed
sort -k 1,1 -k 2,2n -T $bed_dir/ ${bed_file}_edited.bed > ${bed_file}_sorted.bed

# Calcualte coverage
bedtools intersect -wao -sorted -a $master_ref -b ${bed_file}_sorted.bed > ${bed_file}_temp.bed
awk 'OFS="\t" {print $4,$2,$3,$1,$13}' ${bed_file}_temp.bed | bedtools merge -scores sum -i - > ${bed_file}_coverage.bed
awk 'OFS="\t" { print $1, $4 / ($3 - $2 + 1)}' ${bed_file}_coverage.bed > ${bed_file}_read_depth.bed

rm ${bed_file}_temp.bed


<commit_msg>refactor the batch_make bed script to use new system<commit_after>#!/usr/bin/env bash
#BSUB -J coverage[1-300]%5
#BSUB -e logs/coverage_%J.log
#BSUB -o logs/coverage_%J.out
#BSUB -R "select[mem>40] rusage[mem=40]"
#BSUB -q normal
#BSUB -P Sikela

# catch unset variables, non-zero exits in pipes and calls, enable x-trace.
set -o nounset -o pipefail -o errexit -x

source code/config.sh

# LSB_JOBINDEX is the job array position
sample=${SAMPLES[$(($LSB_JOBINDEX - 1))]}

bam_file=$alignment_dir/${sample}
bed_file=$bed_dir/$sample

code/make_bed.sh -r $master_ref -p "paired" -b $bam_file -o $bed_file

{'fraction_non_alphanumeric': 0.15010460251046026, 'fraction_numerical': 0.018305439330543932, 'mean_word_length': 4.497126436781609, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, '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': '5072768', 'n_tokens_mistral': 796, 'n_tokens_neox': 768, 'n_words': 209}