Package: obnb
Open Biomedical Network BenchmarkThe Open Biomedical Network Benchmark (OBNB) is a comprehensive resource for setting up benchmarking graph datasets usingbiomedical networksandgene annotations.
Our goal is to accelerate the adoption of advanced graph machine learning techniques, such as graph neural networks and graph embeddings, in network biology for gaining novel insights into genes' function, trait, and disease associations using biological networks.
To make this adoption convenient, OBNB also provides dataset objects compatible with popular graph deep learning frameworks, includingPyTorch Geometric (PyG)andDeep Graph Library (DGL).A comprehensive benchmarking study with a wide-range of graph neural networks and graph embedding methods on OBNB datasets can be found in our benchmarking repositoryobnbench.Package usageConstruct default datasetsWe provide a high-level dataset constructor to help users easily set up benchmarking graph datasets
for a combination of network and label. In particular, the dataset will be set up with study-bias
holdout split (6/2/2), where 60% of the most well-studied genes according to the number of
associated PubMed publications are used for training, 20% of the least studied genes are used for
testing, and the rest of the 20% genes are used for validation. For more customizable data loading
and processing options, see thecustomized dataset constructionsection below.fromobnb.datasetimportOpenBiomedNetBenchfromobnb.util.versionimportget_available_data_versionsroot="datasets"# save dataset and cache under the datasets/ directoryversion="current"# use the last archived version# Optionally, set version to the specific data version number# Or, set version to "latest" to download the latest data from source and process it from scratch# Download and process network/label data. Use the adjacency matrix as the ML featuredataset=OpenBiomedNetBench(root=root,graph_name="BioGRID",label_name="DisGeNET",version=version,graph_as_feature=True,use_dense_graph=True)# Check the specific archive data version usedprint(dataset.version)# Check all available stable archive data versionsprint(get_available_data_versions())Users can also load the dataset objects into ones that are compatible with PyG or DGL (see below).PyG datasetfromobnb.datasetimportOpenBiomedNetBenchPyGdataset=OpenBiomedNetBenchPyG(root,"BioGRID","DisGeNET")Note: requires installing PyG first (seeinstallation instructions)DGL datasetfromobnb.datasetimportOpenBiomedNetBenchDGLdataset=OpenBiomedNetBenchDGL(root,"BioGRID","DisGeNET")Note: requires installing DGL first (seeinstallation instructions)Evaluating standard modelsEvaluation of simple machine learning methods such as logistic regression and label propagation
can be done easily using the trainer objects.fromobnb.model_trainerimportSupervisedLearningTrainer,LabelPropagationTrainersl_trainer=SupervisedLearningTrainer()lp_trainer=LabelPropagationTrainer()Then, use thefit_and_evalmethod of the trainer to evaluate a given ML model over all tasks
in a one-vs-rest setting.fromsklearn.linear_modelimportLogisticRegressionfromobnb.model.label_propagationimportOneHopPropagation# Initialize modelssl_mdl=LogisticRegression(penalty="l2",solver="lbfgs")lp_mdl=OneHopPropagation()# Evaluate the models over all taskssl_results=sl_trainer.fit_and_eval(sl_mdl,dataset)lp_results=lp_trainer.fit_and_eval(lp_mdl,dataset)Evaluating GNN modelsTraining and evaluation of Graph Neural Network (GNN) models can be done in a very similar fashion.fromtorch_geometric.nnimportGCNfromobnb.model_trainer.gnnimportSimpleGNNTrainer# Use 1-dimensional trivial node feature by defaultdataset=OpenBiomedNetBench(root=root,graph_name="BioGRID",label_name="DisGeNET",version=version)# Train and evaluate a GCNgcn_mdl=GCN(in_channels=1,hidden_channels=64,num_layers=5,out_channels=n_tasks)gcn_trainer=SimpleGNNTrainer(device="cuda",metric_best="apop")gcn_results=gcn_trainer.train(gcn_mdl,dataset)Customized dataset constructionLoad network and labelsfromobnbimportdata# Load processed BioGRID data from archive.g=data.BioGRID(root,version=version)# Load DisGeNET gene set collections.lsc=data.DisGeNET(root,version=version)Setting up data and splitsfromobnb.util.converterimportGenePropertyConverterfromobnb.label.splitimportRatioHoldout# Load PubMed count gene property converter and use it to set up study-bias holdout splitpubmedcnt_converter=GenePropertyConverter(root,name="PubMedCount")splitter=RatioHoldout(0.6,0.4,ascending=False,property_converter=pubmedcnt_converter)Filter labeled data based on network genes and splits# Apply in-place filters to the labelset collectionlsc.iapply(filters.Compose(# Only use genes that are present in the networkfilters.EntityExistenceFilter(list(g.node_ids)),# Remove any labelsets with less than 50 network genesfilters.LabelsetRangeFilterSize(min_val=50),# Make sure each split has at least 10 positive examplesfilters.LabelsetRangeFilterSplit(min_val=10,splitter=splitter),),)Combine into datasetfromobnbimportDatasetdataset=Dataset(graph=g,feature=g.to_dense_graph().to_feature(),label=lsc,splitter=splitter)InstallationOBNB can be installed easily via pip fromPyPI:pipinstallobnbInstall with extension modules (optional)OBNB provides interfaces with several other packages for network feature extractions, such asPecanPyandGraPE.
To enable those extensions, installobnbwith theextextra option enabled:pipinstallobnb[ext]Install graph deep learning libraries (optional)Follow installation instructions forPyGorDGLto set up the graph deep learning library of your choice.Alternatively, we also provide aninstallation scriptthat helps you installthe graph deep-learning dependencies in a new conda environmentobnb:gitclonehttps://github.com/krishnanlab/obnb&&cdobnbsourceinstall.shcu117# other options are [cpu,cu118]