Skip to content

Commit

Permalink
Merge f7cce70 into 95cb121
Browse files Browse the repository at this point in the history
  • Loading branch information
amnona committed Jun 30, 2020
2 parents 95cb121 + f7cce70 commit 0b36818
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 16 deletions.
1 change: 0 additions & 1 deletion calour/analysis.py
Expand Up @@ -130,7 +130,6 @@ def correlation(exp: Experiment, field, method='spearman', nonzero=False, transf
keep, odif, pvals = dsfdr.dsfdr(data, labels, method=method, transform_type=transform, alpha=alpha, numperm=numperm, fdr_method=fdr_method)
logger.info('Positive correlated features : %d. Negative correlated features : %d. total %d'
% (np.sum(odif[keep] > 0), np.sum(odif[keep] < 0), np.sum(keep)))

newexp = _new_experiment_from_pvals(cexp, exp, keep, odif, pvals)
newexp.feature_metadata[_CALOUR_DIRECTION] = [field if x > 0 else 'Anti-%s' % field for x in newexp.feature_metadata[_CALOUR_STAT]]
return newexp
Expand Down
5 changes: 4 additions & 1 deletion calour/dsfdr.py
Expand Up @@ -272,15 +272,18 @@ def dsfdr(data, labels, transform_type='rankdata', method='meandiff',
index = np.nonzero(data[i, :])
label_nonzero = labels[index]
sample_nonzero = data[i, :][index]
if len(sample_nonzero) == 0:
continue
if method == 'nonzerospearman':
sample_nonzero = sp.stats.rankdata(sample_nonzero)
label_nonzero = sp.stats.rankdata(label_nonzero)
sample_nonzero = sample_nonzero - np.mean(sample_nonzero)
label_nonzero = label_nonzero - np.mean(label_nonzero)
tstat[i] = np.dot(sample_nonzero, label_nonzero)
t[i] = np.abs(tstat[i])
if np.std(sample_nonzero) == 0:
continue
tstat[i] = tstat[i] / (np.std(sample_nonzero) * np.std(label_nonzero) * len(sample_nonzero))

permlabels = np.zeros([len(label_nonzero), numperm])
for cperm in range(numperm):
rlabels = np.random.permutation(label_nonzero)
Expand Down
6 changes: 3 additions & 3 deletions calour/export_html.py
Expand Up @@ -34,22 +34,22 @@
logger = getLogger(__name__)


def _list_to_string(l):
def _list_to_string(cl):
'''Convert a list to a string representation of the list
For use in the html javascript
Parameters
----------
l : list
cl : list
Returns
-------
str
ready for embedding into html javascript
'''
cstr = '['
for cval in l:
for cval in cl:
cstr += '"'
cstr += str(cval)
cstr += '",'
Expand Down
2 changes: 1 addition & 1 deletion calour/heatmap/plotgui.py
Expand Up @@ -139,7 +139,7 @@ def _set_figure(self, figure=None, tree_size=0):
self.ax_legend = self.figure.add_subplot(gs[7])
self.gridspec = gs

def resize_figure (self, *args, **kwargs):
def resize_figure(self, *args, **kwargs):
'''Resize the figure.
It is a convenient function that wraps on
Expand Down
2 changes: 1 addition & 1 deletion calour/tests/test_analysis.py
Expand Up @@ -116,7 +116,7 @@ def test_correlation_complex_spearman(self):
np.random.seed(2017)
# test on real complex dataset (timeseries) with spearman correlation
dd = self.complex.correlation('MF_SAMPLE_NUMBER', method='spearman')
print(len(dd.feature_metadata))
# print(len(dd.feature_metadata))
self.assertTrue(np.abs(51 - len(dd.feature_metadata)) < 5)

def test_diff_abundance_kw(self):
Expand Down
8 changes: 6 additions & 2 deletions calour/tests/test_database.py
Expand Up @@ -36,11 +36,15 @@ def test_mock_db(self):
def test_gui_interface(self):
mdb = self.mock_db
res = mdb.get_seq_annotation_strings(self.s1)
print(res)
self.assertEqual(len(res), 2)
self.assertEqual(res[1][1], 'nice')
self.assertFalse('_db_interface' in res[0][0])
gui = _create_plot_gui(self.test1, gui='qt5', databases=[])
gui.databases.append(mdb)
res = gui.get_database_annotations(self.s1)
print(res)
self.assertEqual(len(res), 2)
self.assertTrue('_db_interface' in res[0][0])
self.assertEqual(res[1][1], 'nice')

def test_get_database_class(self):
d = mkdtemp()
Expand Down
14 changes: 7 additions & 7 deletions calour/util.py
Expand Up @@ -70,28 +70,28 @@ def compute_prevalence(abundance):
return cutoffs, prevalences


def _transition_index(l):
def _transition_index(obj):
'''Return the transition index and current value of the list.
Examples
-------
>>> l = ['a', 'a', 'b']
>>> list(_transition_index(l))
>>> obj = ['a', 'a', 'b']
>>> list(_transition_index(obj))
[(2, 'a'), (3, 'b')]
>>> l = ['a', 'a', 'b', 1, 2, None, None]
>>> list(_transition_index(l))
>>> obj = ['a', 'a', 'b', 1, 2, None, None]
>>> list(_transition_index(obj))
[(2, 'a'), (3, 'b'), (4, 1), (5, 2), (7, None)]
Parameters
----------
l : Iterable of arbitrary objects
obj : Iterable of arbitrary objects
Yields
------
tuple of (int, arbitrary)
the transition index, the item value
'''
it = enumerate(l)
it = enumerate(obj)
i, item = next(it)
item = str(type(item)), item
for i, current in it:
Expand Down

0 comments on commit 0b36818

Please sign in to comment.