aertslab / SCopeLoomR

R package (compatible with SCope) to create generic .loom files and extend them with other data e.g.: SCENIC regulons, Seurat clusters and markers, ...
MIT License
38 stars 15 forks source link

Bug in conversion to loom v3 #17

Closed cbravo93 closed 4 years ago

cbravo93 commented 4 years ago

Hi!

In the convert_to_loom_v3_spec, these two lines have to switch order:

    loom$attr_delete(attr_name = global_attr_key)
    add_global_attr(loom = loom, key = global_attr_key, value = value)

Below the updated and functional version:

convert_to_loom_v3_spec <- function(loom) {
  if(is_loom_spec_version_3_or_greater(loom = loom)) {
    stop("The given loom is already in Loom version 3 specification.")
  }
  gmd<-get_global_meta_data(loom = loom)
  # Update loom spec version to 3
  print("Updating to Loom v3 specification...")
  if(loom$attr_exists(attr_name = GA_LOOM_SPEC_VERSION)) {
    remove_global_attr(loom = loom, GA_LOOM_SPEC_VERSION) 
  }
  # Create the global attrs group
  loom$create_group("attrs")
  add_global_loom_spec_version(loom, loom.spec.version = 3)
  for(global_attr_key in list.attributes(object = loom)) {
    print(paste0("Converting ", global_attr_key, " global attribute to Loom v3 specification..."))
    if(global_attr_key == "MetaData") {
      value <- rjson::toJSON(x = gmd)
    } else {
      value <- h5attr(x = loom, which = global_attr_key)
    }
    loom$attr_delete(attr_name = global_attr_key)
    add_global_attr(loom = loom, key = global_attr_key, value = value)
  }
  flush(loom = loom)
  return (loom)
  print("Done")
}
dweemx commented 4 years ago

Hi @cbravo93, Indeed this makes more sense I have fixed this bug in v0.9.2 Thanks for the bug report