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
create table tmp_data as | |
SELECT DISTINCT molecule_dictionary.chembl_id,compound_structures.canonical_smiles,ASSAYS.TID,target_dictionary.chembl_id AS target_chembl_id, | |
TARGET_DICTIONARY.ORGANISM,ACTIVITIES.*,assays.chembl_id AS assay_chembl_id | |
from molecule_dictionary,compound_structures,assays,activities,target_dictionary | |
where compound_structures.molregno = MOLECULE_DICTIONARY.MOLREGNO | |
and MOLECULE_DICTIONARY.MOLREGNO = ACTIVITIES.MOLREGNO | |
and ASSAYS.TID = TARGET_DICTIONARY.TID AND ASSAYS.ASSAY_ID = ACTIVITIES.ASSAY_ID | |
and ACTIVITIES.STANDARD_UNITS = 'nM' AND ACTIVITIES.STANDARD_VALUE < 50 | |
and TARGET_DICTIONARY.ORGANISM = 'Homo sapiens' |
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.packages('RPostgreSQL', type='source') | |
#initiate connection | |
library(RPostgreSQL) | |
library(BMS) | |
library(ggplot2) | |
drv <- dbDriver("PostgreSQL") | |
con <- dbConnect(drv, dbname="chembl_18") |
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
# Create function | |
create or replace function inchi_mol(x text) | |
returns text | |
AS $$ | |
from rdkit import Chem | |
from rdkit.Chem import AllChem | |
file = open("/home/chembl/logerror2.txt","a") | |
try : | |
m=Chem.MolFromInchi(x) | |
if m is not None : |
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
# x = a vector for scores | |
# y = a vector of labels | |
function (x, y, decreasing = TRUE, top = 1) | |
{ | |
if (length(x) != length(y)) { | |
stop(paste("Length of scores does not match with labels.")) | |
} | |
N <- length(y) | |
n <- sum(y == 1) |
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
# x = a vector of scores | |
# y = a vector of labels | |
function (x, y, decreasing = TRUE, alpha = 20) | |
{ | |
if (length(x) != length(y)) { | |
stop(paste("The length of scores should be equal to number of labels.")) | |
} | |
N <- length(y) | |
n <- length(which(y == 1)) |
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
# x = a vector of scores | |
# y = a vector of labels | |
function (x, y, decreasing = TRUE, alpha = 20) | |
{ | |
if (length(x) != length(y)) { | |
stop(paste("The length of scores should be equal to number of labels.")) | |
} | |
N <- length(y) | |
n <- length(which(y == 1)) |
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
# Parameter r: restart probability | |
r<-0.8 | |
# convergence cutoff | |
conv_cut<-1e-10 | |
RWR <- function(M, p_0, r,conv_cut, prop=FALSE) { | |
# use Network propagation when prop=TRUE | |
if(prop) { | |
w<-colSums(M) |
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
# Algorithm to perform MCL Clustering in R | |
# Add the identity matrix to the matrix which indicates self loops | |
add.selfloops <- function (M) { | |
LM<-M+diag(dim(M)[1]) | |
return (LM); | |
} | |
# Inflation step of MCL | |
inflate <- function (M,inf) { | |
M <- M^(inf) |
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
nbi < - function (A){ | |
# A is the n x m adjacencny matrix here | |
n <- nrow(A) | |
m <- ncol(A) | |
# You need to calculate the degree of columns to use it as node weight | |
Ky <- diag(1/colSums(A)) | |
Ky[is.infinite(Ky) | is.na(Ky)] <- 0 | |
kx <- rowSums(A) | |
Nx <- 1/(matrix(kx, nrow=n, ncol=n, byrow=TRUE)) |
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
data(Enzyme) | |
# Adjacency Matrix | |
A = enzyme_ADJ | |
# Compute inner product | |
m <- t(A) %*% A | |
m[m>0] <- 1 | |
# Chemical similarity Matrix |
OlderNewer