Skip to content

Commit 2982557

Browse files
author
pubudu
committed
Update hands-on z-score
1 parent 8d3d173 commit 2982557

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

content/6.Vectorized_Operations_in_NumPy.md

+21
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,27 @@ std_diff = diff_z_scores.std()
720720
z_score_ratios = diff_z_scores / std_diff
721721
print_array_info(z_score_ratios)
722722
print(z_score_ratios[:10])
723+
724+
## Rank genes according to the Z score ratio
725+
726+
### """
727+
# The Z-ratio provides a standardized measure of the difference between conditions for each gene.
728+
# Dividing by the SD (difference - all genes) accounts for the overall variability in the experiment.
729+
# A gene showing a difference of, say, 0.5 in average Z-score might be highly significant if most genes show very little difference (small Z-score difference - SD), but not significant if many genes show large differences (large Z-score difference - SD).
730+
# It puts the individual gene's change in the context of the overall experimental variation.
731+
### """
732+
733+
### Sort z_score_ratio in descending order and access indices
734+
### Rank genes using indices
735+
736+
gene_list = ["ACTR3B", "ANLN", "APOBEC3G", "AURKA", "BAG1", "BCL2", "BIRC5", "BLVRA", "CCL5", "CCNB1", "CCNE1", "CCR2", "CD2", "CD27", "CD3D", "CD52", "CD68", "CDC20", "CDC6", "CDH3", "CENPF", "CEP55", "CORO1A", "CTSL2", "CXCL9", "CXXC5", "EGFR", "ERBB2", "ESR1", "EXO1", "FGFR4", "FOXA1", "FOXC1", "GAPDH", "GPR160", "GRB7", "GSTM1", "GUSB", "GZMA", "GZMK", "HLA-DMA", "IL2RG", "KIF2C", "KRT14", "KRT17", "KRT5", "LCK", "MAPT", "MDM2", "MELK", "MIA", "MKI67", "MLPH", "MMP11", "MRPL19", "MYBL2", "MYC", "NAT1", "NDC80", "NUF2", "ORC6", "PGR", "PHGDH", "PRKCB", "PSMC4", "PTPRC", "PTTG1", "RRM2", "SCUBE2", "SF3A1", "SFRP1", "SH2D1A", "SLC39A6", "TFRC", "TMEM45B", "TP53", "TYMS", "UBE2C", "UBE2T", "VEGFA"]
737+
738+
### `np.argsort()` returns indices of the array that would sort in ascending order
739+
### slicing syntax [start:stop:step] with step -1 returns a reversed array
740+
741+
gene_ranks = np.argsort(z_score_ratios)[::-1]
742+
print("Genes ranked according to Z-score ratio:")
743+
print(np.array(gene_list)[gene_ranks])
723744
```
724745

725746
:::

0 commit comments

Comments
 (0)