<commit_before><commit_msg>Add script to normalize bed files<commit_after>#!/usr/bin/env perl
#-------------------------------------------------------------------------------
# Purpose:  Normalize the score in a BED file to log10 percent (0<=x<=1).
# Usage:    samtools -D file.bam | pileup_to_bed.pl
# Author:   mdb
# Created:  2/24/14 for qTeller integration pipeline
#-------------------------------------------------------------------------------

use strict;

my $filename = shift;
open(my $fh, $filename);

# Determine max score
my $maxScore = 0;
while (<$fh>) {
    my @col = split("\t", $_);
    my $score = normalize($col[4]);
    $maxScore = $score if ($score > $maxScore);
}

# Generate normalized output
seek($fh, 0, 0);
while (<$fh>) {
    my @col = split("\t", $_);
    if ($maxScore > 0) {
        $col[4] = normalize($col[4]) / $maxScore;
    }
    print join("\t", @col);
}

close($fh);
exit;

#-------------------------------------------------------------------------------
sub normalize {
    my $n = shift;
    return log10(abs($n)+1);
}

sub log10 {
    my $n = shift;
    return log($n)/log(10);
}

{'fraction_non_alphanumeric': 0.35625, 'fraction_numerical': 0.020535714285714286, 'mean_word_length': 1.5078299776286352, 'pattern_counts': {'":': 0, '<': 7, '<?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': '6240728', 'n_tokens_mistral': 362, 'n_tokens_neox': 336, 'n_words': 95}