Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions netZooPy/condor/condor.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,13 +305,14 @@ def matrices(self, c,resolution):
# Computes weighted biadjacency matrix.
A = np.matrix(np.zeros((p, q)))
for edge in self.net.iterrows():
A[gn[edge[1][1]], rg[edge[1][0]]] = edge[1][2]
row = edge[1]
A[gn[row.iloc[1]], rg[row.iloc[0]]] = row.iloc[2]

# Computes node degrees for the nodesets.
ki = A.sum(1)
dj = A.sum(0)
# Computes sum of edges and bimodularity matrix.
m = float(sum(ki))
m = float(ki.sum())
B = A - resolution*((ki @ dj) / m)

# d = self.index_dict
Expand Down
9 changes: 5 additions & 4 deletions netZooPy/panda/io.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
from __future__ import print_function

import math
import os
import numpy as np
import sys
import pandas as pd


def load_motif(motif_file):
if type(motif_file) is str:
if isinstance(motif_file, (str, os.PathLike)):
# If motif_file is a filename
motif_data = pd.read_csv(motif_file, sep="\t", header=None)
motif_tfs = sorted(set(motif_data[0]))
motif_genes = sorted(set(motif_data[1]))
elif type(motif_file) is not str:
else:
# If motif_file is an object
if motif_file is None:
# Computation without motif
Expand All @@ -37,7 +38,7 @@ def load_motif(motif_file):


def load_expression(expression_file, with_header = False, start = 1, end = None):
if type(expression_file) is str:
if isinstance(expression_file, (str, os.PathLike)):
# If we pass an expression file, check if we have a 'with header' flag and read it

if with_header:
Expand All @@ -54,7 +55,7 @@ def load_expression(expression_file, with_header = False, start = 1, end = None)
expression_genes = expression_data.index.tolist()
expression_samples = expression_data.columns.astype(str)

elif type(expression_file) is not str:
else:
# Pass expression as a dataframe
if expression_file is not None:
if not isinstance(expression_file, pd.DataFrame):
Expand Down
4 changes: 2 additions & 2 deletions netZooPy/panda/panda.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,14 +357,14 @@ def processData(

### Loading the PPI
# #TODO: move this to io
if type(ppi_file) is str:
if isinstance(ppi_file, (str, os.PathLike)):
with Timer("Loading PPI data ..."):
self.ppi_data = pd.read_csv(ppi_file, sep="\t", header=None)
self.ppi_tfs = sorted(
set(pd.concat([self.ppi_data[0], self.ppi_data[1]]))
)
print("Number of PPIs:", self.ppi_data.shape[0])
elif type(ppi_file) is not str:
else:
if ppi_file is not None:
if not isinstance(ppi_file, pd.DataFrame):
raise Exception("Please provide a pandas dataframe for PPI data.")
Expand Down
2 changes: 1 addition & 1 deletion netZooPy/puma/puma.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def __init__(
with Timer("Loading miR data ..."):
# If the mir_file is a string the mir list is read from file
# otherwise the input list is used directly
if type(mir_file) is str:
if isinstance(mir_file, (str, os.PathLike)):
with open(mir_file, "r") as f:
miR = f.read().splitlines()
elif isinstance(mir_file,list):
Expand Down
5 changes: 3 additions & 2 deletions tests/test_cobra.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def test_cobra():
pd.testing.assert_frame_equal(G, G_gt, rtol=1e-10, check_exact=False)

q = psi.shape[0]
X_mean = np.mean(X.to_numpy(), axis=0)
for i in range(q):
C = Q.to_numpy().dot(np.mean(X, axis=0)[i] * np.diag(psi.to_numpy()[i, :])).dot(Q.to_numpy().T)
C_gt = Q_gt.to_numpy().dot(np.mean(X, axis=0)[i] * np.diag(psi_gt.to_numpy()[i, :])).dot(Q_gt.to_numpy().T)
C = Q.to_numpy().dot(X_mean[i] * np.diag(psi.to_numpy()[i, :])).dot(Q.to_numpy().T)
C_gt = Q_gt.to_numpy().dot(X_mean[i] * np.diag(psi_gt.to_numpy()[i, :])).dot(Q_gt.to_numpy().T)
pd.testing.assert_frame_equal(pd.DataFrame(C), pd.DataFrame(C_gt), rtol=1e-10, check_exact=False)
Loading