kevinblighe / scDataviz

scDataviz: single cell dataviz and downstream analyses
61 stars 17 forks source link

Adding Metadata #18

Closed elevendoky closed 3 years ago

elevendoky commented 3 years ago

Hello I am a little confused about how you add metadata. I am not sure what this line of code means.

metadata <- data.frame(
    sample = gsub('\\ [A-Za-z0-9]*\\.fcs$', '',
      gsub('scDataviz_data\\/FCS\\/\\/', '', filelist)),
    group = c(rep('Healthy', 7), rep('Disease', 11)),
    treatment = gsub('\\.fcs$', '',
      gsub('scDataviz_data\\/FCS\\/\\/[A-Z0-9]*\\ ', '', filelist)),
    row.names = filelist,
    stringsAsFactors = FALSE)
  metadata

Specifically I do not understand all the back and forward slashes can you please explain? Thanks!

kevinblighe commented 3 years ago

These lines of code construct the metadata, but manually. The backslashes are 'escaping' key characters in the gsub() commands. In this case, much of the metadata is simply constructed from the file listing, filelist.

I am not sure of your level of experience, but, to learn more, you could search for 'regex' and 'escaping characters'.

You likely already have a metadata file in your possession (?). To be valid, this should be a data-frame whose rownames match the input FCS file listing in length and order.

Kind regards, kevin