Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add_seurat_clustering fails when clusters are not integers #15

Closed
KatjaRM opened this issue May 24, 2020 · 9 comments
Closed

add_seurat_clustering fails when clusters are not integers #15

KatjaRM opened this issue May 24, 2020 · 9 comments

Comments

@KatjaRM
Copy link

KatjaRM commented May 24, 2020

Hi Team,

I am trying to add my Seurat clustering from a v3 object to a loom file and get the following error with
add_seurat_clustering(loom = loom, seurat = seurat.object, default.clustering.overwrite = T)`

Error in add_seurat_clustering(loom = loom, seurat = seurat.object, default.clustering.overwrite = T) : The given seurat.clustering.prefix is required. E.g.: RNA_snn_res.

What information do I add for seurat.clustering.prefix = ?
The clustering is not simply a single Seurat clustering round with one resolution factor, but I have subclustering and partly clustering by marker expression, so I am really confused as to what I have to provide.

I would be thankful for any help!

Best,

Katja

@dweemx
Copy link
Contributor

dweemx commented May 25, 2020

Hi @KatjaRM,
Is/are your clustering(s) part of a Seurat object ?
If it is the case could you share the results of

colnames(x = seurat@metadata)

?

@KatjaRM
Copy link
Author

KatjaRM commented May 25, 2020

Hi!

Thanks for the answer! Yes:
colnames(seurat.object@meta.data)

[1] "orig.ident" "nCount_RNA" "nFeature_RNA"
[4] "dataset" "integrated_snn_res.0.1" "seurat_clusters"
[7] "CellfindR"

The clustering I would like to add is stored in orig.ident. I could either add it from there or from seurat.object@active.ident.

@dweemx
Copy link
Contributor

dweemx commented May 25, 2020

I see, you should be able to add the clustering using this code:

add_clustering(loom = loom,
   group = "[a-group-for-your-clustering, e.g.: Seurat]",
   name = "[a-name-for-your-clustering]",
   clusters = seurat@active.ident
)

@KatjaRM
Copy link
Author

KatjaRM commented May 25, 2020

Hm, now I get the error message

The following from values were not present in x: NA
[1] "Clusterings already exists..."
[1] 1
Warning message:
In sort(as.integer(levels(clusters)), decreasing = F) :
NAs introduced by coercion

Even though I set overwrite.default = TRUE

@dweemx
Copy link
Contributor

dweemx commented May 26, 2020

Thanks for the report bug. I might have a closer lookup to it today.
I'll will let you know once I fixed the bug

@dweemx
Copy link
Contributor

dweemx commented May 26, 2020

Hey @KatjaRM,
I cannot reproduce your error unfortunately. The following snippet works for me:

loom <- build_loom(
  file.name = "tests/Seurat_v3/Seurat.loom",
  title = "Seurat",
  dgem = seurat@assays$RNA@counts,
  ...
)
add_clustering(
  loom = loom,
  group = "Seurat",
  name = "Seurat Active Ident",
  clusters = seurat@active.ident
)

However, here are some things you could check,

  • I'm using SCopeLoomR version 0.9.0. Could you double-check that you're using the latest version:
packageVersion(pkg = "SCopeLoomR")
  • Check if the structure is similar to your R object seurat@active.ident
> seurat@active.ident[1:10]
AAACCTGAGGTGGGTT-1 AAACGGGCAAGTAGTA-1 AAACGGGGTGTCAATC-1 AAAGCAACAATCGAAA-1 AAATGCCAGCCAACAG-1 AAATGCCTCACTCTTA-1 AACCGCGAGATCGATA-1 AACCGCGAGGTTCCTA-1 AACCGCGCAGCGATCC-1 AACTCCCCATATACGC-1 
                13                  3                  3                  3                 18                  3                  3                 19                 19                  8 
Levels: 0 1 10 11 12 13 14 15 16 17 18 19 2 20 21 22 23 24 25 26 3 4 5 6 7 8 9

(Normally this should be the case)

  • Check that you don't have any NA values in seurat@active.ident

@KatjaRM
Copy link
Author

KatjaRM commented May 26, 2020

Hi Max,

Thank you so much for taking all the time and looking into it. I checked all the points you mentioned and everything was fine.

I have played around with it a little more and what fixed the issue in the end renaming the clusters to just numbers. Weird, but I'll take it.

Thank you again for your time!

Katja

@KatjaRM KatjaRM closed this as completed May 26, 2020
@dweemx
Copy link
Contributor

dweemx commented May 26, 2020

Mmhh, could you post the result of:

seurat@active.ident[1:10]

I'm still interested to understand why it was not working if it were not numbers

@dweemx dweemx reopened this May 26, 2020
@KatjaRM
Copy link
Author

KatjaRM commented May 26, 2020

For my initial cluster names:

seurat2@active.ident[1:10]
dataset2_AAAGTAGGTACGACCC dataset2_AACTGGTCAACACCCG
4.1 older germ cell 4.0 undifferentiated germ cell
dataset2_AAGGAGCAGATATACG dataset2_ACATCAGTCTACCAGA
4.0 undifferentiated germ cell 4.1 older germ cell
dataset2_ACCAGTAGTGGTCTCG dataset2_ACGATGTCATGTAGTC
4.0 undifferentiated germ cell 4.0 undifferentiated germ cell
dataset2_ACGCAGCGTTCCACGG dataset2_ACTGTCCGTATAAACG
4.0 undifferentiated germ cell 4.0 undifferentiated germ cell
dataset2_ACTTTCAGTGTGACGA dataset2_AGCATACGTCGCCATG
4.1 older germ cell 4.1 older germ cell
25 Levels: 5 muscle cell ... 0 MB 1-5

After renaming the clusters:

seurat_2@active.ident[1:10]
dataset2_AAAGTAGGTACGACCC dataset2_AACTGGTCAACACCCG dataset2_AAGGAGCAGATATACG
25 24 24
dataset2_ACATCAGTCTACCAGA dataset2_ACCAGTAGTGGTCTCG dataset2_ACGATGTCATGTAGTC
25 24 24
dataset2_ACGCAGCGTTCCACGG dataset2_ACTGTCCGTATAAACG dataset2_ACTTTCAGTGTGACGA
24 24 25
dataset2_AGCATACGTCGCCATG
25
Levels: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 21 22 23 24 25 26

The only thing I changed is using SetIdent from Seurat to rename each cluster.

@dweemx dweemx changed the title Error in add_seurat_clustering add_seurat_clustering fails when clusters are not integers May 26, 2020
@dweemx dweemx closed this as completed in 780c765 May 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants