# Creating the single-cell RNA-seq reference dataset for deconvolution

 Author(s) Wendi BaconMehmet Tekman Tester(s) Marisa Loach
Overview
Questions:
• Where can I find good quality scRNA-seq reference datasets?

• How can I reformat and manipulate these downloads to create the right format for MuSiC?

Objectives:
• You will retrieve raw data from the EMBL-EBI Single cell expression atlas.

• You will manipulate the metadata and matrix files.

• You will combine the metadata and matrix files into an ESet object for MuSiC deconvolution.

• You will create multiple ESet objects - both combined and separated out by disease phenotype for your single cell reference.

Requirements:
Time estimation: 1 hour
Supporting Materials:
Last modification: Feb 3, 2023

# Introduction

After completing the MuSiC Wang et al. 2019 deconvolution tutorial, you are hopefully excited to apply this analysis to data of your choice. Annoyingly, getting data in the right format is often what prevents us from being able to successfully apply analyses. This tutorial is all about reformatting a raw scRNA-seq dataset pulled from a public resource (the EMBL-EBI single cell expression atlas Moreno et al. 2021. Let’s get started!

Agenda

In this tutorial, we will cover:

First, we will tackle the metadata. We are roughly following the same concept as in the previous bulk deconvolution tutorial, by comparing human pancreas data across a disease variable (type II diabetes vs healthy), but using public datasets to do it.

## Find the data

We explored the single cell expression atlas, browsing experiments in order to find a pancreas dataset (Segerstolpe et al. 2016). You can explore this dataset using their browser. These cells come from 6 healthy individuals and 4 individuals with Type II diabetes, so we will create reference Expression Set objects for the total as well as separating out by phenotype, as you may have reason to do this in your analysis (or you may not!).

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.

• Click on the curriculum icon on the top menu, this will open the GTN inside Galaxy.
• 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.

Galaxy has a specific tool for ingesting data from the Single cell expression atlas, so there are no uploads for this tutorial.

Hands-on: Data retrieval
1. EBI SCXA Data Retrieval Tool: toolshed.g2.bx.psu.edu/repos/ebi-gxa/retrieve_scxa/retrieve_scxa/v0.0.2+galaxy2 with the following parameters:
• “SC-Atlas experiment accession”: E-MTAB-5061

Data management is going to be key in this analysis, so trust me now to start adding tags.

1. Add to the EBI SCXA Data Retrieval on E-MTAB-5061 exp_design.tsv file the following tags: #ebi #metadata #singlecell

• Click on the dataset
• Click on galaxy-tags Add Tags
• Add a tag starting with #

Tags starting with # will be automatically propagated to the outputs of tools using this dataset.

• Check that the tag is appearing below the dataset name

This tool will retrieve four files: a barcodes list, a genes list, an experimental design file, and a matrix market format (where columns refer to genes, cells, and quantities). We (mostly) only need the experimental design file, but keep in mind this will have data on all the cells reported by the authors.

Question
1. How many cells are in the sample?
2. How many cells were submitted by the authors?
1. If you select the param-file barcodes.tsv file, you’ll find that it contains 2914 lines - this corresponds to the 2914 cells, because each cell is given a barcode.
2. The nature of public repositories is that they ingest data from many places, which means they usually apply a uniform analysis to samples. This rarely means they yield the same cell numbers as the original authors. If you check the param-file exp_design.tsv file, which refers to the data submitted by the authors, you’ll find it contains 3514 lines - referring to 3514 cells submitted by authors. It’s important to know that (currently) these files differ.

## Prepare the experimental design file

Let’s get rid of a bunch of repetitive columns in the metadata we don’t need. You can find out what each column is by inspecting the dataset galaxy-eye in the history window.

1. Cut Tool: Cut1 with the following parameters:
• “Cut columns”: c1,c4,c6,c8,c10,c14,c20,c24,c26,c30,c32,c34
• param-file “From”: design_tsv (output of EBI SCXA Data Retrieval tool)

You can inspect the dataset galaxy-eye to see that it’s full of annoying “” everywhere, and overly long descriptions of each columns.

Now, there might be a better way to do this in Galaxy (or you might consider downloading the file locally and changing it in a spreadsheet application or something), but this is what will work to reformat all that annoying text.

1. Regex Find And Replace Tool: toolshed.g2.bx.psu.edu/repos/galaxyp/regex_find_replace/regex1/1.0.2 with the following parameters:
• param-file “Select lines from”: out_file1 (output of Cut tool)
• In “Check”:
• param-repeat “Insert Check”
• “Find Regex”: "Sample Characteristic$individual$"
• “Replacement”: Individual
• param-repeat “Insert Check”
• “Find Regex”: "Sample Characteristic$sex$"
• “Replacement”: Sex
• param-repeat “Insert Check”
• “Find Regex”: "Sample Characteristic$age$"
• “Replacement”: Age
• param-repeat “Insert Check”
• “Find Regex”: "Sample Characteristic$body mass index$"
• “Replacement”: BMI
• param-repeat “Insert Check”
• “Find Regex”: kilogram per square meter
• param-repeat “Insert Check”
• “Find Regex”: HbA1c
• param-repeat “Insert Check”
• “Find Regex”: "Sample Characteristic$clinical information$"
• “Replacement”: HbA1c
• param-repeat “Insert Check”
• “Find Regex”: %
• param-repeat “Insert Check”
• “Find Regex”: "Sample Characteristic$disease$"
• “Replacement”: Disease
• param-repeat “Insert Check”
• “Find Regex”: "Sample Characteristic$single cell quality$"
• “Replacement”: Single cell quality
• param-repeat “Insert Check”
• “Find Regex”: "Sample Characteristic$submitted single cell quality$"
• “Replacement”: "Submitted single cell quality"
• param-repeat “Insert Check”
• “Find Regex”: "Factor Value$inferred cell type - ontology labels$"
• “Replacement”: Inferred cell type - ontology label
• param-repeat “Insert Check”
• “Find Regex”: "Factor Value$inferred cell type - authors labels$"
• “Replacement”: Inferred cell type - author labels
• param-repeat “Insert Check”
• “Find Regex”: ""
• “Replacement”:
• param-repeat “Insert Check”
• “Find Regex”: "
• “Replacement”:
Comment

What’s with the \ everywhere? That’s because the [] symbols usually call the code to do something, rather than just read it as a normal character. the \ prevents this.

2. Change the datatype to tabular.

• Click on the galaxy-pencil pencil icon for the dataset to edit its attributes
• In the central panel, click on the galaxy-chart-select-data Datatypes tab on the top
• Select tabular
• tip: you can start typing the datatype into the field to filter the dropdown menu
• Click the Save button

Great, this file is now ready to go! But, it contains all those extra cells that didn’t pass filtration with the EBI pipeline and therefore won’t exist in the matrix. We need to remove them for future steps to work. We can use our barcodes list to remove the extra cells.

## Prepare the barcodes file

• “text to add”: Cell
• param-file “input file”: barcode_tsv (output of EBI SCXA Data Retrieval tool)
2. Change the datatype to tabular.

• Click on the galaxy-pencil pencil icon for the dataset to edit its attributes
• In the central panel, click on the galaxy-chart-select-data Datatypes tab on the top
• Select tabular
• tip: you can start typing the datatype into the field to filter the dropdown menu
• Click the Save button
Comment

This is an annoying step we have to do to get the right format, otherwise future steps won’t work.

## Use the barcodes list to filter out cells in the experimental design file

Hands-on: Joining datasets
1. Join two Datasets Tool: join1 with the following parameters:
• param-file “Join”: outfile (output of Add line to file tool)
• “using column”: c1
• param-file “with”: out_file1 (output of Regex Find And Replace tool)
• “and column”: c1
• “Fill empty columns”: No
• “Keep the header lines”: Yes
Comment

Make sure that you join the files in the same order as above - put the output of Add line to file in first - otherwise your columns will be in a different order for the next step. Everything will still work, but you would need to change the number of the column you remove using Advanced Cut.

Question
1. How many cells are now in your table?
1. If you select the output dataset in your history, you will find 2915 lines, corresponding to 2914 cells and a header. Success!
2. Not quite - notice how you have two identical columns Cell and Assay? Let’s get rid of one.
Hands-on: Remove duplicate columns
1. Advanced Cut Tool: toolshed.g2.bx.psu.edu/repos/bgruening/text_processing/tp_cut_tool/1.1.0 with the following parameters:
• param-file “File to cut”: out_file1 (output of Join two Datasets tool)
• “Operation”: Discard
• “Cut by”: fields
• “List of Fields”: c1
Comment

Advanced cut works slightly differently in a workflow versus running the tool independently. Independently, there is a list and you can click through the list to note your columns, while in a workflow it appears as a text option and you put each column on a different line. The point is, each number above represents a column, so remove them!

Fantastic! You’ve completed part 1 - making the single cell metadata file. It should now look like this:

You can use the workflow for this portion of the tutorial, and access an example history.

# Manipulate the expression matrix

Currently, the matrix data is in a 3-column format common in 10x outputs, where you need the barcodes and the genes files to interpret the matrix. What you actually need is an expression matrix with cells on one axis and genes on another. While we aren’t running a Scanpy analysis, we can still use our Scanpy tools to get this format.

## Reformat the matrix

• param-file “Expression matrix in sparse matrix format (.mtx)”: matrix_mtx (output of EBI SCXA Data Retrieval tool)
• param-file “Gene table”: genes_tsv (output of EBI SCXA Data Retrieval tool)
• param-file “Barcode/cell table”: barcode_tsv (output of EBI SCXA Data Retrieval tool)
• “Format of output object”: AnnData format (h5 for older versions)
2. Change the datatype to h5ad

• Click on the galaxy-pencil pencil icon for the dataset to edit its attributes
• In the central panel, click on the galaxy-chart-select-data Datatypes tab on the top
• Select h5ad
• tip: you can start typing the datatype into the field to filter the dropdown menu
• Click the Save button

Now your precious matrix is stored in the 10x AnnData object. Let’s retrieve it!

Hands-on: Inspect the matrix
1. Inspect AnnData Tool: toolshed.g2.bx.psu.edu/repos/iuc/anndata_inspect/anndata_inspect/0.7.5+galaxy1 with the following parameters:
• param-file “Annotated data matrix”: output_h5 (output of Scanpy Read10x tool)
• “What to inspect?”: The full data matrix
Question
1. Which are currently the rows in your matrix, cells or genes?
1. You may remember from earlier that the sample should have 2914 cells in it. If you inspect the dataset in your history, you will find that it contains 2915 lines (1 for the header), which means that rows correspond to cells. Unfortunately… that’s not what you need.
Hands-on: Transpose the matrix
1. Transpose Tool: toolshed.g2.bx.psu.edu/repos/iuc/datamash_transpose/datamash_transpose/1.1.0+galaxy2 with the following parameters:
• param-file “Input tabular dataset”: X (output of Inspect AnnData tool)
Question
1. How many genes are in your sample?
1. You should have 30,416 lines in it, meaning your sample has 30,415 genes.

## Collapse EnsemblIDs

Ok, real talk here. Technically, the best way of analysing anything is by using the EnsemblIDs for any given RNA transcript, because they are more specific than gene names and also cover more of the transcriptome than our gene names… But… As biologists, it’s very difficult to interpret ENSIDs. And it’s an awful shame to get to the end of the MuSiC deconvolution and have all our plots show sad ENS IDs. So, courtesy of the excellent @mtekman, we steal his workflow to collapse the ENS IDs into gene names.

Hands-on: Convert from Ensembl to GeneSymbol using workflow
1. Import this workflow.

• Click on Workflow on the top menu bar of Galaxy. You will see a list of all your workflows.
• Click on the upload icon galaxy-upload at the top-right of the screen
• Option 1: Paste the URL of the workflow into the box labelled “Archived Workflow URL”
• Option 2: Upload the workflow file in the box labelled “Archived Workflow File”
• Click the Import workflow button
2. Run the workflow on your sample with the following parameters:

• “Organism”: Human
• param-file “Expression Matrix (Gene Rows)”: output_h5 (output of Transpose tool)
• Click on Workflow on the top menu bar of Galaxy. You will see a list of all your workflows.
• Click on the workflow-run (Run workflow) button next to your workflow
• Configure the workflow as needed
• Click the Run Workflow button at the top-right of the screen
• You may have to refresh your history to see the queued jobs

The output will likely be called Text transformation and will look like this:

# Construct Expression Set Objects

We’re nearly there! We have three more tasks to do: first, we need to create the expression set object with all the phenotypes combined. Then, we also want to create two separate objects - one for healthy and one for diseased as references.

Hands-on: Creating the combined object
1. Construct Expression Set Object Tool: toolshed.g2.bx.psu.edu/repos/bgruening/music_construct_eset/music_construct_eset/0.1.1+galaxy4 with the following parameters:
• param-file “Assay Data”: out_file #matrix (output of Text transformation tool)
• param-file “Phenotype Data”: output (output of Advanced Cut tool)
2. Remove the #metadata #matrix tags from the output RData ESet Object

3. Add the tag #combined to the output RData ESet Object
Question
1. How many genes are in your sample now?
1. If you select the galaxy-eye of the output General Info dataset in the history, you will find it contains 21671 features and 2914 samples, or rather, 21671 genes and 2914 cells. That’s a huge reduction in genes thanks to the ENS ID collapsing!
Hands-on: Creating the disease-only object
1. Manipulate Expression Set Object Tool: toolshed.g2.bx.psu.edu/repos/bgruening/music_manipulate_eset/music_manipulate_eset/0.1.1+galaxy4 with the following parameters:
• param-file “Expression Set Dataset”: out_rds (output of Construct Expression Set Object tool)
• “Concatenate other Expression Set objects?”: No
• “Subset the dataset?”: Yes
• “By”: Filter Samples and Genes by Phenotype Values
• In “Filter Samples by Condition”:
• param-repeat “Insert Filter Samples by Condition”
• “Name of phenotype column”: Disease
• “List of values in this column to filter for, comma-delimited”: type II diabetes mellitus
2. Remove the #combined tag from the output RData ESet Object

3. Add the tag #T2D to the output RData ESet Object

You can either re-run this tool or set it up again to create the healthy-only object.

Hands-on: Creating the healthy-only object
1. Manipulate Expression Set Object Tool: toolshed.g2.bx.psu.edu/repos/bgruening/music_manipulate_eset/music_manipulate_eset/0.1.1+galaxy4 with the following parameters:
• param-file “Expression Set Dataset”: out_rds (output of Construct Expression Set Object tool)
• “Concatenate other Expression Set objects?”: No
• “Subset the dataset?”: Yes
• “By”: Filter Samples and Genes by Phenotype Values
• In “Filter Samples by Condition”:
• param-repeat “Insert Filter Samples by Condition”
• “Name of phenotype column”: Disease
• “List of values in this column to filter for, comma-delimited”: normal
2. Remove the #combined tag from the output RData ESet Object

3. Add the tag #healthy to the output RData ESet Object
Question
1. Why are you making a healthy-only and diseased-only reference objects?
1. We could imagine that the cells will express different transcript levels, but that the deconvolution tools will have to take some sort of average. Perhaps it might be more accurate to infer like from like, i.e. healthy from healthy? Or perhaps that is skewing the data through a more ‘supervised’ approach. We’re not quite sure, and it likely depends on the biology, so we’re covering all our bases by making sure you can do this every way. (We’ve tested it on our dataset in all the ways and got the same results, so it doesn’t make much of a difference as far as we can tell!)

# Conclusion

You have successfully performed, essentially, three workflows. You can find the workflows for generating the ESet object and the answer key history for this entire tutorial.

With these workflows, you’ve created three Expression Set objects, capable of running in the MuSiC Compare tutorial. Now you just need the bulk RNA-seq Expression Set objects!

This tutorial is part of the https://singlecell.usegalaxy.eu portal (Tekman et al. 2020).

Key points
• The EMBL-EBI Single-cell expression atlas contains high quality datasets.

• Metadata manipulation is key for generating the correctly formatted resource.

Have questions about this tutorial? Check out the tutorial FAQ page or the FAQ page for the Single Cell topic to see if your question is listed there. If not, please ask your question on the GTN Gitter Channel or the Galaxy Help Forum

# Useful literature

Further information, including links to documentation and original publications, regarding the tools, analysis techniques and the interpretation of results described in this tutorial can be found here.

# References

1. Segerstolpe, Å., A. Palasantza, P. Eliasson, E.-M. Andersson, A.-C. Andréasson et al., 2016 Single-cell transcriptome profiling of human pancreatic islets in health and type 2 diabetes. Cell metabolism 24: 593–607. 10.1016/j.cmet.2016.08.020
2. Wang, X., J. Park, K. Susztak, N. R. Zhang, and M. Li, 2019 Bulk tissue cell type deconvolution with multi-subject single-cell expression reference. Nature communications 10: 1–9. 10.1038/s41467-018-08023-x
3. Tekman, M., B. Batut, A. Ostrovsky, C. Antoniewski, D. Clements et al., 2020 A single-cell RNA-sequencing training and analysis suite using the Galaxy framework. GigaScience 9: giaa102. 10.1093/gigascience/giaa102 https://academic.oup.com/gigascience/article/9/10/giaa102/5931798
4. Moreno, P., S. Fexova, N. George, J. R. Manning, Z. Miao et al., 2021 Expression Atlas update: gene and protein expression in multiple species. Nucleic Acids Research 50: D129–D140. 10.1093/nar/gkab1030

# Feedback

Did you use this material as an instructor? Feel free to give us feedback on how it went.
Did you use this material as a learner or student? Click the form below to leave feedback.

# Citing this Tutorial

1. Wendi Bacon, Mehmet Tekman, Creating the single-cell RNA-seq reference dataset for deconvolution (Galaxy Training Materials). https://training.galaxyproject.org/training-material/topics/single-cell/tutorials/bulk-music-2-preparescref/tutorial.html Online; accessed TODAY
2. Batut et al., 2018 Community-Driven Data Analysis Training for Biology Cell Systems 10.1016/j.cels.2018.05.012



@misc{single-cell-bulk-music-2-preparescref,
author = "Wendi Bacon and Mehmet Tekman",
title = "Creating the single-cell RNA-seq reference dataset for deconvolution (Galaxy Training Materials)",
year = "",
month = "",
day = ""
url = "\url{https://training.galaxyproject.org/training-material/topics/single-cell/tutorials/bulk-music-2-preparescref/tutorial.html}",
note = "[Online; accessed TODAY]"
}
@article{Hiltemann_2023,
doi = {10.1371/journal.pcbi.1010752},
url = {https://doi.org/10.1371%2Fjournal.pcbi.1010752},
year = 2023,
month = {jan},
publisher = {Public Library of Science ({PLoS})},
volume = {19},
number = {1},
pages = {e1010752},
author = {Saskia Hiltemann and Helena Rasche and Simon Gladman and Hans-Rudolf Hotz and Delphine Larivi{\{e}}re and Daniel Blankenberg and Pratik D. Jagtap and Thomas Wollmann and Anthony Bretaudeau and Nadia Gou{\'{e}} and Timothy J. Griffin and Coline Royaux and Yvan Le Bras and Subina Mehta and Anna Syme and Frederik Coppens and Bert Droesbeke and Nicola Soranzo and Wendi Bacon and Fotis Psomopoulos and Crist{\'{o}}bal Gallardo-Alba and John Davis and Melanie Christine Föll and Matthias Fahrner and Maria A. Doyle and Beatriz Serrano-Solano and Anne Claire Fouilloux and Peter van Heusden and Wolfgang Maier and Dave Clements and Florian Heyl and Björn Grüning and B{\'{e}}r{\'{e}}nice Batut and},
editor = {Francis Ouellette},
title = {Galaxy Training: A powerful framework for teaching!},
journal = {PLoS Comput Biol} Computational Biology}
}

`

Congratulations on successfully completing this tutorial!