Skip to content

Commit

Permalink
Fixed linkage bug, added two-tailed GO requests, fixed locality error
Browse files Browse the repository at this point in the history
  • Loading branch information
MeeshCompBio committed May 17, 2017
1 parent 4b3ce6b commit 8c27c94
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
8 changes: 7 additions & 1 deletion camoco/COB.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import networkx as nx
import pandas as pd
import numpy as np
from numpy import nan
import itertools
from odo import odo
from scipy.misc import comb
Expand Down Expand Up @@ -1092,8 +1093,11 @@ def locality(self, gene_list, iter_name=None, include_regression=False):
degree.columns = ['global', 'local']
degree = degree.sort_values(by='global')
if include_regression:
#set up variables to use astype to aviod pandas sm.OLS error
loc_deg = degree['local']
glob_deg = degree['global']
# Add the regression lines
ols = sm.OLS(degree['local'], degree['global']).fit()
ols = sm.OLS(loc_deg.astype(float), glob_deg.astype(float)).fit()
degree['resid'] = ols.resid
degree['fitted'] = ols.fittedvalues
degree = degree.sort_values(by='resid',ascending=False)
Expand Down Expand Up @@ -1499,6 +1503,8 @@ def _calculate_gene_hierarchy(self,method='single'):
dists = (dists * pcc_std) + pcc_mean
dists = np.tanh(dists)
dists = 1 - dists
#convert nan to 0's, linkage can only use finite values
dists[np.isnan(dists)] = 0
gc.collect()
# Find the leaves from hierarchical clustering
gene_link = linkage(dists, method=method)
Expand Down
5 changes: 3 additions & 2 deletions camoco/cli/camoco
Original file line number Diff line number Diff line change
Expand Up @@ -722,8 +722,9 @@ if __name__ == '__main__':
)
health.add_argument(
'--two_tailed_GO',
default=None,
help='Include negative density values for GO statistics (default: None)'
action='store_true',
default=False,
help='Include negative density values for GO statistics (default: False)'
)
health.add_argument(
'--min-term-size',
Expand Down
8 changes: 4 additions & 4 deletions camoco/cli/commands/health.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,18 +157,18 @@ def cob_health(args):
term.loci = list(filter(lambda x: x in cob, term.loci))
if len(term) < args.min_term_size or len(term) > args.max_term_size:
continue
#set density value for two tailed go so we only test it once
density = cob.density(term.loci)
#one tailed vs two tailed test
if args.two_tailed_GO is None:
if args.two_tailed_GO is True:
#run one tail for only positive values
if cob.density(term.loci) > 0:
density = cob.density(term.loci)
if density > 0:
density_emp.append(density)
#skip negative density values
else:
continue
#if two_tailed_go is not none
else:
density = cob.density(term.loci)
density_emp.append(density)
term_ids.append(term.id)
term_sizes.append(len(term))
Expand Down

0 comments on commit 8c27c94

Please sign in to comment.