Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix travis #189

Merged
merged 20 commits into from
Jul 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion calour/analysis.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can u combine it with the if on 275 line?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

less convenient since sample_nonzero is modified after the first if and before this if... and i think also will be less clear to understand if joined.

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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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