Skip to content

Instantly share code, notes, and snippets.

View brianhill11's full-sized avatar

Brian Hill brianhill11

View GitHub Profile
@brianhill11
brianhill11 / categorical_encoder.py
Last active August 15, 2022 13:46
Aggregate one-hot encoded vectors for multiple column values mapping to same primary key
"""
Requires Pandas, Numpy
Example:
In: data = {"primary_key": ["a", "a", "a", "b", "b", "b", "b", "c", "c"],
"target": ["x", "y", "z", "w", "x", "y", "z", "t", "u"]}
In: example_df = pd.DataFrame.from_dict(data)
Out:
primary_key target
@brianhill11
brianhill11 / fix_haploid_calls.py
Last active August 24, 2018 16:27
Finds haploid genotype calls and turns them into homozygous diploid calls
#/usr/bin/python
from pysam import VariantFile
import sys
import os
import argparse
parser = argparse.ArgumentParser()
bcf_in = VariantFile(sys.argv[1], 'r')
@brianhill11
brianhill11 / split_dir_create_softlinks.sh
Created August 1, 2018 16:43
Script splits a large directory with many files into subdirectories, and makes soft links from the original files to the new split directories (for batch processing in parallel)
@brianhill11
brianhill11 / split_bam.py
Last active March 27, 2023 09:16
Script to split input BAM file randomly (without replacement) into two BAM files; REQUIRES: pysam, numpy
import numpy as np
import os
import pysam
import argparse
import errno
def main():
parser = argparse.ArgumentParser(description="Splits BAM file into two BAM files, putting p reads into one BAM and (1-p) into the other")
parser.add_argument('-b', '--bam-file', dest='bam_file', required=True, help='Input BAM file')
@brianhill11
brianhill11 / diff_two_file_lists.py
Last active May 16, 2017 02:27
Get lines that appear in one file but not the other, useful for finding missing files when copying/transferring big batches of files.
#!/usr/bin/python
import sys
import os
from sets import Set
def create_file_set(filename, file_extension):
with open(filename, "r") as in_f:
result_set = Set()
for line in in_f:
@brianhill11
brianhill11 / convert_sra2fastq.sh
Created November 19, 2016 05:08
Script to convert all .sra files in a directory to .fastq.gz files in batches
#!/usr/bin/bash
# used to set time zone for logging date/time
export TZ=":America/Los_Angeles" date
# sets max number of processes to launch in a batch
MAX_NUM_PROCS=24
# directory holding the .sra files
SRA_FILES=/hdfs1/FlintData/*.sra
# directory to save the .fastq files to
`timescale 1ns/100ps
module relu_backward_layer_tb();
`include "/home/b/FPGA-CNN/test/test_data/relu_backward_test_data.vh"
parameter CYCLE = 5; //clk period: 5ns = 200Mhz signal
parameter NEG_SLOPE = 0.0; //negative slope param
parameter WIDTH = 8; //width of input/output vec
parameter NUM_TESTS = 4000; //number of test iterations
parameter MEM_SIZE = NUM_TESTS*WIDTH;
`timescale 1ns/100ps
module conv_forward_layer_tb();
`include "/home/b/FPGA-CNN/test/test_data/conv_forward_test_data.vh"
parameter CYCLE = 5; //clk period: 5ns = 200 Mhz
parameter MULT_DELAY = 5; //#clks to complete a mult
parameter ADD_DELAY = 7; //#clks to complete an add
parameter WIDTH = 8; //input vector width
parameter NUM_TESTS = 5000;
`ifndef RELU_BACKWARD_TEST_H
`define RELU_BACKWARD_TEST_H
reg [31:0] test_input [32];
reg [31:0] test_output [32];
initial begin
test_input[0:7] = '{32'h4263335c, 32'h40c5e004, 32'hc10ecd76, 32'hc234574d, 32'h429a1ec3, 32'hc29511fd, 32'hc230bfa6, 32'hc1e3c527};
test_output[0:7] = '{32'h4263335c, 32'h40c5e004, 32'h0, 32'h0, 32'h429a1ec3, 32'h0, 32'h0, 32'h0};
//############ DEBUG ############
test_input[0:7] = '{56.8001540825, 6.1835958546, -8.92516122294, -45.0852558653, 77.0600843176, -74.5351342745, -44.1871555525, -28.4712667127};
test_output[0:7] = '{56.8001540825, 6.1835958546, 0.0, 0.0, 77.0600843176, 0.0, 0.0, 0.0};
`ifndef CONV_FORWARD_TEST_H
`define CONV_FORWARD_TEST_H
reg [31:0] test_input [32];
reg [31:0] test_weights [32];
reg [31:0] test_bias [4];
reg [31:0] test_output [4];
initial begin
test_input[0:7] = '{32'h42bc08ea, 32'hc117d9b4, 32'h41b9931d, 32'hc1886216, 32'hc0d38e20, 32'hc2748491, 32'hc29456ce, 32'h42a2e80b};
test_weights[0:7] = '{32'h42bbbbd4, 32'hc1604072, 32'hc1e94116, 32'h4110a30e, 32'h4199d5f3, 32'hc2611d3f, 32'hc2bcf717, 32'hc189631a};
test_bias[0] = '{32'h0};