Skip to content

Instantly share code, notes, and snippets.

View Balharbi's full-sized avatar
💭
@mengyang2000 your coding style very intresting, mind if I ask abt repo DSS

Bader Alharbi Balharbi

💭
@mengyang2000 your coding style very intresting, mind if I ask abt repo DSS
  • Virginia
View GitHub Profile
@djsutherland
djsutherland / example.hmm
Created November 1, 2011 05:10
Code for a Hidden Markov Model, along with some sample data / parameters for testing.
4 # number of states
START
COLD
HOT
END
3 # size of vocab
1
2
3
@dsparks
dsparks / Avoiding a loop.R
Created September 12, 2012 13:19
lapply() as an alternative to a multiply-nested loop
# Alternative to a doubly-nested loop
# Imagine I want to perform an operation on a data frame
# once for each combination of two variables, such as Country and Year
# I can do this with a nested loop, or I can do this with (among other
# things) lapply()
# Generate random data:
allCountries <- LETTERS[1:10]
allYears <- 1990:2012
@jwaageSnippets
jwaageSnippets / gist:5133941
Created March 11, 2013 12:34
Get refseq genes from UCSC, and extract longest transcripts for each gene symbol
library("rtracklayer")
session <- browserSession("UCSC")
genome(session)<-"mm9"
query <- ucscTableQuery(session, "refGene")
tableName(query) <- "refGene"
getTable(query) -> refseq
refseq[,c(2,3,4,5,6,7,8,13)] -> refseq
refseq$"width" <- refseq$"txEnd"-refseq$"txStart"
as.character(refseq[,1]) -> refseq[,1]
@al2na
al2na / annotateWithFeatures.R
Last active June 10, 2020 09:31
new annotation functions for genomation,
library(data.table)
library(genomation)
library(ggplot2)
#' Annotate given ranges with genomic features
#'
#' The function annotates a target GRangesList or GRanges object as overlapping
#' or not with
#' the elements of named GRangesList. This is useful to annotate your regions
@mtmorgan
mtmorgan / grangesToSymbol
Created July 29, 2016 20:50
Extract ranges of genes, and map ranges to corresponding genes
geneRanges <-
function(db, column="ENTREZID")
{
g <- genes(db, columns=column)
col <- mcols(g)[[column]]
genes <- granges(g)[rep(seq_along(g), elementNROWS(col))]
mcols(genes)[[column]] <- as.character(unlist(col))
genes
}
@giuseppebonaccorso
giuseppebonaccorso / hodgkin-huxley-main.py
Created August 19, 2017 15:06
Hodgkin-Huxley spiking neuron model in Python
import matplotlib.pyplot as plt
import numpy as np
from scipy.integrate import odeint
# Set random seed (for reproducibility)
np.random.seed(1000)
# Start and end time (in milliseconds)
tmin = 0.0
@slavailn
slavailn / jaccard_genes_cluster.R
Last active August 26, 2020 14:50
Cluster sets of genes based on Jaccard distance (mostly stolen from Biostars post)
# test Jaccard
# Create a list gene sets
char1 <- c("gene1", "gene2", "gene5", "gene9", "gene10")
char2 <- c("gene2", "gene3", "gene5", "gene7", "gene10")
char3 <- c("gene7", "gene9", "gene10", "gene11", "gene12", "gene1")
lst <- list(char1, char2, char3)
# Function to calculate Jaccard distance
@Balharbi
Balharbi / annotate_metilene_regions.R
Created March 7, 2020 17:10 — forked from slavailn/annotate_metilene_regions.R
annotate RRBS metilene regions
library(ChIPpeakAnno)
library(biomaRt)
library(genomation)
library(dplyr)
# Read in metilene results
res <- read.table("results_de_novo_all_10.txt", sep = "\t", header = T)
head(res)
@Balharbi
Balharbi / Avoiding a loop.R
Created June 28, 2020 01:44 — forked from dsparks/Avoiding a loop.R
lapply() as an alternative to a multiply-nested loop
# Alternative to a doubly-nested loop
# Imagine I want to perform an operation on a data frame
# once for each combination of two variables, such as Country and Year
# I can do this with a nested loop, or I can do this with (among other
# things) lapply()
# Generate random data:
allCountries <- LETTERS[1:10]
allYears <- 1990:2012