Machine learning models and tools can assist with a wide spectrum of supervised learning problems - predicting whether a pileup of reads really contains a variant, inferring ancestry from genetic variants, or predicting disease risk from expression data, to name a few.
The rest of this section walks through a tissue-classification question - given a gene expression profile, can you tell what tissue it came from? Put another way - given an unlabeled sample, can a model predict its tissue type?
This example uses real data from the GTEx project and tools available directly in the Cloud Workspace.
The GTEx Dataset
The Genotype-Tissue Expression (GTEx) project catalogs gene expression and its genetic regulation across a wide range of human tissues, drawn from donors after death. It's a natural dataset for this kind of question: many tissues, many samples, and known labels for every one. 948 donors, 54 tissues, 17382 samples.
Each donor contributed between 1 and 39 tissue samples (18 on average), and each tissue is represented by anywhere from 4 samples (Kidney - Medulla) to 900 (Skeletal Muscle) - Whole Blood and Skin (Exposed) are also especially well represented, at 840 and 797 samples respectively. That unevenness matters: a model has far more to learn from for common tissues than rare ones.
CWIC Training Data Mirror Training Data on GitHub
Reads to Expression
Before any modeling happens, raw sequencing reads have to become an expression matrix. That pipeline has three stages: sequencing, mapping & assembly, and quantification. Each stage has a well-known complication:
- Genes are spliced. A spliced aligner (such as STAR) is needed to map reads correctly and assemble isoforms.
- Read count isn't transcript abundance. A gene's read count depends on its length and on how deeply the whole sample was sequenced, so raw counts aren't comparable across genes or experiments. TPM (Transcripts Per Million) corrects for both effects and is the recommended metric for most analyses. It's what you'd see if you sequenced one million full-length transcripts and counted how many came from each gene.
- Expression is stochastic. Even technical replicates of the same sample won't match perfectly, so meaningful comparisons need enough biological replicates to separate real differences from noise.
In the Cloud Workspace, tools like STAR, Cufflinks, and DESeq2 are available directly from the tool panel to run each of these stages.
Exploring Expression Data
Before training any model, it helps to look at the data. A heatmap with hierarchical clustering (the heatmap2 tool) is a good first pass: each row is a sample, each column a gene, and clusters of similar color reveal which samples group together.
The trouble is that an expression matrix has as many dimensions as it has genes, from hundreds to thousands. A few dimensionality-reduction techniques make that space visible:
- PCA (Principal Components Analysis) — A linear rotation of the data onto the axes of greatest variation. It's generally the "safest" technique: distances between points keep their real meaning.
- t-SNE and UMAP — Non-linear techniques that can separate groups more sharply, but the trade-off is interpretability: distances are only meaningful locally, and neither the direction nor the distance between two distant points carries real information.
Note: Because UMAP tends to pull unusual points toward the nearest large cluster, it can visually exaggerate how distinct common groups are and can misrepresent genetic admixture, which is fundamentally additive in a way UMAP's geometry isn't. Geneticists have flagged this specifically for ancestry visualizations: a messier PCA or Admixture plot is sometimes a more honest picture of the data than a cleaner UMAP.
In the Cloud Workspace, both a PCA 3D Plot visualization and clustering tools are available directly from the Visualize menu on any dataset.
Classification Models
Once you can see structure in the data, the next step is a model that predicts a label - tissue type, and in this case for a sample it hasn't seen before. A few classic approaches, all available as Galaxy tools:
More complex approaches like artificial neural networks, convolutional networks (the architecture behind early breakthroughs like AlexNet), and transformer-based models (the architecture behind large language models) extend the same basic idea to images, sequences, and text, at the cost of needing far more data and compute.
Training and Evaluating a Model
Building a model always means doing two separate things with your data: estimating its parameters (training) and measuring how well it works (testing) on data the model never saw during training.
Reading a confusion matrix
Once a model makes predictions, a confusion matrix breaks down exactly where it succeeds and fails. For a "predict Blood vs. not-Blood" task:
- Precision — Of everything predicted Blood, how much really was? (False positives hurt precision.)
- Recall (sensitivity) — Of everything that really was Blood, how much did the model find? (False negatives hurt recall.)
- F1 score — A single number combining precision and recall.
- AUC-ROC — Plots true-positive rate against false-positive rate across every possible decision threshold, and measures overall separability as the area under that curve.
Overfitting: A model that fits its training data almost perfectly but performs poorly on new data has overfit. It memorizes quirks of the training set rather than learning the underlying pattern. The tell-tale sign is a generalization curve: if training loss keeps improving while validation loss gets worse, the model has stopped learning and started memorizing.
Hands-on: Predict Tissue Type
This walks through training a kNN classifier on GTEx expression data, entirely with tools already in the Cloud Workspace.
- Log into galaxy.cfdeworkspace.org and give your history a descriptive name.
- Upload the training set: use Upload → Paste/Fetch data and paste in the training data URL (gtex_tissue_train_200x100.tsv) from the CWIC training data mirror above.
- Explore it: view it with Tabulator, or build a Bar/Line/Scatter chart to see how a couple of genes vary across tissues.
- Look for structure: try Datamash for quick summary statistics, or a Heatmap visualization to see samples and genes cluster.
- Reduce dimensions: run a PCA 3D Plot to see visually which tissues separate out easily and which overlap.
- Train a classifier: run the Nearest Neighbor Classification tool, using all columns except SampleID and Tissue as training features, and the Tissue column as the label to predict.
- Load the held-out test set (gtex_tissue_test_labeled_100x100.tsv): real tissue labels the model hasn't seen.
- Split it with the cut tool: one output keeping just SampleID and Tissue (the truth), another keeping only the expression columns (the features to predict from).
- Predict: run Nearest Neighbor Classification again, this time in "Load a model and predict" mode, using your trained model on the held-out features.
- Check accuracy: cut out just the predictions, paste them alongside the true labels, and use Count occurrences of each record to tally how often predictions matched reality and which tissues got confused for one another.
After: Try a different model. Once you have a working kNN classifier, search the tool panel for an SVM or a Random Forest ("ensemble methods") tool and repeat steps 6–10. Different models can behave very differently on the same data - which one comes out ahead?
Next Steps & Homework
Classification is only one branch of the wider machine learning taxonomy: regression, clustering, and generative modeling all follow the same core discipline of training on labeled or unlabeled data and evaluating honestly on data the model hasn't seen.
A guided version of this whole walkthrough, with sample data and step-by-step instructions, is available as a Galaxy Training Network tutorial.