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

St plots #161

Open
wants to merge 55 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
82bc291
Update README.md
andy6a Jul 29, 2023
1affe3d
Update README.md part 2
andy6a Jul 29, 2023
693cb98
Update _sourcetracker.py
andy6a Jul 29, 2023
e149980
Update README.md
andy6a Aug 25, 2023
ec4c493
Merge branch 'caporaso-lab:master' into master
andy6a Aug 30, 2023
4756df1
Merge branch 'caporaso-lab:master' into master
andy6a Dec 8, 2023
28bf12c
Merge branch 'caporaso-lab:master' into master
andy6a Jan 16, 2024
e6414d9
Merge branch 'caporaso-lab:master' into master
andy6a Feb 29, 2024
5f9c818
Adding new and more applicable plots to sourcetracker
andy6a Feb 29, 2024
8ad0397
Add new Plotting code to access new plots in gibbs.py
andy6a Feb 29, 2024
0613d28
Update __init__.py remove old code
andy6a Feb 29, 2024
ed567c5
Update _plot.py Transposing issue
andy6a Feb 29, 2024
a974cc2
Update _plot.py Transpose issues
andy6a Feb 29, 2024
3ab0654
Update _plot.py
andy6a Feb 29, 2024
1375f52
Update _plot.py tra alteration
andy6a Mar 6, 2024
efee857
Update gibbs.py transpose alteration
andy6a Mar 7, 2024
d2f5149
Update README.md from biota to caporaso
andy6a Mar 11, 2024
9459aa2
Update _plot.py remove excess code
andy6a Apr 19, 2024
377352d
Update gibbs.py readability order
andy6a Apr 19, 2024
77c5347
Update _gibbs_defaults.py added descriptions of new features
andy6a Apr 19, 2024
46e2dad
Update _gibbs_defaults.py fix indent
andy6a Apr 19, 2024
ee18c6f
Update gibbs.py add help tabs to new inputs
andy6a Apr 19, 2024
e0eeb19
Update gibbs.py remove excess space
andy6a Apr 19, 2024
c333e19
Update _plot.py remove commented out code
andy6a Apr 23, 2024
3f2d94d
Update _plot.py changing output name from spaces to underscore
andy6a Apr 23, 2024
665b88a
Update _plot.py
andy6a Apr 23, 2024
f7bb40f
Update gibbs.py streamline heatmap and paired heatmap
andy6a Apr 23, 2024
bfd0b16
Update _plot.py heat_ratio variable
andy6a Apr 23, 2024
f117b13
Update _plot.py modified doc strings
andy6a May 1, 2024
61126a0
Update _plot.py
andy6a May 1, 2024
94573a8
Update gibbs.py stacked bar alterations
andy6a May 2, 2024
3f0366a
Update gibbs.py
andy6a May 2, 2024
bb32c7e
Update gibbs.py
andy6a May 2, 2024
4a043c8
Update _plot.py Stacked bar variations alterations and alignment
andy6a May 2, 2024
efc0a38
Update _plot.py
andy6a May 3, 2024
bc9342f
Update _plot.py
andy6a May 3, 2024
eed7975
Update sourcetracker/_plot.py
andy6a May 3, 2024
e8bedbf
Update sourcetracker/_gibbs_defaults.py
andy6a May 3, 2024
c56abe4
Update _gibbs_defaults.py
andy6a May 3, 2024
709f7ca
Update sourcetracker/_plot.py
andy6a May 3, 2024
9dd2b04
Update _plot.py descriptive unknowns
andy6a May 3, 2024
3f1f991
Update gibbs.py unknowns to keep unknowns
andy6a May 3, 2024
6e837a8
Update _plot.py unknowns to keep unknowns
andy6a May 3, 2024
721d657
Update gibbs.py
andy6a May 3, 2024
5e6e021
Update _plot.py
andy6a May 3, 2024
3258b4f
Update _plot.py
andy6a May 3, 2024
75ba827
Update _plot.py
andy6a May 3, 2024
b572ae4
Update _plot.py
andy6a May 3, 2024
3fd4515
Update _plot.py
andy6a May 3, 2024
d3f1716
Update _plot.py
andy6a May 3, 2024
13272c1
Update _plot.py Remove ST_bar
andy6a May 7, 2024
30de33b
Update _plot.py
andy6a May 7, 2024
448b476
Update _plot.py
andy6a May 7, 2024
d008ebf
Update _plot.py
andy6a May 7, 2024
56f7b0f
Update _plot.py remove white space hopefully.
andy6a May 28, 2024
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ you can install it directly from the github repository.

**Note: Only run this if you wish to use the development version**
```bash
pip install https://github.com/biota/sourcetracker2/archive/master.zip
pip install https://github.com/caporaso-lab/sourcetracker2/archive/master.zip
```

To test that your installation was successful, try the following command:
Expand Down
3 changes: 1 addition & 2 deletions sourcetracker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@

from ._compare import compare_sinks, compare_sink_metrics
from ._sourcetracker import gibbs
from ._plot import plot_heatmap


__version__ = '2.0.1-dev'
_readme_url = "https://github.com/biota/sourcetracker2/blob/master/README.md"

__all__ = ['compare_sinks', 'compare_sink_metrics', 'gibbs', 'plot_heatmap']
__all__ = ['compare_sinks', 'compare_sink_metrics', 'gibbs']
cherman2 marked this conversation as resolved.
Show resolved Hide resolved
58 changes: 49 additions & 9 deletions sourcetracker/_cli/gibbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from sourcetracker._cli.cli import cli
from sourcetracker._gibbs import gibbs_helper
from sourcetracker._plot import plot_heatmap
from sourcetracker._plot import ST_graphs
from sourcetracker._util import parse_sample_metadata, biom_to_df

# import default descriptions
Expand All @@ -29,7 +29,11 @@
DESC_RAF2, DESC_RST, DESC_DRW,
DESC_BRN, DESC_DLY, DESC_PFA,
DESC_RPL, DESC_SNK, DESC_SRS,
DESC_SRS2, DESC_CAT)
DESC_SRS2, DESC_CAT, DESC_DIA,
DESC_LIM, DESC_STBAR, DESC_HTM,
DESC_PHTM, DESC_TTL, DESC_HCOL,
DESC_UKN, DESC_TRA, DESC_BCOL,
DESC_FLBR)

# import default values
from sourcetracker._gibbs_defaults import (DEFAULT_ALPH1, DEFAULT_ALPH2,
Expand Down Expand Up @@ -120,9 +124,28 @@
help=DESC_CAT)
# Stats functions for diagnostics
@click.option('--diagnostics', required=False, default=False, is_flag=True,
show_default=True)
show_default=True, help=DESC_DIA)
@click.option('--limit', required=False, default=0.05, type=click.FLOAT,
show_default=True)
show_default=True, help=DESC_LIM)
# (added options for graphical ouput and varying stats functions)
@click.option('--stacked_bar', required=False, default=False, is_flag=True,
show_default=True, help=DESC_STBAR)
@click.option('--heatmap', required=False, default=True, is_flag=True,
show_default=True, help=DESC_HTM)
@click.option('--paired_heatmap', required=False, default=False, is_flag=True,
show_default=True, help=DESC_PHTM)
@click.option('--title', required=False, default='Mixing Proportions',
type=click.STRING, show_default=True, help=DESC_TTL)
@click.option('--heatmap_color', required=False, default='viridis',
type=click.STRING, show_default=True, help=DESC_HCOL)
@click.option('--keep_unknowns', required=False, default=True, is_flag=True,
show_default=True, help=DESC_UKN)
@click.option('--transpose', required=False, default=False, is_flag=True,
show_default=True, help=DESC_TRA)
@click.option('--bar_color', required=False, default="", type=click.STRING,
show_default=True, help=DESC_BCOL)
@click.option('--flip_bar', required=False, default=False, is_flag=True,
show_default=True, help=DESC_FLBR)
def gibbs(table_fp: Table,
mapping_fp: pd.DataFrame,
output_dir: str,
Expand All @@ -144,7 +167,16 @@ def gibbs(table_fp: Table,
sink_column_value: str,
source_category_column: str,
diagnostics: bool,
limit: float):
limit: float,
stacked_bar: bool,
heatmap: bool,
paired_heatmap: bool,
title: str,
heatmap_color: str,
keep_unknowns: bool,
transpose: bool,
bar_color: str,
flip_bar: bool):
'''Gibb's sampler for Bayesian estimation of microbial sample sources.

For details, see the project README file.
Expand Down Expand Up @@ -180,11 +212,19 @@ def gibbs(table_fp: Table,
mpm.to_csv(os.path.join(output_dir, 'mixing_proportions.txt'), sep='\t')
mps.to_csv(os.path.join(output_dir, 'mixing_proportions_stds.txt'),
sep='\t')

# need to count number of rows here to check for equality
# add notice if not equal
color_list = bar_color.split(",")
# Plot contributions.
fig, ax = plot_heatmap(mpm.T)
fig.savefig(os.path.join(output_dir, 'mixing_proportions.pdf'), dpi=300)

graphs = ST_graphs(mpm, output_dir, title=title, color=heatmap_color)
if heatmap:
graphs.ST_heatmap(keep_unknowns=keep_unknowns)
if paired_heatmap:
graphs.ST_paired_heatmap(keep_unknowns=keep_unknowns,
normalized=transpose, transpose=transpose)
if stacked_bar:
graphs.ST_Stacked_bar(keep_unknowns=keep_unknowns, coloring=color_list,
flipped=flip_bar)
if diagnostics:
os.mkdir(output_dir + 'diagnostics')
data = np.load('envcounts.npy', allow_pickle=True)
Expand Down
34 changes: 34 additions & 0 deletions sourcetracker/_gibbs_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,37 @@
'sink (or source if `--loo is passed). '
'This feature table contains the specific '
' of each fractional contribution.')
DESC_DIA = ('Activate diagnostics function which visualizes the '
'deviation of each SourceTracker run, requires'
'at least 2 restarts. Default is False.')
DESC_LIM = ('Minimum deviation limit for display. Default value'
'of 0.05')
DESC_STBAR = ('Activates stacked bar plot visualization.'
'Default is False.')
DESC_HTM = ('Deactivates Heatmap plot. Default is True.')
DESC_PHTM = ('Activates Paired heatmap visualization. Paired'
'heatmap intends to visualize pairings for sourcetracker'
'to identify these pairings. Non random pairings are '
'identified by the highest result in each column. '
'For each correct pairing, the resulting proportion '
'should be calculated against a binomial distribution '
'with a p value calculated against random distribution '
'with a correct proportion of 1/n at random.'
'This can be used for groupings such as convergent '
'microbiomes or organ transfer similarities as a few'
' examples.')
DESC_TTL = ('Title input. String format')
DESC_HCOL = ('Heatmap coloring. Coloring pattern for default and'
' paired heatmap. Default is viridis, other options in'
' plot.py.')
DESC_UKN = ('keep unknown sources in heatmap or stacked bar plots.'
'IMPORTANT: Setting to False will normalize proportions back to'
'1.')
DESC_TRA = ('Transpose Heatmap plots.Flips x and y axis. Default is'
' False.')
DESC_BCOL = ('Coloring for stacked bar plot. Default is matplotlib'
' default. List format should be used.'
'An example of this would be [red,green,blue] with'
' each color in a string format.')
DESC_FLBR = ('Transpose bar plot. Flips x and y axis. Default is'
' False.')
Loading
Loading