Question: How to combine seperate seurat meta.data ID;s into one column?
0
gravatar for cook.675
14 months ago by
cook.67560
cook.67560 wrote:

I have an integrated object with 4 data sets (Veh1, Exp1, Veh2, Exp2)

These tags are appended in the object meta data under object$cond

What I would like to do is create a new metadata column called "exp", and label any cell that was labeled as Veh1 or Veh2 as VEH and any cell that was labeled as Exp1/Exp2 as EXP so that it would look something like this when finished:

              orig.ident    cond     seurat_clusters   exp
Veh1_AAACCTGAGATCCTGT       VEH1        6              VEH
Veh2_AAACCTGCAGTACACT       VEH2        9              VEH
Exp1_AAACCTGGTCCCTTGT       EXP1        12             EXP
Exp2_AAACCTGTCAAAGACA       EXP2        7              EXP

I have tried using 4 seperate if statements for each condition:

if (object$cond == "VEH1") {
  object$exp <- "VEH"
}

and I have tried using an ifelse statement like this:

if (object$cond == "VEH1") { 
  object$exp <- "VEH"
} else if (object$cond == "VEH2") {
  object$exp <- "VEH"
} else if  (object$cond == "EXP1") {
  object$exp <- "EXP"
} else {object$cond == "EXP2"
  object$exp <- "EXP"
}

both of these labeled every cell as VEH, and I got the warning

Warning message:
In if (object$cond == "VEH") { :
  the condition has length > 1 and only the first element will be used
> head(x = object[[]])

lastly I tried using a for loop like this, where 48,000 is the number of cells I have

for (i in 1:48000)
{
  if (object$cond[[i]] == "VEH1") {
    object$exp <- "VEH"
  }
}

This didn't work etihe.

Does anyone have a recommendation? I fell like this simple task shouldn't be that difficult but I can't figure out how to get it

Thanks in advance!

seurat scrna • 858 views
ADD COMMENTlink modified 14 months ago by _r_am32k • written 14 months ago by cook.67560
0
gravatar for _r_am
14 months ago by
_r_am32k
Baylor College of Medicine, Houston, TX
_r_am32k wrote:

It looks like you're trying to add a column to a data.frame. You can simply use something like:

df$new_col <- function_to_manipulate(df$existing_col)

where function_to_manipulate() is any function that gets new values from old values (which in your case could be a gsub or a toupper(substr())).

You should be able to use the clues above to figure out exact code.

ADD COMMENTlink modified 14 months ago • written 14 months ago by _r_am32k

Thanks for the hint. I tried:

object$exp <- AddMetaData(object, object$cond == "VEH1", col.name = "VEH")

and got returned an error.

But I found the solution here!!

ADD REPLYlink written 14 months ago by cook.67560
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1965 users visited in the last hour
_