Skip to content

Commit

Permalink
NEW: adds pcoa plot
Browse files Browse the repository at this point in the history
  • Loading branch information
lizgehret authored Oct 7, 2024
2 parents b9aa0ec + 900c1aa commit e5aa087
Show file tree
Hide file tree
Showing 6 changed files with 650 additions and 78 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
channels:
- https://packages.qiime2.org/qiime2/2024.5/tiny/passed
- https://packages.qiime2.org/qiime2/2024.5/amplicon/passed
- conda-forge
- bioconda
dependencies:
- qiime2-tiny
# Note 1: Add any additional conda dependencies here.
- q2-diversity
- pip
- pip:
# Note 2: Add any additional pip dependencies here.
# - # some pip dependency
# Note 3: If you host your repository on GitHub, and you uncomment and modify
# the following lines to replace REPO-OWNER with the user or organization
# name that owns the repository, your installation commands can be updated to
# install from this file without additional steps.
# - "gut-to-soil-manuscript-figures @ git+https://github.com/REPO-OWNER/gut-to-soil-manuscript-figures.git"
- gut_to_soil_manuscript_figures@git+https://github.com/caporaso-lab/gut-to-soil-manuscript-figures.git
78 changes: 75 additions & 3 deletions gut_to_soil_manuscript_figures/_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,80 @@
# The full license is in the file LICENSE, distributed with this software.
# ----------------------------------------------------------------------------

import pandas as pd
import os
import pkg_resources
import skbio
import subprocess

import qiime2

def duplicate_table(table: pd.DataFrame) -> pd.DataFrame:
return table

def pcoa_2d(output_dir: str, metadata: qiime2.Metadata,
ordination: skbio.OrdinationResults,
measure: str = 'Unweighted Unifrac',
average: bool = False, week_annotations: bool = False,
invert_x: bool = False, invert_y: bool = False,
swap_axes: bool = False, himalaya: bool = False,
pit_toilet: bool = False, export_legend: bool = False,
highlighted_buckets: str = ''):

md = metadata.to_dataframe()

metadata_fp = os.path.join(output_dir, 'metadata.tsv')
ordination_fp = os.path.join(output_dir, 'ordination.txt')

md.to_csv(metadata_fp, sep='\t', index_label='sample-id')
ordination.write(ordination_fp)

script_path = \
pkg_resources.resource_filename(
'gut_to_soil_manuscript_figures',
'scripts/plot_pcoa_2d.py'
)

average = str(average)
week_annotations = str(week_annotations)
invert_x = str(invert_x)
invert_y = str(invert_y)
swap_axes = str(swap_axes)
himalaya = str(himalaya)
pit_toilet = str(pit_toilet)
export_legend = str(export_legend)

plot_fp = os.path.join(output_dir, 'pcoa_plot.png')

if export_legend:
legend_fp = os.path.join(output_dir, 'legend.png')

command = [
'python', script_path,
metadata_fp,
ordination_fp,
measure,
average,
week_annotations,
plot_fp,
invert_x,
invert_y,
swap_axes,
himalaya,
pit_toilet,
export_legend,
highlighted_buckets,
legend_fp
]
subprocess.run(command, check=True)

with open(os.path.join(output_dir, 'index.html'), 'w') as f:
f.write('''
<!DOCTYPE html>
<html>
<head>
<title>2D PCoA Plot</title>
</head>
<body>
<h1>2D PCoA Plot</h1>
<img src="pcoa_plot.png" alt="PCoA Plot">
</body>
</html>
''')
55 changes: 30 additions & 25 deletions gut_to_soil_manuscript_figures/plugin_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,41 @@
# The full license is in the file LICENSE, distributed with this software.
# ----------------------------------------------------------------------------

from qiime2.plugin import Citations, Plugin
from q2_types.feature_table import FeatureTable, Frequency
from gut_to_soil_manuscript_figures import __version__
from gut_to_soil_manuscript_figures._methods import duplicate_table
from qiime2.plugin import Plugin, Metadata, Bool, Str

from q2_types.ordination import PCoAResults

citations = Citations.load("citations.bib", package="gut_to_soil_manuscript_figures")
from gut_to_soil_manuscript_figures import __version__
from gut_to_soil_manuscript_figures._methods import pcoa_2d

plugin = Plugin(
name="gut-to-soil-manuscript-figures",
name='gut-to-soil-manuscript-figures',
version=__version__,
website="https://github.com/caporaso-lab/gut-to-coil-manuscript-figures/",
package="gut_to_soil_manuscript_figures",
description="Plugin that contains methods for figure generation used in Jeff Meilander's PhD manuscript",
short_description="Plugin template.",
# The plugin-level citation of 'Caporaso-Bolyen-2024' is provided as
# an example. You can replace this with citations to other references
# in citations.bib.
citations=[citations['Caporaso-Bolyen-2024']]
website='https://github.com/caporaso-lab/gut-to-coil-manuscript-figures/',
package='gut_to_soil_manuscript_figures',
description="Plugin that contains methods for figure generation used in"
" Jeff Meilander's PhD manuscript.",
short_description=''
)

plugin.methods.register_function(
function=duplicate_table,
inputs={'table': FeatureTable[Frequency]},
parameters={},
outputs=[('new_table', FeatureTable[Frequency])],
input_descriptions={'table': 'The feature table to be duplicated.'},
plugin.visualizers.register_function(
function=pcoa_2d,
inputs={'ordination': PCoAResults},
parameters={
'metadata': Metadata,
'measure': Str,
'average': Bool,
'week_annotations': Bool,
'invert_x': Bool,
'invert_y': Bool,
'swap_axes': Bool,
'himalaya': Bool,
'pit_toilet': Bool,
'export_legend': Bool,
'highlighted_buckets': Str
},
input_descriptions={},
parameter_descriptions={},
output_descriptions={'new_table': 'The duplicated feature table.'},
name='Duplicate table',
description=("Create a copy of a feature table with a new uuid. "
"This is for demonstration purposes only. 🧐"),
citations=[]
name='',
description=('')
)
Loading

0 comments on commit e5aa087

Please sign in to comment.