Skip to content

Instantly share code, notes, and snippets.

View al2na's full-sized avatar
💭
fishing 🎣

Altuna Akalin al2na

💭
fishing 🎣
View GitHub Profile
@al2na
al2na / uniteByChr.R
Created February 6, 2014 22:19
methylKit unite chromosome by chromosome
subsetByChr<-function(methylRawList.obj,my.chr="chr21"){
sub=lapply(methylRawList.obj, function(x) x[x$chr==my.chr] )
new("methylRawList",sub,treatment=methylRawList.obj@treatment)
}
my.chrs= unique(methylRawList.obj[[1]]$chr)
@al2na
al2na / readTableFast.R
Last active August 29, 2015 13:56
read.table faster with known column classes and data.table::fread. I wonder which one is
.readTableFast<-function(filename,header=T,skip=0,sep="")
{
tab5rows <- read.table(filename, header = header,skip=skip,sep=sep,
nrows = 100,stringsAsFactors=FALSE)
classes <- sapply(tab5rows, class)
classes[classes=="logical"]="character"
return( read.table(filename, header = header,skip=skip,sep=sep,
colClasses = classes) )
}
@al2na
al2na / meanMethGroup.R
Created September 27, 2014 17:34
get mean methylation per group from a methylBase object
# returns a matrix of mean methylation values for groups defined
# by treatment vector in the methylBase obj
meanMethGroup<-function(methylBase.obj,weighted=TRUE ){
data=getData(methylBase.obj) # get data frame part of the object
treatment=methylBase.obj@treatment # get the treatment vector from the object
# create the the empty resulting matrix
result=matrix(0,ncol=length(unique(methylBase.obj@treatment)) ,nrow=nrow(methylBase.obj) )
colnames(result)=paste('group',unique(treatment),sep='') # column names are from treatmet vector
@al2na
al2na / mread.methylKit.R
Last active August 29, 2015 14:08
faster read for methylKit using fread from data.table package
require(data.table)
.structureAMPoutput<-function(data)
{
strand=rep("+",nrow(data))
strand[data[,4]=="R"]="-"
numCs=round(data[,5]*data[,6]/100)
numTs=round(data[,5]*data[,7]/100)
data.frame(chr=data[,2],start=data[,3],end=data[,3]
,strand=strand,coverage=data[,5],numCs=numCs,numTs=numTs)
#!/bin/bash
#$ -N run_bowtie
#$ -cwd
#$ -pe smp 2
#$ -l h_vmem=6G
infile=/data/bioinfo/genome_data/sample.ce10.fastq
outfile=~/my.alignment.sam
btindex=/data/bioinfo/genome_data/Caenorhabditis_elegans/UCSC/ce10/Sequence/BowtieIndex/genome

This document shows how to use packrat to create reproducible R projects. packrat allows reproducuiblty of R code in an OS independent manner. First we need to install the packrat package.

install.packages("packrat")
setwd("~/mdc_desktop_projects/packrat_trial3")

now we can initialize the packrat project. This will create local directories for packages and .Rprofile file. Whenever we run R in this directory, we will be using locally installed R packages and even if we copy this directory to some other computer (even with different OS) we will still have the same setup.

@al2na
al2na / scatterNVD3.R
Last active August 29, 2015 14:19
rcharts NVD3 scatterplot with different shapes and color code adjustment. Works in reveal.js slides
y=readRDS("data/othersmRNA.pca.table.rds")
p1=nPlot(PC2 ~ PC1, data = y,group="cellDisease", type = "scatterChart",
filter="disease")
p1$xAxis(axisLabel = 'PC1')
p1$yAxis(axisLabel = 'PC2')
p1$chart(color = y$color) # color for each dot
p1$chart(sizeRange = c(100,100)) # for dot sizes
@al2na
al2na / methSegDemo.R
Last active August 29, 2015 14:23
methseg usage and installation
download.file("https://dl.dropboxusercontent.com/u/1373164/H1.chr21.chr22.rds",destfile="H1.chr21.chr22.rds",method="curl")
mbw=readRDS("H1.chr21.chr22.rds")
# it finds the optimal number of componets as 6
res=methSeg(mbw,diagnostic.plot=TRUE,maxInt=100,minSeg=10)
# however the BIC stabilizes after 4, we can also try 4 componets
res=methSeg(mbw,diagnostic.plot=TRUE,maxInt=100,minSeg=10,G=1:4)
# get segments to BED file
@al2na
al2na / .gitignore
Created September 28, 2015 10:00 — forked from hadley/.gitignore
Benchmark different ways of reading a file
.Rproj.user
.Rhistory
.RData
*.Rproj
*.html