-
Notifications
You must be signed in to change notification settings - Fork 13
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
Adding spherized profiles #60
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
84c95e1
add spherize notebook
gwaybio fe513d4
Merge remote-tracking branch 'upstream/master' into spherize
gwaybio f5b64e2
add batch 2 spherize processing
gwaybio 88feafd
add spherized profiles
gwaybio 502c610
move folders
gwaybio 26990ab
add multiple spherize outputs
gwaybio 681f215
add spherized data
gwaybio b34fb37
update READMEs
gwaybio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,7 +75,7 @@ | |
|
||
cmd = [ | ||
"python", | ||
"profile.py", | ||
"profile_cells.py", | ||
"--sql_file", | ||
sql_file, | ||
"--batch", | ||
|
3 changes: 3 additions & 0 deletions
3
.../2016_04_01_a549_48hr_batch1_dmso_spherized_profiles_with_input_normalized_by_dmso.csv.gz
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
...4_01_a549_48hr_batch1_dmso_spherized_profiles_with_input_normalized_by_whole_plate.csv.gz
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
...s/profiles/2017_12_05_Batch2_dmso_spherized_profiles_with_input_normalized_by_dmso.csv.gz
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
...les/2017_12_05_Batch2_dmso_spherized_profiles_with_input_normalized_by_whole_plate.csv.gz
Git LFS file not shown
100 changes: 100 additions & 0 deletions
100
spherized_profiles/scripts/nbconverted/spherize-batch-effects.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#!/usr/bin/env python | ||
# coding: utf-8 | ||
|
||
# ## Adjust batch effects with a spherize transform | ||
# | ||
# Here, we load in all normalized profiles (level 4a) data across all plates and apply a spherize transform using the DMSO profiles as the background distribution. | ||
# | ||
# We've previously observed that sphering (aka whitening) the data successfully adjusts for technical artifacts induced by batch to batch variation and plate position effects. | ||
|
||
# In[1]: | ||
|
||
|
||
import os | ||
import pathlib | ||
import subprocess | ||
import pandas as pd | ||
|
||
from pycytominer import normalize, feature_select | ||
from pycytominer.cyto_utils import output, infer_cp_features | ||
|
||
|
||
# In[2]: | ||
|
||
|
||
input_dir = pathlib.Path("../profiles/") | ||
batches = ["2016_04_01_a549_48hr_batch1", "2017_12_05_Batch2"] | ||
|
||
suffixes = { | ||
"whole_plate": "_normalized.csv.gz", | ||
"dmso": "_normalized_dmso.csv.gz" | ||
} | ||
|
||
plates = { | ||
batch: [x.name for x in pathlib.Path(f"{input_dir}/{batch}").iterdir() if ".DS_Store" not in x.name] | ||
for batch in batches | ||
} | ||
|
||
files = { | ||
batch: { | ||
suffix: [pathlib.Path(f"{input_dir}/{batch}/{x}/{x}{suffixes[suffix]}") for x in plates[batch]] | ||
for suffix in suffixes | ||
} | ||
for batch in batches | ||
} | ||
|
||
feature_select_ops = [ | ||
"variance_threshold", | ||
"correlation_threshold", | ||
"drop_na_columns", | ||
"blacklist", | ||
"drop_outliers" | ||
] | ||
|
||
na_cut = 0 | ||
corr_threshold = 0.95 | ||
outlier_cutoff = 60 | ||
|
||
output_dir = "profiles" | ||
|
||
|
||
# In[3]: | ||
|
||
|
||
for batch in batches: | ||
for suffix in suffixes: | ||
output_file = pathlib.Path( | ||
f"{output_dir}/{batch}_dmso_spherized_profiles_with_input_normalized_by_{suffix}.csv.gz" | ||
) | ||
print(f"Now processing {output_file}...") | ||
|
||
profile_df = pd.concat([pd.read_csv(x) for x in files[batch][suffix]]).reset_index(drop=True) | ||
|
||
# Perform feature selection | ||
profile_df = feature_select( | ||
profiles=profile_df, | ||
operation=feature_select_ops, | ||
na_cutoff=0, | ||
corr_threshold=corr_threshold, | ||
outlier_cutoff=outlier_cutoff | ||
) | ||
|
||
print(profile_df.shape) | ||
profile_df.head() | ||
|
||
spherize_df = normalize( | ||
profiles=profile_df, | ||
features="infer", | ||
meta_features="infer", | ||
samples="Metadata_broad_sample == 'DMSO'", | ||
method="whiten", | ||
) | ||
|
||
print(spherize_df.shape) | ||
spherize_df.head() | ||
|
||
output( | ||
df=spherize_df, | ||
output_filename=output_file | ||
) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've not read the whole thing yet, but I wonder if you should mention the existence of spherized data somewhere here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, good point