1 load libraries

2 Load Seurat Object


All_samples_Merged <- readRDS("../../../../0-Seurat_RDS_Final_OBJECT/All_samples_Merged_with_Renamed_Clusters_final-26-10-2025.rds")

DefaultAssay(All_samples_Merged) <- "RNA"

# If RNA has not been normalized yet, run NormalizeData (safe to run again)
All_samples_Merged <- NormalizeData(All_samples_Merged,
                                    normalization.method = "LogNormalize",
                                    scale.factor = 1e4,
                                    verbose = TRUE)
Performing log-normalization
0%   10   20   30   40   50   60   70   80   90   100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|

3 Run CyteTypeR for cluster annotation

Idents(All_samples_Merged) <- "seurat_clusters"

# ---------------------------------------------------------
# 2️⃣ Find marker genes per cluster
SS_markers <- FindAllMarkers(
  All_samples_Merged,
  only.pos = TRUE,
  min.pct = 0.25,
  logfc.threshold = 0.25,
  min.pct.diff = 0.2
  
)

library(dplyr)

# Precise blacklist for uninformative genes
blacklist_patterns <- c(
  "^TRAV", "^TRBV", "^TRGV", "^TRDV", "^TRBC", "^TRAC", "^TRDC", "^TRGC", # TCR
  "^IGH", "^IGK", "^IGL", "^IGJ",                                         # Ig genes
  "^RPL", "^RPS",                                                         # ribosomal
  "^MT-",                                                                 # mitochondria
  "^HBA", "^HBB", "^HB[ABZ]",                                             # hemoglobins
  "^NEAT1$", "^MALAT1$",                                                  # optional lncRNAs
  "^XIST$"                              )

blacklist_regex <- paste(blacklist_patterns, collapse = "|")

# Preview which markers will be removed
to_remove <- SS_markers %>%
  filter(grepl(blacklist_regex, gene, ignore.case = TRUE))
message("Rows to remove: ", nrow(to_remove))
head(to_remove$gene)
[1] "TRAV17"  "TRAV9-2" "RPL22L1" "RPL7"    "RPL35A"  "NEAT1"  
# Filter markers (keep important metabolic/proliferation genes)
SS_markers_filtered <- SS_markers %>%
  filter(!grepl(blacklist_regex, gene, ignore.case = TRUE))

4 Run CyteTypeR for cluster annotation

library(CyteTypeR)
library(dplyr)
# -------------------------------
# Prepare data for CyteTypeR
# -------------------------------
prepped_data <- PrepareCyteTypeR(
  All_samples_Merged,
  SS_markers_filtered,
  n_top_genes = 25,               # top 10 marker genes per cluster
  group_key = 'renamed_clusters',  # must match Seurat object
  aggregate_metadata = TRUE,
  coordinates_key = "umap"
)



# -------------------------------
# Metadata for CyteTypeR
# -------------------------------
metadata <- list(
  title = 'My scRNA-seq analysis of human Sézary syndrome ',
  run_label = 'initial_analysis',
  experiment_name = 'Sézary_Syndrome_Cell_lines_human_samples_study'
)


# Remove both literal "NA" and true NA names
prepped_data$clusterMetadata <- prepped_data$clusterMetadata[
  !is.na(names(prepped_data$clusterMetadata)) & 
  names(prepped_data$clusterMetadata) != "NA"
]

# Confirm cleanup
names(prepped_data$clusterMetadata)





# -------------------------------
# Run CyteTypeR
# -------------------------------
results <- CyteTypeR(
  obj = All_samples_Merged,
  prepped_data = prepped_data,
  study_context = "Sezary syndrome blood samples from humans cell lines derived from Patients and CD4T_lab and CD4T_10x are purified CD4 T cells from healthy donors in orig.ident",
  metadata = metadata
)

# -------------------------------
# Check results
# -------------------------------
# If job succeeds, retrieve results:
# GetResults(results)

#saveRDS(results, file = "CyteTypeR_results_SS_cell_lines_finalized.rds")

5 Run CyteTypeR for cluster Visualization



DimPlot(results, group.by = "cytetype_cell_ontology_renamed_clusters", label = T, label.box = T,repel = T, reduction = "umap")

DimPlot(results, group.by = "cytetype_renamed_clusters", label = F, label.box = T,repel = T, reduction = "umap")

NA
NA

https://nygen-labs-prod--cytetype-api.modal.run/report/b82fefe9-555f-4de9-8030-4e74bbde5035

LS0tCnRpdGxlOiAiQ3l0ZVR5cGVSIEFubm90YXRpb24gdXNpbmcgQUlfcmVuYW1lZF9jbHVzdGVycyIKYXV0aG9yOiAiTmFzaXIgTWFobW9vZCBBYmJhc2kiCmRhdGU6ICJgciBmb3JtYXQoU3lzLnRpbWUoKSwgJyVCICVkLCAlWScpYCIKb3V0cHV0OgogIGh0bWxfbm90ZWJvb2s6CiAgICBudW1iZXJfc2VjdGlvbnM6IHRydWUKICAgIHRvYz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