This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# install the Rsamtools package if necessary | |
source("http://bioconductor.org/biocLite.R") | |
biocLite("Rsamtools") | |
# load the library | |
library(Rsamtools) | |
# specify the bam file you want to import | |
bamFile <- "test.bam" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# resource: http://seqanswers.com/forums/showthread.php?t=4914 | |
# Calculate length for each transcript for a GTF file | |
awk -F"\t" ' | |
$3=="exon" | |
{ | |
ID=substr($9, length($9)-16, 15); | |
L[ID]+=$5-$4+1 | |
} | |
END{ | |
for(i in L) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## RNA-seq analysis with DESeq2 | |
## Stephen Turner, @genetics_blog | |
# RNA-seq data from GSE52202 | |
# http://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=gse52202. All patients with | |
# ALS, 4 with C9 expansion ("exp"), 4 controls without expansion ("ctl") | |
# Import & pre-process ---------------------------------------------------- | |
# Import data from featureCounts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A function (borrowed from the Sleuth documentation) for connecting Ensembl transcript names to common gene names | |
convert_tx_to_gene <- function(dat="drerio_gene_ensembl"){ | |
mart <- biomaRt::useMart( | |
biomart = "ensembl", | |
dataset = dat | |
) | |
t2g <- biomaRt::getBM( | |
attributes = c("ensembl_transcript_id", "ensembl_gene_id", "external_gene_name"), | |
mart = mart |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@SQ SN:chrM LN:16571 | |
@SQ SN:chr1 LN:249250621 | |
@SQ SN:chr2 LN:243199373 | |
@SQ SN:chr3 LN:198022430 | |
@SQ SN:chr4 LN:191154276 | |
@SQ SN:chr5 LN:180915260 | |
@SQ SN:chr6 LN:171115067 | |
@SQ SN:chr7 LN:159138663 | |
@SQ SN:chr8 LN:146364022 | |
@SQ SN:chr9 LN:141213431 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### My favourite ggplot2 themes, always accessible ### | |
## just source this gist from any project ## | |
##################################################################################### | |
# Noam's default ggplot2 styling ##### | |
# Source: https://github.com/noamross/noamtools/blob/master/R/theme_nr.R | |
theme_nr <-theme(text=element_text(family="Helvetica", size=14), | |
panel.grid.major.x=element_blank(), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Multiple plot function | |
# | |
# ggplot objects can be passed in ..., or to plotlist (as a list of ggplot objects) | |
# - cols: Number of columns in layout | |
# - layout: A matrix specifying the layout. If present, 'cols' is ignored. | |
# | |
# If the layout is something like matrix(c(1,2,3,3), nrow=2, byrow=TRUE), | |
# then plot 1 will go in the upper left, 2 will go in the upper right, and | |
# 3 will go all the way across the bottom. | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
swatch <- function(x) { | |
# x: a vector of colours (hex, numeric, or string) | |
par(mai=c(0.2, max(strwidth(x, "inch") + 0.4, na.rm = TRUE), 0.2, 0.4)) | |
barplot(rep(1, length(x)), col=rev(x), space = 0.1, axes=FALSE, | |
names.arg=rev(x), cex.names=0.8, horiz=T, las=1) | |
} | |
# Example: | |
# swatch(colours()[1:10]) | |
# swatch(iwanthue(5)) |