Combining single cell datasets after pre-processing
Author(s) |
![]() |
Editor(s) |
![]() |
Tester(s) |
|
OverviewQuestions:
Objectives:
I have some AnnData files from different samples that I want to combine into a single file. How can I combine these and label them within the object?
Requirements:
Combine data matrices from different samples in the same experiment
Label the metadata for downstream processing
- Introduction to Galaxy Analyses
- slides Slides: An introduction to scRNA-seq data analysis
- tutorial Hands-on: Understanding Barcodes
- tutorial Hands-on: Generating a single cell matrix using Alevin
Time estimation: 1 hourSupporting Materials:
- Datasets
- Workflows
- galaxy-history-input Input Histories
- galaxy-history-answer Answer Histories
- FAQs
- video Recordings
- instances Available on these Galaxies
Published: Sep 8, 2022Last modification: Jun 14, 2024License: Tutorial Content is licensed under Creative Commons Attribution 4.0 International License. The GTN Framework is licensed under MITpurl PURL: https://gxy.io/GTN:T00246version Revision: 16
This tutorial will take you from the multiple AnnData outputs of the previous tutorial to a single, combined AnnData object, ready for all the fun downstream processing. We will also look at how to add in metadata (for instance, SEX or GENOTYPE) for analysis later on.
AgendaIn this tutorial, we will cover:
Get Data
The sample data is a subset of the reads in a mouse dataset of fetal growth restriction Bacon et al. 2018 (see the study in Single Cell Expression Atlas and the project submission). Each of the 7 samples (N701 –> N707) has been run through the workflow from the Alevin tutorial.
You can access the data for this tutorial in multiple ways:
-
Your own history - If you’re feeling confident that you successfully ran a workflow on all 7 samples from the previous tutorial, and that your resulting 7 AnnData objects look right (you can compare with the answer key history), then you can use those! To avoid a million-line history, I recommend dragging the resultant datasets into a fresh history
There 3 ways to copy datasets between histories
-
From the original history
- Click on the galaxy-gear icon which is on the top of the list of datasets in the history panel
- Click on Copy Datasets
-
Select the desired files
-
Give a relevant name to the “New history”
- Validate by ‘Copy History Items’
- Click on the new history name in the green box that have just appear to switch to this history
-
Using the galaxy-columns Show Histories Side-by-Side
- Click on the galaxy-dropdown dropdown arrow top right of the history panel (History options)
- Click on galaxy-columns Show Histories Side-by-Side
- If your target history is not present
- Click on ‘Select histories’
- Click on your target history
- Validate by ‘Change Selected’
- Drag the dataset to copy from its original history
- Drop it in the target history
-
From the target history
- Click on User in the top bar
- Click on Datasets
- Search for the dataset to copy
- Click on its name
- Click on Copy to current History
-
- Importing from a history
- You can import this history for usegalaxy.eu
- You can import this history for usegalaxy.org
- Open the link to the shared history
- Click on the Import this history button on the top left
- Enter a title for the new history
- Click on Copy History
- If you want to import the history to another Galaxy server, check how to do it below!
Transfer a Single Dataset
At the sender Galaxy server, set the history to a shared state, then directly capture the galaxy-link link for a dataset and paste the URL into the Upload tool at the receiver Galaxy server.
Transfer an Entire History
Have an account at two different Galaxy servers, and be logged into both.
At the sender Galaxy server
- Navigate to the history you want to transfer, and set the history to a shared state.
- Click into the History Options menu in the history panel.
- Select from the menu galaxy-history-archive Export History to File.
- Choose the option for How do you want to export this History? as to direct download.
- Click on Generate direct download.
- Allow the archive generation process to complete. *
- Copy the galaxy-link link for your new archive.
At the receiver Galaxy server
- Confirm that you are logged into your account.
- Click on Data in the top menu, and choose Histories to reach your Saved Histories.
- Click on Import history in the grey button on the top right.
- Paste in your link’s URL from step 7.
- Click on Import History.
- Allow the archive import process to complete. *
- The transfered history will be uncompressed and added to your Saved Histories.
* For steps 6 and 13: It is Ok to navigate away for other tasks during processing. If enabled, Galaxy will send you status notifications.
tip If the history to transfer is large, you may copy just your important datasets into a new history, and create the archive from that new smaller history. Clearing away deleted and purged datasets will make all histories smaller and faster to archive and transfer!
- Uploading from Zenodo (see below)
Hands-on: Data upload for 7 files
- Create a new history for this tutorial (if you’re not importing the history above)
Import the different AnnData files and the experimental design table from Zenodo.
https://zenodo.org/records/10852529/files/Experimental_Design.tabular.tabular https://zenodo.org/records/10852529/files/N701-400k-AnnData.h5ad https://zenodo.org/records/10852529/files/N702-400k-AnnData.h5ad https://zenodo.org/records/10852529/files/N703-400k-AnnData.h5ad https://zenodo.org/records/10852529/files/N704-400k-AnnData.h5ad https://zenodo.org/records/10852529/files/N705-400k-AnnData.h5ad https://zenodo.org/records/10852529/files/N706-400k-AnnData.h5ad https://zenodo.org/records/10852529/files/N707-400k-AnnData.h5ad
- Copy the link location
Click galaxy-upload Upload Data at the top of the tool panel
- Select galaxy-wf-edit Paste/Fetch Data
Paste the link(s) into the text field
Press Start
- Close the window
- Rename the datasets
Check that the AnnData files datatype is
h5ad
, otherwise you will need to change each file toh5ad
!
- Click on the galaxy-pencil pencil icon for the dataset to edit its attributes
- In the central panel, click galaxy-chart-select-data Datatypes tab on the top
- In the galaxy-chart-select-data Assign Datatype, select
datatypes
from “New type” dropdown
- Tip: you can start typing the datatype into the field to filter the dropdown menu
- Click the Save button
galaxy-eye Inspect the param-file Experimental Design
text file. This shows you how each N70X
corresponds to a sample, and whether that sample was from a male or female. This will be important metadata to add to our sample, which we will add very similarly to how you added the gene_name
and mito
metadata previously!
Important tips for easier analysis
Tools are frequently updated to new versions. Your Galaxy may have multiple versions of the same tool available. By default, you will be shown the latest version of the tool. This may NOT be the same tool used in the tutorial you are accessing. Furthermore, if you use a newer tool in one step, and try using an older tool in the next step… this may fail! To ensure you use the same tool versions of a given tutorial, use the Tutorial mode feature.
- Open your Galaxy server
- Click on the curriculum icon on the top menu, this will open the GTN inside Galaxy.
- Navigate to your tutorial
- Tool names in tutorials will be blue buttons that open the correct tool for you
- Note: this does not work for all tutorials (yet)
- You can click anywhere in the grey-ed out area outside of the tutorial box to return back to the Galaxy analytical interface
Warning: Not all browsers work!
- We’ve had some issues with Tutorial mode on Safari for Mac users.
- Try a different browser if you aren’t seeing the button.
Did you know we have a unique Single Cell Omics Lab with all our single cell tools highlighted to make it easier to use on Galaxy? We recommend this site for all your single cell analysis needs, particularly for newer users.
The Single Cell Omics Lab currently uses the main European Galaxy infrastructure and power, it’s just organised better for users of particular analyses…like single cell!
Try it out! All your histories/workflows/logins from the general European Galaxy server will be there!
- subdomain Single Cell Omics Lab
When something goes wrong in Galaxy, there are a number of things you can do to find out what it was. Error messages can help you figure out whether it was a problem with one of the settings of the tool, or with the input data, or maybe there is a bug in the tool itself and the problem should be reported. Below are the steps you can follow to troubleshoot your Galaxy errors.
- Expand the red history dataset by clicking on it.
- Sometimes you can already see an error message here
View the error message by clicking on the bug icon galaxy-bug
- Check the logs. Output (stdout) and error logs (stderr) of the tool are available:
- Expand the history item
- Click on the details icon
- Scroll down to the Job Information section to view the 2 logs:
- Tool Standard Output
- Tool Standard Error
- For more information about specific tool errors, please see the Troubleshooting section
- Submit a bug report! If you are still unsure what the problem is.
- Click on the bug icon galaxy-bug
- Write down any information you think might help solve the problem
- See this FAQ on how to write good bug reports
- Click galaxy-bug Report button
- Ask for help!
- Where?
- In the User community chatspace in Slack in our #single-cell-users channel
- In the GTN Matrix Channel
- In the Galaxy Matrix Channel
- Browse the Galaxy Help Forum to see if others have encountered the same problem before (or post your question).
- When asking for help, it is useful to share a link to your history
Concatenating objects
Hands-on: Concatenating AnnData objects
- Manipulate AnnData ( Galaxy version 0.10.3+galaxy0) with the following parameters:
- param-file “Annotated data matrix”:
N701-400k
- “Function to manipulate the object”:
Concatenate along the observations axis
- param-file “Annotated data matrix to add”:
Select all the other matrix files from bottom to top, N707 to N702
Warning: N707 to N702!You are adding files to N701, so do not add N701 to itself!
- “Join method”:
Intersection of variables
- “Key to add the batch annotation to obs”:
batch
- “Separator to join the existing index names with the batch category”:
-
- Rename galaxy-pencil output
Combined Object
Now let’s look at what we’ve done! Unfortunately, AnnData objects are quite complicated, so the galaxy-eye won’t help us too much here. Instead, we’re going to use a tool to look into our object from now on.
Hands-on: Inspecting AnnData Objects
- Inspect AnnData ( Galaxy version 0.10.3+galaxy0) with the following parameters:
- param-file “Annotated data matrix”:
Combined object
- “What to inspect?”:
General information about the object
- Inspect AnnData ( Galaxy version 0.7.5+galaxy1) with the following parameters:
- param-file “Annotated data matrix”:
Combined object
- “What to inspect?”:
Key-indexed observations annotation (obs)
- Inspect AnnData ( Galaxy version 0.7.5+galaxy1) with the following parameters:
- param-file “Annotated data matrix”:
Combined object
- “What to inspect?”:
Key-indexed annotation of variables/features (var)
Now have a look at the three tool Inspect AnnData outputs.
Question
- How many cells do you have now?
- Where is
batch
information stored?
- If you look at the General information tool output, you can see there are now
331 cells
, as the matrix is now 331 cells x 35734 genes. You can see this as well in the obs tool (cells) and var tool (genes) file sizes.- Under Key-indexed observations annotation (obs). Different versions of the Manipulate tool might put the
batch
columns in different locations. The tool version in this course putsbatch
in the8th
column. Batch refers to the order in which the matrices were added. The files are added from the bottom of the history upwards, so be careful how you set up your histories when running this (i.e. if your first dataset is N703 and the second is N701, thebatch
will call N7030
and N7011
!)
Adding batch metadata
I set up the example history with the earliest indices at the bottom.
![The files are numbered such that dataset #1 is N701, dataset #2 is N702, etc., up through #7 as N707. This puts N707 at the top and N701 at the bottom in the Galaxy history.](../../images/scrna-casestudy/wab-history-files-ascending.png)
Therefore, when it is all concatenated together, the batch
appears as follows:
Index | Batch | Genotype | Sex |
---|---|---|---|
N701 | 0 | wildtype | male |
N702 | 1 | knockout | male |
N703 | 2 | knockout | female |
N704 | 3 | wildtype | male |
N705 | 4 | wildtype | male |
N706 | 5 | wildtype | male |
N707 | 6 | knockout | male |
If you used Zenodo to import files, they may not have imported in order (i.e. N701 to N707, ascending). In that case, you will need to tweak the parameters of the next tools appropriately to label your batches correctly!
The two critical pieces of metadata in this experiment are sex and genotype. I will later want to color my cell plots by these parameters, so I want to add them in now!
Hands-on: Labelling sex
- Replace Text in a specific column ( Galaxy version 9.3+galaxy0) with the following parameters:
- param-file “File to process”: output of Inspect AnnData: Key-indexed observations annotation (obs) tool)
“1. Replacement”
- “in column”:
Column: 8
- or whichever columnbatch
is in- “Find pattern”:
0|1|3|4|5|6
- “Replace with”:
male
- + Insert Replacement
“2. Replacement”
- “in column”:
Column: 8
- “Find pattern”:
2
- “Replace with”:
female
- + Insert Replacement
“3. Replacement”
- “in column”:
Column: 8
- “Find pattern”:
batch
- “Replace with”:
sex
Run this tool - we will use the output in Step 2.
From the output of Step 1 we want only the single column containing the sex information - we will ultimately add this into the cell annotation in the AnnData object.
- Cut columns from a table with the following parameters:
- “Cut columns”:
c8
- “Delimited by”:
Tab
- param-file “From”: output of Replace text tool
- Rename galaxy-pencil output
Sex metadata
That was so fun, let’s do it all again but for genotype!
Hands-on: Labelling genotype
- Replace Text in a specific column ( Galaxy version 9.3+galaxy0) with the following parameters:
- param-file “File to process”: output of Inspect AnnData: Key-indexed observations annotation (obs) tool
“1. Replacement”
- “in column”:
Column: 8
- “Find pattern”:
0|3|4|5
- “Replace with”:
wildtype
- + Insert Replacement
“2. Replacement”
- “in column”:
Column: 8
- “Find pattern”:
1|2|6
- “Replace with”:
knockout
- + Insert Replacement
“3. Replacement”
- “in column”:
Column: 8
- “Find pattern”:
batch
- “Replace with”:
genotype
Now we want only the column containing the genotype information - we will ultimately add this into the cell annotation in the AnnData object.
- Cut columns from a table with the following parameters:
- “Cut columns”:
c8
- “Delimited by”:
Tab
- param-file “From”: output of Replace text tool
- Rename galaxy-pencil output
Genotype metadata
You might want to do this with all sorts of different metadata - which labs handled the samples, which days they were run, etc. Once you’ve added all your metadata columns, we can add them together before plugging them into the AnnData object itself.
Hands-on: Combining metadata columns
- Paste two files side by side with the following parameters:
- param-file “Paste”:
Genotype metadata
- param-file “and”:
Sex metadata
- “Delimit by”:
Tab
- Rename galaxy-pencil output
Cell Metadata
Let’s add it to the AnnData object!
Hands-on: Adding metadata to AnnData object
- Manipulate AnnData ( Galaxy version 0.10.3+galaxy0) with the following parameters:
- param-file “Annotated data matrix”:
Combined object
- “Function to manipulate the object”:
Add new annotation(s) for observations or variables
- “What to annotate?”:
Observations (obs)
`- param-file “Table with new annotations”:
Cell Metadata
Woohoo! We’re there! You can run an Inspect AnnData ( Galaxy version 0.10.3+galaxy0) to check now, but I want to clean up this AnnData object just a bit more first. It would be a lot nicer if ‘batch’ meant something, rather than ‘the order in which the Manipulate AnnData tool added my datasets’.
Hands-on: Labelling batches
- Manipulate AnnData ( Galaxy version 0.10.3+galaxy0) with the following parameters:
- param-file “Annotated data matrix”: output of Manipulate AnnData - Add new annotations tool
- “Function to manipulate the object”:
Rename categories of annotation
- “Key for observations or variables annotation”:
batch
- “Comma-separated list of new categories”:
N701,N702,N703,N704,N705,N706,N707
- Rename galaxy-pencil output
Batched Object
Huzzah! We are JUST about there. However, while we’ve been focussing on our cell metadata (sample, batch, genotype, etc.) to relabel the ‘observations’ in our object…
Mitochondrial reads
Do you remember when we mentioned mitochondria early on in this tutorial? And how often in single cell samples, mitochondrial RNA is often an indicator of stress during dissociation? We should probably do something with our column of true/false in the gene annotation that tells us information about the cells. You will need to do this whether you have combined FASTQ files or are analysing just one.
Hands-on: Calculating mitochondrial RNA in cells
- AnnData Operations ( Galaxy version 1.9.3+galaxy0) with the following parameters:
- param-file “Input object in hdf5 AnnData format”:
Batched Object
- “Format of output object”:
AnnData format
- “Gene symbols field in AnnData”:
NA.
- “Flag genes that start with these names”:
Insert Flag genes that start with these names
- “Starts with”:
True
- “Var name”:
mito
- Rename galaxy-pencil output
Annotated Object
congratulationsWell done! I strongly suggest have a play with the Inspect AnnData tool on your final Pre-processed object
to see the wealth of information that has been added. You are now ready to move along to further filtering! There is a cheat that may save you time in the future though…
Pulling single cell data from public resources
If you happen to be interested in analysing publicly available data, particularly from the Single Cell Expression Atlas, you may be interested in the following tool Moreno et al. 2020 which combines all these steps into one! For this tutorial, the dataset can be seen at the EBI with experiment id of E-MTAB-6945
. It’s important to note that this matrix is processed somewhat through the SCXA pipeline, which is quite similar to this tutorial, and it contains any and all metadata provided by their pipeline as well as the authors (for instance, more cell or gene annotations).
If you wish, you can have a closer look how to pull this dataset from the Single Cell Expression Atlas by following another tutorial: Importing files from public atlases.
Conclusion
![Combining data files.](../../images/scrna-casestudy/wab-combining_datasets_alevin.png)
You’ve reached the end of this session!
You may be interested in seeing an example history and workflow. Note that the workflow might require changing of the column
containing the batch metadata depending on how you are running it and checking the order of the combined datasets. The final object containing the total the reads can be found in this Galaxy History on UseGalaxy EU.
feedback To discuss with like-minded scientists, join our Galaxy Training Network chatspace in Slack and discuss with fellow users of Galaxy single cell analysis tools on #single-cell-users
We also post new tutorials / workflows there from time to time, as well as any other news.
point-right If you’d like to contribute ideas, requests or feedback as part of the wider community building single-cell and spatial resources within Galaxy, you can also join our Single cell & sPatial Omics Community of Practice.
tool You can request tools here on our Single Cell and Spatial Omics Community Tool Request Spreadsheet