Skip to content

Instantly share code, notes, and snippets.

View dvanic's full-sized avatar

Darya Vanichkina dvanic

View GitHub Profile
@dvanic
dvanic / readGTF.py
Last active August 15, 2016 06:26
pythonReadGTFlocal
from collections import defaultdict
import gzip
import pandas as pd
import re
GTF_HEADER = ['seqname', 'source', 'feature', 'start', 'end', 'score',
'strand', 'frame']
R_SEMICOLON = re.compile(r'\s*;\s*')
R_COMMA = re.compile(r'\s*,\s*')
@dvanic
dvanic / cigarfunction.r
Created July 29, 2016 07:26
R gist to summarise CIGAR string
matcher <- function(pattern, x) {
ind = gregexpr(pattern, x)[[1]]
start = as.numeric(ind)
end = start + attr(ind, "match.length")- 2
apply(cbind(start,end), 1, function(y) substr(x, start=y[1], stop=y[2]));
}
doone <- function(c, cigar) {
pat <- paste("\\d+", c , sep="")
sum(as.numeric(matcher(pat, cigar)), na.rm=T)
@dvanic
dvanic / char2var.R
Last active September 20, 2016 04:12
Character to variable and variable to character conversion #R
# Variable name to character
deparse(substitute(variable))
"variable"
# Character to variable
eval(as.name("variable"))