SKILL.md
Version Compatibility
Reference examples tested with: matplotlib 3.8+, numpy 1.26+, pandas 2.2+, scipy 1.12+
Before using code patterns, verify installed versions match. If versions differ:
- Python:
pip show <package>thenhelp(module.function)to check signatures
If code throws ImportError, AttributeError, or TypeError, introspect the installed package and adapt the example to match the actual API rather than retrying.
Quality Metrics
"Assess quality of my IMC acquisition" → Evaluate IMC data quality through signal-to-noise ratios, channel correlations, tissue integrity scores, and acquisition-specific QC metrics.
- Python:
numpy/scipyfor SNR calculation and channel correlation analysis
Signal-to-Noise Ratio
import numpy as np
from scipy import ndimage
from skimage import io
def calculate_snr(image, mask=None):
'''Calculate signal-to-noise ratio for an image channel.'''
if mask is None:
mask = image > np.percentile(image, 10)
signal = np.mean(image[mask])
noise = np.std(image[~mask])
if noise == 0:
return np.inf
snr = signal / noise
return snr
def calculate_snr_all_channels(image_stack, channel_names, tissue_mask=None):
'''Calculate SNR for all channels in stack.'''
results = {}
for i, name in enumerate(channel_names):
snr = calculate_snr(image_stack[i], tissue_mask)
results[name] = snr
return results
image_stack = io.imread('imc_image.tiff')
channel_names = ['CD45', 'CD3', 'CD68', 'panCK', 'DNA']
snr_values = calculate_snr_all_channels(image_stack, channel_names)
for ch, snr in snr_values.items():
status = 'PASS' if snr > 3 else 'WARN' if snr > 1.5 else 'FAIL'
print(f'{ch}: SNR = {snr:.2f} [{status}]')
Channel Correlation
def calculate_channel_correlation(image_stack, channel_names):
'''Calculate pairwise correlation between channels.'''
n_channels = image_stack.shape[0]
flat_data = image_stack.reshape(n_channels, -1)
corr_matrix = np.corrcoef(flat_data)
import pandas as pd
corr_df = pd.DataFrame(corr_matrix, index=channel_names, columns=channel_names)
return corr_df
def flag_unexpected_correlations(corr_df, expected_pairs=None, threshold=0.7):
'''Flag unexpected high correlations (possible spillover).'''
issues = []
if expected_pairs is None:
expected_pairs = []
for i, ch1 in enumerate(corr_df.columns):
for j, ch2 in enumerate(corr_df.columns):
if i >= j:
continue
corr = corr_df.loc[ch1, ch2]
pair = (ch1, ch2)
is_expected = pair in expected_pairs or (ch2, ch1) in expected_pairs
if corr > threshold and not is_expected:
issues.append({'channel_1': ch1, 'channel_2': ch2, 'correlation': corr, 'expected': is_expected})
return pd.DataFrame(issues)
corr_matrix = calculate_channel_correlation(image_stack, channel_names)
print('Channel correlations:')
print(corr_matrix.round(2))
expected = [('CD3', 'CD45')]
issues = flag_unexpected_correlations(corr_matrix, expected)
if len(issues) > 0:
print('\nUnexpected high correlations:')
print(issues)
