Skip to content

Commit

Permalink
Merge branch 'master' into docker_windows
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-l-kong committed May 3, 2022
2 parents 7c8c70c + 2de0c73 commit dfca6b3
Show file tree
Hide file tree
Showing 50 changed files with 8,099 additions and 4,417 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ data/example_dataset/metaclustering/example_manually_adjust_metaclusters.ipynb
Pipfile
Pipfile.lock
.coverage
.python-version
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ jobs:
if: tag IS present
python: 3.6
script:
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
- "travis_wait 20 sleep 1200 &"
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
- docker build -t "$TRAVIS_REPO_SLUG" .
- docker tag "$TRAVIS_REPO_SLUG" "$TRAVIS_REPO_SLUG":latest
- docker tag "$TRAVIS_REPO_SLUG" "$TRAVIS_REPO_SLUG":"${TRAVIS_TAG}"
Expand Down
10 changes: 9 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM python:3.6

# system maintenance
RUN apt-get update && apt-get install -y gcc
RUN apt-get update && apt-get install -y gcc r-base

WORKDIR /scripts

Expand All @@ -16,5 +16,13 @@ COPY ark /opt/ark-analysis/ark
# Install the package via setup.py
RUN pip install /opt/ark-analysis

# Install R dependency packages
RUN R -e "install.packages('https://cran.r-project.org/src/contrib/Archive/BH/BH_1.75.0-0.tar.gz', repos=NULL, type='source')"
RUN R -e "install.packages('arrow')"
RUN R -e "install.packages('data.table')"
RUN R -e "install.packages('BiocManager')"
RUN R -e "BiocManager::install('FlowSOM')"
RUN R -e "BiocManager::install('ConsensusClusterPlus')"

# jupyter lab
CMD jupyter lab --ip=0.0.0.0 --allow-root --no-browser --port=$JUPYTER_PORT --notebook-dir=/$JUPYTER_DIR
43 changes: 32 additions & 11 deletions ark/analysis/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from ark.utils import misc_utils


def draw_boxplot(cell_data, col_name, col_split=None, split_vals=None, dpi=None, save_dir=None):
def draw_boxplot(cell_data, col_name, col_split=None,
split_vals=None, dpi=None, save_dir=None, save_file=None):
"""Draws a boxplot for a given column, optionally with help from a split column
Args:
Expand All @@ -23,6 +24,9 @@ def draw_boxplot(cell_data, col_name, col_split=None, split_vals=None, dpi=None,
The resolution of the image to save, ignored if save_dir is None
save_dir (str):
If specified, a directory where we will save the plot
save_file (str):
If save_dir specified, specify a file name you wish to save to.
Ignored if save_dir is None
"""

# the col_name must be valid
Expand Down Expand Up @@ -61,11 +65,12 @@ def draw_boxplot(cell_data, col_name, col_split=None, split_vals=None, dpi=None,

# save visualization to a directory if specified
if save_dir is not None:
misc_utils.save_figure(save_dir, "boxplot_viz.png", dpi=dpi)
misc_utils.save_figure(save_dir, save_file, dpi=dpi)


def draw_heatmap(data, x_labels, y_labels, dpi=None, center_val=None,
overlay_values=False, colormap="vlag", save_dir=None):
def draw_heatmap(data, x_labels, y_labels, dpi=None, center_val=None, min_val=None, max_val=None,
cbar_ticks=None, colormap="vlag", row_colors=None, row_cluster=True,
col_colors=None, col_cluster=True, save_dir=None, save_file=None):
"""Plots the z scores between all phenotypes as a clustermap.
Args:
Expand All @@ -79,12 +84,27 @@ def draw_heatmap(data, x_labels, y_labels, dpi=None, center_val=None,
The resolution of the image to save, ignored if save_dir is None
center_val (float):
value at which to center the heatmap
overlay_values (bool):
whether to overlay the raw heatmap values on top
min_val (float):
minimum value the heatmap should take
max_val (float):
maximum value the heatmap should take
cbar_ticks (int):
list of values containing tick labels for the heatmap colorbar
colormap (str):
color scheme for visualization
row_colors (list):
Include these values as an additional color-coded cluster bar for row values
row_cluster (bool):
Whether to include dendrogram clustering for the rows
col_colors (list):
Include these values as an additional color-coded cluster bar for column values
col_cluster (bool):
Whether to include dendrogram clustering for the columns
save_dir (str):
If specified, a directory where we will save the plot
save_file (str):
If save_dir specified, specify a file name you wish to save to.
Ignored if save_dir is None
"""

# Replace the NA's and inf values with 0s
Expand All @@ -95,13 +115,14 @@ def draw_heatmap(data, x_labels, y_labels, dpi=None, center_val=None,
data_df = pd.DataFrame(data, index=x_labels, columns=y_labels)
sns.set(font_scale=.7)

if overlay_values:
sns.clustermap(data_df, cmap=colormap, annot=data, center=center_val)
else:
sns.clustermap(data_df, cmap=colormap, center=center_val)
sns.clustermap(
data_df, cmap=colormap, center=center_val,
vmin=min_val, vmax=max_val, row_colors=row_colors, row_cluster=row_cluster,
col_colors=col_colors, col_cluster=col_cluster, cbar_kws={'ticks': cbar_ticks}
)

if save_dir is not None:
misc_utils.save_figure(save_dir, "z_score_viz.png", dpi=dpi)
misc_utils.save_figure(save_dir, save_file, dpi=dpi)


def get_sorted_data(cell_data, sort_by_first, sort_by_second, is_normalized=False):
Expand Down
4 changes: 2 additions & 2 deletions ark/analysis/visualize_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_draw_heatmap():

# test that with save_dir, we do save
visualize.draw_heatmap(z, pheno_titles, pheno_titles,
save_dir=temp_dir)
save_dir=temp_dir, save_file="z_score_viz.png")
assert os.path.exists(os.path.join(temp_dir, "z_score_viz.png"))


Expand Down Expand Up @@ -66,7 +66,7 @@ def test_draw_boxplot():
with tempfile.TemporaryDirectory() as temp_dir:
visualize.draw_boxplot(cell_data=random_data, col_name="A",
col_split=settings.PATIENT_ID, split_vals=[1, 2],
save_dir=temp_dir)
save_dir=temp_dir, save_file="boxplot_viz.png")
assert os.path.exists(os.path.join(temp_dir, "boxplot_viz.png"))


Expand Down
Loading

0 comments on commit dfca6b3

Please sign in to comment.