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

QC for TMAs and Control Samples #358

Merged
merged 32 commits into from
Jul 20, 2023
Merged

Conversation

srivarra
Copy link
Contributor

@srivarra srivarra commented Apr 14, 2023

If you haven't already, please read through our contributing guidelines before opening your PR

What is the purpose of this PR?

Closes #277.
Closes #362.
Adds QC metric for TMAs, and for tissue wide-batch effects.

How did you implement your changes

Added helper functions for ranking TMAs and computing tissue QC metrics.
Added plotting functions for QC TMA metrics, and updated the batch effect plot functions.

Sample Figures from the TONIC Cohort

TMA QC Plot
TONIC_TMA1_99 9% intensity value
TONIC_TMA1_Non-zero mean intensity

Violin Plot, for CD*
ln_nonzero_mean_stats
ln_bottom_nonzero_mean_stats
ln_top_nonzero_mean_stats

In addition, other notable changes include adding a Random number generator Fixture in conftest.py, so for any test, we can just add that fixture as a function argument like below:

def test_function_requries_random_numbers(rng: np.random.Generator):
    my_cool_random_numbers = rng.random(size=(10,))
    ...

Adjusted some Pandas function calls to be Pandas 2.0 compatible (Notably you cannot pd.append DataFrames, you must pd.concat them). In the future we can take advantage of 2.0 features.

Dependency Modifications:

  • Bumped scipy to >=1.10.1
  • Added loguru as a dev dependency.

Remaining issues

  • Run the QC TMA on the Tonic Cohort
  • Ran into some issues w.r.t image_stitching.get_tiled_names where some FOVs would return
        {"tonsil_bottom": "fov-1-scan-1"}
    instead of say,
        {"RnCm": "fov-1-scan-1"}
    Is this expected behavior for some jsons?

Next Steps

  • Need to create a notebook which encapsulates all of these QC metrics (design doc needed)
  • Need to add QC metrics as a function of acquisition order (design doc needed)

@srivarra srivarra added the enhancement New feature or request label Apr 14, 2023
@srivarra srivarra self-assigned this Apr 14, 2023
@srivarra srivarra marked this pull request as ready for review April 17, 2023 17:52
@ngreenwald
Copy link
Member

This looks great. Can you open a new issue and self-assign for adding a ranks for the TMA-wide QC tissue ranks?

Right now, the only way to see if a specific TMA has a control sample that is higher (or lower) than all the others is to look by eye at the color of each dot and see if a specific colored dot is most often at the top or bottom of the violin. Having a way to automatically check this would be helpful.

I think you can copy what you did in the first part, averaging the rank across different markers. It would be useful to compute that same ranking for the control tissues. So instead of creating a rank across the 50 FOVs in an TMA, it would be across the 3 or 4 different LN_Top samples.

Copy link
Member

@ngreenwald ngreenwald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The visualization looks good, let me know once you've generated the plots for each TMA so we can confirm there are no spatial effects.

Copy link
Contributor

@camisowers camisowers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Are we adding in a notebook for this as well?

src/toffy/qc_comp.py Outdated Show resolved Hide resolved
@srivarra
Copy link
Contributor Author

@camisowers Yeah the notebook will be the final PR for these extra QCs.

@camisowers camisowers mentioned this pull request Apr 19, 2023
3 tasks
Copy link
Contributor

@alex-l-kong alex-l-kong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, one comment regarding condensing a deeply nested loop.

src/toffy/qc_comp.py Outdated Show resolved Hide resolved
@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

Copy link
Member

@ngreenwald ngreenwald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functionality looks great, added a bunch of comments about simplifying the notebook.

Copy link
Contributor

@camisowers camisowers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good to me!

pyproject.toml Outdated Show resolved Hide resolved
src/toffy/qc_comp.py Show resolved Hide resolved
@srivarra srivarra changed the title QC for TMAs QC for TMAs and Batches Jun 17, 2023
@srivarra srivarra requested a review from ngreenwald July 14, 2023 19:47
@srivarra
Copy link
Contributor Author

@ngreenwald How does the notebook look after these updates?

Copy link
Member

@ngreenwald ngreenwald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, some more notebook simplifications

pyproject.toml Show resolved Hide resolved
templates/6_tma_batch_qc_metrics.ipynb Show resolved Hide resolved
templates/6_tma_batch_qc_metrics.ipynb Show resolved Hide resolved
templates/6_tma_batch_qc_metrics.ipynb Show resolved Hide resolved
templates/6_tma_batch_qc_metrics.ipynb Show resolved Hide resolved
templates/6_tma_batch_qc_metrics.ipynb Show resolved Hide resolved
templates/6_tma_batch_qc_metrics.ipynb Show resolved Hide resolved
templates/6_tma_batch_qc_metrics.ipynb Show resolved Hide resolved
@srivarra srivarra changed the title QC for TMAs and Batches QC for TMAs and Control Samples Jul 17, 2023
@srivarra srivarra requested a review from ngreenwald July 17, 2023 21:23
Copy link
Member

@ngreenwald ngreenwald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple issues from first round that didn't get completely addressed. Make sure to glance over the full notebook before re-requesting review. Almost there!

@srivarra srivarra requested a review from ngreenwald July 20, 2023 18:10
Copy link
Member

@ngreenwald ngreenwald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@ngreenwald ngreenwald merged commit 1dabc9f into main Jul 20, 2023
4 checks passed
@ngreenwald ngreenwald deleted the qc/location_specific_image_artifacts branch July 20, 2023 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TMA-wide QC Tissue Ranks Plot marker intensity as a function of image location
4 participants