Skip to content

Instantly share code, notes, and snippets.

View davetang's full-sized avatar
🦀
🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀

Dave Tang davetang

🦀
🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀
View GitHub Profile
#!/bin/env perl
use strict;
use warnings;
my $usage = "Usage: $0 <bam_flag>\n";
my $flag = shift or die $usage;
die "Please enter a numerical value\n" if $flag =~ /\D+/;
@davetang
davetang / mandelbrot.pl
Created May 13, 2014 12:41
The Mandelbrot set is a mathematical set of points whose boundary is a distinctive and easily recognizable two-dimensional fractal shape
#!/usr/bin/perl
use warnings;
use strict;
my $BAILOUT=16;
my $MAX_ITERATIONS=1000;
my $begin = time();
#!/usr/bin/env perl
use strict;
use warnings;
my $usage = "Usage: $0 <bp> <seed>\n";
my $num = shift or die $usage;
my $seed = shift or die $usage;
#set seed for reproducibility
#!/usr/bin/env perl
use strict;
use warnings;
my $usage = "Usage: $0 <infile.fa> <number> <length>\n";
my $fasta = shift or die $usage;
my $num = shift or die $usage;
my $len = shift or die $usage;
@davetang
davetang / compare_list.pl
Last active August 29, 2015 14:22
Script that compares two files of IDs, that are on separate lines
#!/usr/bin/env perl
#
# Script that compares two files of IDs, that are on separate lines
# See http://stackoverflow.com/questions/2933347/comparing-two-arrays-using-perl
#
use strict;
use warnings;
use Array::Utils qw(:all);
@davetang
davetang / random_paired_end.pl
Last active August 29, 2015 14:22
A script that takes an input fasta and generates properly paired reads
#!/usr/bin/env perl
# Simple script that takes an input fasta sequence
# and generates paired end reads
use strict;
use warnings;
my $usage = "Usage: $0 <infile.fa> <read length> <number of pairs> <inner mate distance> <seed>\n";
my $fasta = shift or die $usage;
@davetang
davetang / tsv_sum.pl
Last active September 4, 2015 05:26
Sums the rows and columns of a tab-delimited file
#!/usr/bin/env perl
#
# Reads a tab-delimited file with column and row names
# sums the rows and columns and outputs a tab-delimited
# file with an extra row and column for the sums
#
use strict;
use warnings;
@davetang
davetang / first.pl
Last active December 22, 2015 09:29
My very first Gist
#!/bin/env perl
use strict;
use warnings;
print "My very first Gist on GitHub!\n";
exit(0);
__END__
@davetang
davetang / permutation_with_replacement.R
Created September 8, 2013 14:23
Calculating the number of permutations with repetition/replacement
#install if necessary
install.packages('gtools')
#load library
library(gtools)
#urn with 3 balls
x <- c('red', 'blue', 'black')
#pick 2 balls from the urn with replacement
#get all permutations
permutations(n=3,r=2,v=x,repeats.allowed=T)
# [,1] [,2]
@davetang
davetang / bam_df_to_coverage.R
Last active December 22, 2015 14:19
After storing a BAM file as a data frame (as per https://gist.github.com/davetang/6460320), we can calculate the coverage of mapped reads by using a density plot
#use chr22 as an example
#how many entries on the negative strand of chr22?
table(bam_df$rname == 'chr22' & bam_df$flag == 16)
# FALSE TRUE
#3875997 24413
#function for checking negative strand
check_neg <- function(x){
if (intToBits(x)[5] == 1){
return(T)