Skip to content

Commit

Permalink
format stat table correctly #7
Browse files Browse the repository at this point in the history
  • Loading branch information
sreichl committed Apr 5, 2024
1 parent 66a1933 commit 54a8851
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions workflow/scripts/mixscape.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ DefaultAssay(object = data) <- assay

# check if data is normalized, if not normalize the data
if (all(GetAssayData(object = data, slot = "counts", assay = assay) == GetAssayData(object = data, slot = "data", assay = assay))){
print("Normalizing data")
data <- NormalizeData(object = data)
}

Expand All @@ -63,6 +64,7 @@ if (variable_features_only==1){

# check if data is scaled, if not scale data
if (dim(GetAssayData(object = data, slot = "scale.data", assay = assay))[1]==0){
print("Scaling data")
data <- ScaleData(object = data, features = features)
}

Expand Down Expand Up @@ -181,8 +183,11 @@ save_seurat_object(seurat_obj=data,
result_dir=dirname(mixscape_object_path),
prefix="ALL_")

# save mixscape statistics
fwrite(as.data.frame(t(stat_table)), file=file.path(mixscape_stats_path), row.names=TRUE)
# refromat & save mixscape statistics
stat_table <- reshape(t(stat_table), timevar = "Var2", idvar = "Var1", direction = "wide")
colnames(stat_table) <- gsub("Freq.", "", colnames(stat_table))
colnames(stat_table)[1] <- "gRNA"
fwrite(as.data.frame(stat_table), file=file.path(mixscape_stats_path), row.names=FALSE)

# save matrix of PRTB values; slots counts and scale.data are emtpy -> only save data slot
fwrite(as.data.frame(GetAssayData(object = data, slot = "data", assay = "PRTB")), file=file.path(prtb_data_path), row.names=TRUE)

0 comments on commit 54a8851

Please sign in to comment.