gene expression profile analysis -凯发k8网页登录
this example shows a number of ways to look for patterns in gene expression profiles.
exploring the data set
this example uses data from the microarray study of gene expression in yeast published by derisi, et al. 1997 [1]. the authors used dna microarrays to study temporal gene expression of almost all genes in saccharomyces cerevisiae during the metabolic shift from fermentation to respiration. expression levels were measured at seven time points during the diauxic shift. the full data set can be downloaded from the gene expression omnibus website, .
the mat-file yeastdata.mat
contains the expression values (log2 of ratio of ch2dn_mean
and ch1dn_mean
) from the seven time steps in the experiment, the names of the genes, and an array of the times at which the expression levels were measured.
load yeastdata.mat
to get an idea of the size of the data you can use numel(genes)
to show how many genes are included in the data set.
numel(genes)
ans = 6400
you can access the genes names associated with the experiment by indexing the variable genes
, a cell array representing the gene names. for example, the 15th element in genes
is yal054c. this indicates that the 15th row of the variable yeastvalues
contains expression levels for yal054c.
genes{15}
ans = 'yal054c'
a simple plot can be used to show the expression profile for this orf.
plot(times, yeastvalues(15,:)) xlabel('time (hours)'); ylabel('log2 relative expression level');
you can also plot the actual expression ratios, rather than the log2-transformed values.
plot(times, 2.^yeastvalues(15,:)) xlabel('time (hours)'); ylabel('relative expression level');
the gene associated with this orf, acs1, appears to be strongly up-regulated during the diauxic shift. you can compare the expression of this gene to the expression of other genes by plotting multiple lines on the same figure.
hold on plot(times, 2.^yeastvalues(16:26,:)') xlabel('time (hours)'); ylabel('relative expression level'); title('profile expression levels');
filtering the genes
typically, a gene expression dataset includes information corresponding to genes that do not show any interesting changes during the experiment. to make it easier to find the interesting genes, you can reduce the size of the data set to some subset that contains only the most significant genes.
if you look through the gene list, you will see several spots marked as 'empty'
. these are empty spots on the array, and while they might have data associated with them, for the purposes of this example, you can consider these points to be noise. these points can be found using the strcmp
function and removed from the data set with indexing commands.
emptyspots = strcmp('empty',genes);
yeastvalues(emptyspots,:) = [];
genes(emptyspots) = [];
numel(genes)
ans = 6314
there are also see several places in the dataset where the expression level is marked as nan. this indicates that no data was collected for this spot at the particular time step. one approach to dealing with these missing values would be to impute them using the mean or median of data for the particular gene over time. this example uses a less rigorous approach of simply throwing away the data for any genes where one or more expression level was not measured. the function isnan
is used to identify the genes with missing data and indexing commands are used to remove the genes with missing data.
nanindices = any(isnan(yeastvalues),2); yeastvalues(nanindices,:) = []; genes(nanindices) = []; numel(genes)
ans = 6276
if you were to plot the expression profiles of all the remaining profiles, you would see that most profiles are flat and not significantly different from the others. this flat data is obviously of use as it indicates that the genes associated with these profiles are not significantly affected by the diauxic shift; however, in this example, you are interested in the genes with large changes in expression accompanying the diauxic shift. you can use filtering functions in the bioinformatics toolbox™ to remove genes with various types of profiles that do not provide useful information about genes affected by the metabolic change.
you can use the genevarfilter
function to filter out genes with small variance over time. the function returns a logical array (i.e., a mask) of the same size as the variable genes
with ones corresponding to rows of yeastvalues
with variance greater than the 10th percentile and zeros corresponding to those below the threshold. you can use the mask to index into the values and remove the filtered genes.
mask = genevarfilter(yeastvalues); yeastvalues = yeastvalues(mask,:); genes = genes(mask); numel(genes)
ans = 5648
the function genelowvalfilter
removes genes that have very low absolute expression values. note that these filter functions can also automatically calculate the filtered data and names, so it is not necessary to index the original data using the mask.
[mask,yeastvalues,genes] = genelowvalfilter(yeastvalues,genes,'absval',log2(3));
numel(genes)
ans = 822
finally, you can use the function geneentropyfilter
to remove genes whose profiles have low entropy, for example entropy levels in the 15th percentile of the data.
[mask,yeastvalues,genes] = geneentropyfilter(yeastvalues,genes,'prctile',15);
numel(genes)
ans = 614
cluster analysis
now that you have a manageable list of genes, you can look for relationships between the profiles using some different clustering techniques from the statistics and machine learning toolbox™. for hierarchical clustering, the function pdist
calculates the pairwise distances between profiles and linkage
creates the hierarchical cluster tree.
corrdist = pdist(yeastvalues,'corr'); clustertree = linkage(corrdist,'average');
the cluster
function calculates the clusters based on either a cutoff distance or a maximum number of clusters. in this case, the maxclust
option is used to identify 16 distinct clusters.
clusters = cluster(clustertree,'maxclust',16);
the profiles of the genes in these clusters can be plotted together using a simple loop and the subplot
command.
figure for c = 1:16 subplot(4,4,c); plot(times,yeastvalues((clusters == c),:)'); axis tight end sgtitle('hierarchical clustering of profiles');
the statistics and machine learning toolbox also has a k-means clustering function. again, sixteen clusters are found, but because the algorithm is different these will not necessarily be the same clusters as those found by hierarchical clustering.
initialize the state of the random number generator to ensure that the figures generated by these command match the figures in the html version of this example.
rng('default'); [cidx, ctrs] = kmeans(yeastvalues,16,'dist','corr','rep',5,'disp','final'); figure for c = 1:16 subplot(4,4,c); plot(times,yeastvalues((cidx == c),:)'); axis tight end sgtitle('k-means clustering of profiles');
replicate 1, 21 iterations, total sum of distances = 23.4699. replicate 2, 22 iterations, total sum of distances = 23.5615. replicate 3, 10 iterations, total sum of distances = 24.823. replicate 4, 28 iterations, total sum of distances = 23.4501. replicate 5, 19 iterations, total sum of distances = 23.5109. best total sum of distances = 23.4501
instead of plotting all the profiles, you can plot just the centroids.
figure for c = 1:16 subplot(4,4,c); plot(times,ctrs(c,:)'); axis tight axis off end sgtitle('k-means clustering of profiles');
you can use the clustergram
function to create a heat map of the expression levels and a dendrogram from the output of the hierarchical clustering.
cgobj = clustergram(yeastvalues(:,2:end),'rowlabels',genes,'columnlabels',times(2:end));
principal component analysis
principal-component analysis(pca) is a useful technique that can be used to reduce the dimensionality of large data sets, such as those from microarrays. pca can also be used to find signals in noisy data. the function mapcaplot
calculates the principal components of a data set and create scatter plots of the results. you can interactively select data points from one of the plots, and these points are automatically highlighted in the other plot. this lets you visualize multiple dimensions simultaneously.
h = mapcaplot(yeastvalues,genes);
notice that the scatter plot of the scores of the first two principal components shows that there are two distinct regions. this is not unexpected as the filtering process removed many of the genes with low variance or low information. these genes would have appeared in the middle of the scatter plot.
if you want to look at the values of the principal components, the pca
function in the statistics and machine learning toolbox is used to calculate the principal components of a data set.
[pc, zscores, pcvars] = pca(yeastvalues);
the first output, pc
, is a matrix of the principal components of the yeastvalues
data. the first column of the matrix is the first principal component, the second column is the second principal component, and so on. the second output, zscores
, consists of the principal component scores, i.e., a representation of yeastvalues in the principal component space. the third output, pcvars
, contains the principal component variances, which give a measure of how much of the variance of the data is accounted for by each of the principal components.
it is clear that the first principal component accounts for a majority of the variance in the model. you can compute the exact percentage of the variance accounted for by each component as shown below.
pcvars./sum(pcvars) * 100
ans = 79.8316 9.5858 4.0781 2.6486 2.1723 0.9747 0.7089
this means that almost 90% of the variance is accounted for by the first two principal components. you can use the cumsum
command to see the cumulative sum of the variances.
cumsum(pcvars./sum(pcvars) * 100)
ans = 79.8316 89.4174 93.4955 96.1441 98.3164 99.2911 100.0000
if you want to have more control over the plotting of the principal components, you can use the scatter
function.
figure scatter(zscores(:,1),zscores(:,2)); xlabel('first principal component'); ylabel('second principal component'); title('principal component scatter plot');
an alternative way to create a scatter plot is with the function gscatter
from the statistics and machine learning toolbox. gscatter
creates a grouped scatter plot where points from each group have a different color or marker. you can use clusterdata
, or any other clustering function, to group the points.
figure pcclusters = clusterdata(zscores(:,1:2),'maxclust',8,'linkage','av'); gscatter(zscores(:,1),zscores(:,2),pcclusters,hsv(8)) xlabel('first principal component'); ylabel('second principal component'); title('principal component scatter plot with colored clusters');
self-organizing maps
if you have the deep learning toolbox™, you can use a self-organizing map (som) to cluster the data.
% check to see if the deep learning toolbox is installed if ~exist(which('selforgmap'),'file') disp('the self-organizing maps section of this example requires the deep learning toolbox.') return end
the selforgmap
function creates a new som network object. this example will generate a som using the first two principal components.
p = zscores(:,1:2)'; net = selforgmap([4 4]);
train the network using the default parameters.
net = train(net,p);
use plotsom
to display the network over a scatter plot of the data. note that the som algorithm uses random starting points so the results will vary from run to run.
figure plot(p(1,:),p(2,:),'.g','markersize',20) hold on plotsom(net.iw{1,1},net.layers{1}.distances) hold off
you can assign clusters using the som by finding the nearest node to each point in the data set.
distances = dist(p',net.iw{1}'); [d,cndx] = min(distances,[],2); % cndx contains the cluster index figure gscatter(p(1,:),p(2,:),cndx,hsv(numel(unique(cndx)))); legend off; hold on plotsom(net.iw{1,1},net.layers{1}.distances); hold off
close all figures.
close('all');
delete(cgobj);
delete(h);
references
[1] derisi, j.l., iyer, v.r. and brown, p.o., "exploring the metabolic and genetic control of gene expression on a genomic scale", science, 278(5338):680-6, 1997.