Skip to content

Commit

Permalink
DOC/TST: add working usage example for mann-whitney-u (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
lizgehret authored Apr 29, 2022
1 parent d9cdd59 commit 85c4cad
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 94 deletions.
26 changes: 23 additions & 3 deletions q2_fmt/_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ def faithpd_timedist_factory():
'GroupDist[Ordered, Matched]', _get_data_from_tests('faithpd_timedist')
)

def faithpd_refdist_factory():
return qiime2.Artifact.import_data(
'GroupDist[Unordered, Independent]', _get_data_from_tests('faithpd_refdist')
)

def faithpd_md_factory():
return qiime2.Metadata.load(
_get_data_from_tests('metadata-faithpd.tsv')
Expand Down Expand Up @@ -110,9 +115,24 @@ def wilcoxon_baseline0(use):

stats_table.assert_output_type('StatsTable[Pairwise]')

#TODO: usage example for mann-whitney
def mann_whitney_u(use):
pass
def mann_whitney_pairwise(use):
timedist = use.init_artifact('timedist', faithpd_timedist_factory)
refdist = use.init_artifact('refdist', faithpd_refdist_factory)

stats_table, = use.action(
use.UsageAction('fmt', 'mann_whitney_u'),
use.UsageInputs(
distribution=refdist,
hypothesis='all-pairwise',
against_each=timedist,
p_val_approx='asymptotic',
),
use.UsageOutputNames(
stats='stats'
)
)

stats_table.assert_output_type('StatsTable[Pairwise]')

# Engraftment example using faith PD, baseline0 hypothesis
def engraftment_baseline(use):
Expand Down
5 changes: 4 additions & 1 deletion q2_fmt/plugin_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@
'stats': 'The Mann-Whitney U distribution for either the `reference` or `all-pairwise` hypothesis.',
},
name='Mann-Whitney U Test',
description=''
description='',
examples={
'mann_whitney_pairwise': ex.mann_whitney_pairwise
}
)

plugin.methods.register_function(
Expand Down
29 changes: 29 additions & 0 deletions q2_fmt/tests/data/faithpd_refdist/data.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
id measure group
S879369 10.248839183 reference
S435802 10.379970859 reference
S409550 8.379513518 reference
S916057 10.551980282 reference
S405044 9.263042352 reference
S953010 12.138687523999998 control
S358668 12.402660535 control
S842739 12.771875893 control
S691441 8.145593314 control
S427307 12.967708926 control
S238639 11.649627363 control
S611569 7.989246995999999 control
S298842 9.500026592 control
S160074 14.460895127 control
S211105 11.767674432 control
S460372 9.547484785000002 control
S728037 9.597018329 control
S282059 9.282152505 control
S388055 10.279025972 control
S630647 12.086278795 control
S59807 11.167537754 control
S255688 10.029524157 control
S889561 4.4655846960000005 control
S990074 5.138442046 control
S269036 13.110583296 control
S684586 12.705425981 control
S696581 15.902021065 control
S322808 13.960754461 control
4 changes: 4 additions & 0 deletions q2_fmt/tests/data/faithpd_refdist/metadata.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
column unit description
id id ...
measure faith_pd faith_pd
group InitialDonorSampleID or IsControl ...
174 changes: 87 additions & 87 deletions q2_fmt/tests/data/faithpd_timedist/data.tsv
Original file line number Diff line number Diff line change
@@ -1,88 +1,88 @@
id measure group subject
340445 7.662921088 0 141
892825 8.431734297 0 33
460691 8.513263823 0 407
33196 11.47176562 0 68
676122 9.914657833 0 404
64538 12.62560928 0 354
820102 9.453417415 0 799
19325 9.646052305 0 40
677034 7.778748399 0 745
45687 12.68877984 0 959
634737 11.79632603 0 491
42188 7.386190882 0 604
733472 11.19719621 0 327
660492 10.18787122 0 17
728527 8.448317067 0 555
101304 11.3228199 0 648
352530 7.314753809 0 423
49899 8.27086375 0 704
179157 10.83320209 3 141
932597 9.8956928 3 33
593887 11.86970243 3 407
804240 10.12497616 3 68
823495 9.478838334 3 404
515494 8.502002897 3 354
38418 9.246871802 3 799
656022 12.62000749 3 40
568016 10.50579797 3 959
604276 7.830091789 3 491
376907 6.725748683 3 604
268616 11.98183356 3 327
158516 12.43679596 3 17
311633 9.592979726 3 555
740172 8.880897012 3 648
119473 9.092078686 3 423
257623 8.522314493 3 704
265 10.83670704 10 141
669048 9.172597583 10 33
95356 11.60664407 10 407
40277 10.78345691 10 68
459758 11.48168273 10 404
564018 17.43370405 10 354
936973 15.2623358 10 799
291167 13.53128149 10 40
41971 15.96814451 10 745
681493 13.61043486 10 959
824846 10.62683459 10 491
285186 7.444009936 10 604
773741 9.728676749 10 327
163514 12.77874569 10 17
297641 10.65211873 10 555
794108 11.12683676 10 648
96318 9.027651356 10 423
920509 9.059711997 10 704
683282 11.68795212 18 141
263946 10.65262785 18 33
513816 10.94184424 18 407
456128 13.26471277 18 68
454628 11.69071803 18 404
316090 14.96844078 18 354
318234 10.49866422 18 799
204144 11.09989491 18 40
334403 10.31360211 18 745
743943 11.76570288 18 959
662822 13.66553354 18 491
387858 8.598030851 18 604
131881 11.78182748 18 327
236141 12.20070358 18 17
462162 9.750043462 18 555
784577 10.8908099 18 648
103872 8.990062701 18 423
159294 14.73197158 18 704
466166 14.95236844 100 141
763905 10.26127503 100 33
734500 12.24557912 100 407
599248 19.96358026 100 68
209330 10.82326355 100 404
934977 12.95731892 100 354
540115 14.46464274 100 799
301520 14.68263437 100 40
351280 15.48569583 100 959
726967 16.0492848 100 491
340645 10.87510264 100 604
754317 8.866448342 100 327
91814 13.57054725 100 555
984262 12.36040446 100 648
623940 11.07684349 100 423
476406 12.98841452 100 704
S340445 7.662921088 0 141
S892825 8.431734297 0 33
S460691 8.513263823 0 407
S33196 11.47176562 0 68
S676122 9.914657833 0 404
S64538 12.62560928 0 354
S820102 9.453417415 0 799
S19325 9.646052305 0 40
S677034 7.778748399 0 745
S45687 12.68877984 0 959
S634737 11.79632603 0 491
S42188 7.386190882 0 604
S733472 11.19719621 0 327
S660492 10.18787122 0 17
S728527 8.448317067 0 555
S101304 11.3228199 0 648
S352530 7.314753809 0 423
S49899 8.27086375 0 704
S179157 10.83320209 3 141
S932597 9.8956928 3 33
S593887 11.86970243 3 407
S804240 10.12497616 3 68
S823495 9.478838334 3 404
S515494 8.502002897 3 354
S38418 9.246871802 3 799
S656022 12.62000749 3 40
S568016 10.50579797 3 959
S604276 7.830091789 3 491
S376907 6.725748683 3 604
S268616 11.98183356 3 327
S158516 12.43679596 3 17
S311633 9.592979726 3 555
S740172 8.880897012 3 648
S119473 9.092078686 3 423
S257623 8.522314493 3 704
S265 10.83670704 10 141
S669048 9.172597583 10 33
S95356 11.60664407 10 407
S40277 10.78345691 10 68
S459758 11.48168273 10 404
S564018 17.43370405 10 354
S936973 15.2623358 10 799
S291167 13.53128149 10 40
S41971 15.96814451 10 745
S681493 13.61043486 10 959
S824846 10.62683459 10 491
S285186 7.444009936 10 604
S773741 9.728676749 10 327
S163514 12.77874569 10 17
S297641 10.65211873 10 555
S794108 11.12683676 10 648
S96318 9.027651356 10 423
S920509 9.059711997 10 704
S683282 11.68795212 18 141
S263946 10.65262785 18 33
S513816 10.94184424 18 407
S456128 13.26471277 18 68
S454628 11.69071803 18 404
S316090 14.96844078 18 354
S318234 10.49866422 18 799
S204144 11.09989491 18 40
S334403 10.31360211 18 745
S743943 11.76570288 18 959
S662822 13.66553354 18 491
S387858 8.598030851 18 604
S131881 11.78182748 18 327
S236141 12.20070358 18 17
S462162 9.750043462 18 555
S784577 10.8908099 18 648
S103872 8.990062701 18 423
S159294 14.73197158 18 704
S466166 14.95236844 100 141
S763905 10.26127503 100 33
S734500 12.24557912 100 407
S599248 19.96358026 100 68
S209330 10.82326355 100 404
S934977 12.95731892 100 354
S540115 14.46464274 100 799
S301520 14.68263437 100 40
S351280 15.48569583 100 959
S726967 16.0492848 100 491
S340645 10.87510264 100 604
S754317 8.866448342 100 327
S91814 13.57054725 100 555
S984262 12.36040446 100 648
S623940 11.07684349 100 423
S476406 12.98841452 100 704
4 changes: 2 additions & 2 deletions q2_fmt/tests/test_engraftment.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from q2_fmt._engraftment import group_timepoints
from q2_fmt._stats import wilcoxon_srt, mann_whitney_u
from q2_fmt._examples import faithpd_timedist_factory

class TestBase(TestPluginBase):
package='q2_fmt.tests'
Expand All @@ -27,8 +28,7 @@ def setUp(self):
self.dm = DistanceMatrix.read(self.get_data_path('dist_matrix_donors.tsv')).to_series()
self.alpha = pd.read_csv(self.get_data_path('alpha_div.tsv'), sep='\t', index_col=0, squeeze=True)

self.faithpd_timedist = pd.read_csv(self.get_data_path('faithpd_timedist/data.tsv'),
sep='\t', index_col=0, squeeze=True)
self.faithpd_timedist = faithpd_timedist_factory().view(pd.DataFrame)

class ErrorMixins:
def test_with_time_column_input_not_in_metadata(self):
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
packages=find_packages(),
package_data={
'q2_fmt': ['assets/*'],
'q2_fmt.tests': ['data/*', 'data/faithpd_timedist/*'],
'q2_fmt.tests': ['data/*', 'data/faithpd_timedist/*',
'data/faithpd_refdist/*'],
},
author='Liz Gehret',
author_email='[email protected]',
Expand Down

0 comments on commit 85c4cad

Please sign in to comment.