-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial Cleanup * Refactor static cell info * Changes to fix ATAC bar plot * Revert back to manually breaking displayNames * Fix build errors * Add Active Exps * Sort, better padding * Map key, Initial cleanup * Add optional stimulation to getDisplayName
- Loading branch information
1 parent
5d22ac7
commit c217072
Showing
18 changed files
with
1,612 additions
and
1,211 deletions.
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
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,173 @@ | ||
export type CellName = | ||
"Myeloid_DCs" | ||
| "pDCs" | ||
| "Naive_B" | ||
| "Mem_B" | ||
| "Plasmablasts" | ||
| "Regulatory_T" | ||
| "Naive_Tregs" | ||
| "Memory_Tregs" | ||
| "Effector_CD4pos_T" | ||
| "Naive_Teffs" | ||
| "Memory_Teffs" | ||
| "Th1_precursors" | ||
| "Th2_precursors" | ||
| "Th17_precursors" | ||
| "Follicular_T_Helper" | ||
| "Naive_CD8_T" | ||
| "Central_memory_CD8pos_T" | ||
| "Effector_memory_CD8pos_T" | ||
| "Gamma_delta_T" | ||
| "Immature_NK" | ||
| "Mature_NK" | ||
| "Memory_NK" | ||
| "HSC" | ||
| "MPP" | ||
| "CMP" | ||
| "MEP" | ||
| "Ery" | ||
| "GMP" | ||
| "LMPP" | ||
| "CLP" | ||
| "CD4Tcell" | ||
| "NKcell" | ||
| "Monocytes" | ||
| "Bulk_B" | ||
| "CD8pos_T" | ||
| "pHSC" | ||
| "LSC" | ||
| "Blast" | ||
|
||
export type CellDisplayName = | ||
"Monocyte" | ||
| "Myeloid dendritic cell" | ||
| "Plasmacytoid dendritic cell" | ||
| "Bulk B cell" | ||
| "Naïve B cell" | ||
| "Memory B cell" | ||
| "Plasmablast" | ||
| "Regulatory CD4+ T cell" | ||
| "Naïve T regulatory cell" | ||
| "Memory T regulatory cell" | ||
| "Effector CD4+ T cell" | ||
| "Naïve T effector cell" | ||
| "Memory T effector cell" | ||
| "Th1 precursor" | ||
| "Th2 precursor" | ||
| "Th17 precursor" | ||
| "T follicular helper cell" | ||
| "CD8+ T cell" | ||
| "Naïve CD8+ T cell" | ||
| "Central memory CD8+ T cell" | ||
| "Effector memory CD8+ T cell" | ||
| "Gamma-delta T cell" | ||
| "Immature NK cell" | ||
| "Mature NK cell" | ||
| "Memory NK cell" | ||
| "Hematopoetic stem cell" | ||
| "Multipotent progenitor" | ||
| "Common myeloid progenitor" | ||
| "Megakaryocyte-erythroid progenitor" | ||
| "Erythrocyte" | ||
| "Granulocyte-monocyte progenitors" | ||
| "Lymphocyte-primed multipotent progenitor" | ||
| "Common lymphoid progenitor" | ||
| "CD4+ T cell" | ||
| "NK cell" | ||
| "Preleukemic Hematopoetic Stem Cells" | ||
| "Leukemia Stem Cells" | ||
| "Leukemic Blast Cells"; | ||
|
||
export type CellQueryValue = | ||
"Myeloid_DCs-U" | ||
| "pDCs-U" | ||
| "Naive_B-U" | ||
| "Naive_B-S" | ||
| "Mem_B-U" | ||
| "Mem_B-S" | ||
| "Plasmablasts-U" | ||
| "Regulatory_T-U" | ||
| "Regulatory_T-S" | ||
| "Naive_Tregs-U" | ||
| "Naive_Tregs-S" | ||
| "Memory_Tregs-U" | ||
| "Memory_Tregs-S" | ||
| "Effector_CD4pos_T-U" | ||
| "Effector_CD4pos_T-S" | ||
| "Naive_Teffs-U" | ||
| "Naive_Teffs-S" | ||
| "Memory_Teffs-U" | ||
| "Memory_Teffs-S" | ||
| "Th1_precursors-U" | ||
| "Th1_precursors-S" | ||
| "Th2_precursors-U" | ||
| "Th2_precursors-S" | ||
| "Th17_precursors-U" | ||
| "Th17_precursors-S" | ||
| "Follicular_T_Helper-U" | ||
| "Follicular_T_Helper-S" | ||
| "Naive_CD8_T-U" | ||
| "Naive_CD8_T-S" | ||
| "Central_memory_CD8pos_T-U" | ||
| "Central_memory_CD8pos_T-S" | ||
| "Effector_memory_CD8pos_T-U" | ||
| "Effector_memory_CD8pos_T-S" | ||
| "Gamma_delta_T-U" | ||
| "Gamma_delta_T-S" | ||
| "Immature_NK-U" | ||
| "Mature_NK-U" | ||
| "Mature_NK-S" | ||
| "Memory_NK-U" | ||
| "HSC" | ||
| "CD34_Cord_Blood" | ||
| "CD34_Bone_Marrow" | ||
| "MPP" | ||
| "CMP" | ||
| "MEP" | ||
| "Ery" | ||
| "GMP" | ||
| "LMPP" | ||
| "CLP" | ||
| "CD4Tcell" | ||
| "NKcell" | ||
| "Monocytes-U" | ||
| "Mono" | ||
| "Monocytes-S" | ||
| "Bulk_B-U" | ||
| "Bcell" | ||
| "Bulk_B-S" | ||
| "CD8pos_T-U" | ||
| "CD8Tcell" | ||
| "CD8pos_T-S" | ||
| "pHSC" | ||
| "LSC" | ||
| "Blast" | ||
|
||
// Static information for each cell | ||
export type CellTypeStaticInfo = { | ||
readonly id: CellName; | ||
readonly displayName: CellDisplayName; | ||
/** | ||
* Display name used in the Cell Lineage Tree. Insert '/' to break name onto multiple lines | ||
*/ | ||
readonly treeDisplayName: string; | ||
readonly unstimImagePath: string; | ||
readonly stimImagePath?: string; | ||
readonly unstimCount: number | ||
readonly stimCount?: number | ||
readonly stimulable: boolean; | ||
readonly queryValues?: { | ||
readonly unstimulated: { Calderon?: CellQueryValue | CellQueryValue[], Corces?: CellQueryValue | CellQueryValue[] }; | ||
readonly stimulated?: { Calderon: CellQueryValue | CellQueryValue[] } | ||
} | ||
readonly color: string; | ||
} | ||
|
||
// Dynamic information that changes depending on use case | ||
export type DynamicCellTypeInfo = { | ||
selected: boolean; | ||
stimulated: "S" | "U" | "B"; | ||
readonly selectable: boolean; | ||
} | ||
|
||
export type CellLineageTreeState = { [key in CellName]: DynamicCellTypeInfo } |
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,118 @@ | ||
import { cellTypeStaticInfo } from "../../common/consts"; | ||
import { CellDisplayName, CellLineageTreeState, CellName, CellQueryValue, CellTypeStaticInfo } from "./types"; | ||
|
||
export const getCellColor = (cell: CellName | CellQueryValue | CellDisplayName): string => { | ||
return Object.values(cellTypeStaticInfo).find((x: CellTypeStaticInfo) => x.id === cell || x.displayName === cell || extractQueryValues(x, "B").includes(cell as CellQueryValue))?.color ?? "#000000" | ||
} | ||
|
||
//In some situations, want to be able to display "stimulated" after. In bar plot, the output is used to get Cell color which would break that | ||
//In these cases, would be extracting from cell query value where that info exists | ||
export const getCellDisplayName = (cell: CellName | CellQueryValue, appendStim = false): string => { | ||
let name = Object.values(cellTypeStaticInfo).find((x: CellTypeStaticInfo) => x.id === cell || extractQueryValues(x, "B").includes(cell as CellQueryValue))?.displayName ?? cell | ||
if (name === cell) console.log("Unable to find display name for " + cell) | ||
if (appendStim && cell.slice(-2) == "-S") name += " (stimulated)" | ||
return name | ||
} | ||
|
||
/** | ||
* | ||
* @param cell CellTypeInfo | ||
* @param want "S" | "U" | "B" The query value(s) wanted | ||
* @returns array of query values | ||
*/ | ||
export const extractQueryValues = (cell: CellTypeStaticInfo, want: "S" | "U" | "B"): (CellQueryValue[]) => { | ||
switch (want) { | ||
case "U": return cell.queryValues?.unstimulated ? [...Object.values(cell.queryValues.unstimulated).flat()] : [] | ||
case "S": return cell.queryValues?.stimulated ? [...Object.values(cell.queryValues.stimulated).flat()] : [] | ||
case "B": return (cell.queryValues?.unstimulated ? Object.values(cell.queryValues.unstimulated).flat() : []).concat(cell.queryValues?.stimulated ? (Object.values(cell.queryValues.stimulated).flat()) : []) | ||
} | ||
} | ||
|
||
const cellNames: CellName[] = [ | ||
"Myeloid_DCs", | ||
"pDCs", | ||
"Naive_B", | ||
"Mem_B", | ||
"Plasmablasts", | ||
"Regulatory_T", | ||
"Naive_Tregs", | ||
"Memory_Tregs", | ||
"Effector_CD4pos_T", | ||
"Naive_Teffs", | ||
"Memory_Teffs", | ||
"Th1_precursors", | ||
"Th2_precursors", | ||
"Th17_precursors", | ||
"Follicular_T_Helper", | ||
"Naive_CD8_T", | ||
"Central_memory_CD8pos_T", | ||
"Effector_memory_CD8pos_T", | ||
"Gamma_delta_T", | ||
"Immature_NK", | ||
"Mature_NK", | ||
"Memory_NK", | ||
"HSC", | ||
"MPP", | ||
"CMP", | ||
"MEP", | ||
"Ery", | ||
"GMP", | ||
"LMPP", | ||
"CLP", | ||
"CD4Tcell", | ||
"NKcell", | ||
"Monocytes", | ||
"Bulk_B", | ||
"CD8pos_T" | ||
] | ||
|
||
/** | ||
* Initial Selected Cells being query values not cell names is convenient right now, but confusing. Consider changing in future to plain names, like {name: cellName, stim: "B" | "U" | "S"} | ||
* @param initialSelectedCells cells to select initially, needs to match query values like Bulk_B-U (NOT CELL NAMES). | ||
* @param interactive disables interacting with nodes | ||
*/ | ||
export const generateCellLineageTreeState = (initialSelectedCells: CellQueryValue[], interactive: boolean): CellLineageTreeState => { | ||
//Some iCREs are active in celltypes (Ex: Blast) that are not in the tree. Need to handle this case. Ex: EH38E0243977 is active in Blast | ||
let cellLineageTreeState = {} as CellLineageTreeState | ||
|
||
for (const cellName of cellNames) { | ||
//Try to find matches in the query values of cellLineageTreeStaticInfo | ||
const unstimSelected = initialSelectedCells.some(cell => extractQueryValues(cellTypeStaticInfo[cellName], "U").includes(cell)) | ||
const stimSelected = initialSelectedCells.some(cell => extractQueryValues(cellTypeStaticInfo[cellName], "S").includes(cell)) | ||
cellLineageTreeState[cellName] = { | ||
selected: unstimSelected || stimSelected, | ||
selectable: interactive, | ||
stimulated: | ||
(unstimSelected && stimSelected) ? "B" : | ||
(unstimSelected && !stimSelected) ? "U" : | ||
(!unstimSelected && stimSelected) ? "S" : | ||
"U" | ||
} | ||
} | ||
|
||
return cellLineageTreeState | ||
} | ||
|
||
const svgData = (_svg): string => { | ||
let svg = _svg.cloneNode(true); | ||
svg.setAttribute('xmlns', 'http://www.w3.org/2000/svg'); | ||
let preface = '<?xml version="1.0" standalone="no"?>'; | ||
return preface + svg.outerHTML.replace(/\n/g, '').replace(/[ ]{8}/g, ''); | ||
}; | ||
|
||
const downloadData = (text: string, filename: string, type: string = 'text/plain') => { | ||
const a = document.createElement('a'); | ||
document.body.appendChild(a); | ||
a.setAttribute('style', 'display: none'); | ||
const blob = new Blob([text], { type }); | ||
const url = window.URL.createObjectURL(blob); | ||
a.href = url; | ||
a.download = filename; | ||
a.click(); | ||
window.URL.revokeObjectURL(url); | ||
a.remove(); | ||
}; | ||
|
||
export const downloadSVG = (ref: React.MutableRefObject<SVGSVGElement>, filename: string) => { | ||
ref.current && downloadData(svgData(ref.current!), filename, 'image/svg;charset=utf-8'); | ||
} |
Oops, something went wrong.