An introduction to the statistics behind the most popular genomic data science projects. This is the sixth course in the Genomic Big Data Science Specialization from Johns Hopkins University.

Loading...

From the course by Johns Hopkins University

Statistics for Genomic Data Science

116 ratings

An introduction to the statistics behind the most popular genomic data science projects. This is the sixth course in the Genomic Big Data Science Specialization from Johns Hopkins University.

From the lesson

Module 1

This course is structured to hit the key conceptual ideas of normalization, exploratory analysis, linear modeling, testing, and multiple testing that arise over and over in genomic studies.

- Jeff Leek, PhDAssociate Professor, Biostatistics

Bloomberg School of Public Health

One of the most common used tools for exploratory analysis of genomic data is

Â clustering, so I'm going to talk a little bit about that.

Â So I'm going to set up my plotting parameters just like I do

Â in every lecture, and then I'm going to load in the packages we're going to need.

Â In this case the main one that we're going to be using

Â is this dendextend package to make some of the dendegrams prettier.

Â So now I'm going to load the body map, data set.

Â I'm going to load it from a connection.

Â Once I've loaded in the file, then I'm going to find an easy to work

Â with variable and I'm going to extract off the FENA type data,

Â the expression data, and the feature data.

Â So the first thing that I'm going to do, to make it a little bit easier to work

Â with, is I'm going to filter it out, just like we talked about on the transforms

Â lecture, the data that has means that are below some values.

Â So I'm going to say, I'm going to require the mean count to be greater than 5000.

Â And so if I do that, I get a data set with about 1,100 or so,

Â or 1,200 or so genes, and then I'm going to take the log2 transform.

Â And again, I'm going to add 1 so that I don't get those undefined values.

Â And so the first thing that I can do is I might want to calculate

Â the distances between either samples or between genes.

Â And so if I calculate this distance

Â between genes or samples, the first thing that it's going to do is it's going to

Â calculate a distance between rows.

Â So if I want the distance between samples, then I have to take

Â the transpose of that data set so that it basically puts the samples in the rows.

Â Then when I apply disks, it'll like calculate the distance in this case,

Â the Euclidian distance between each of the different samples, and so

Â then I've got this distance matrixes.

Â The distance between every pair of samples in the data set.

Â So once I have that, I can start doing some clustering on that,

Â so the first thing I'm going to do is I'm going to define a greater set of colors.

Â So again I'm going to define this color ramp, where I go from sort of pink to blue

Â through the intermediate of white and I'm going to define nine colors.

Â Then I can make a heat map of the data set as I did in the exploratory lecture

Â I'm just going to make a heat map here of the distance now.

Â Not the actual data itself,

Â I'm going to make a heat map of the distances between the samples.

Â And so by taking the distances between the samples, I can see that, so for example

Â right here on the diagonal line, that's the distance between a sample and itself.

Â Obviously that distance is very low.

Â But you can see some samples are closer to each other, these are like these white

Â chunk here versus the some samples are farther apart say, this 19th, 18th and

Â 19th are pretty far apart, you can see that by the blue distance there.

Â And so, then what I can do is I can perform clustering on this,

Â so I use the H-clust function to do hierarchical clustering like we discussed

Â in the lecture on clustering, and so I can just apply that to the distance function,

Â and I get hierarchical clustering which I can then plot.

Â And so this shows which samples are close to each other sort of according to

Â the distance metric that we calculated.

Â If I want to make it so that it's a little easier.

Â I find it easier to read if you have all the labels at the same level and so

Â you can do that with hang equals minus 1.

Â Now you can see all of the samples sort of lined up in the same level.

Â The other thing that you might want to do is you might want to color the samples in

Â various different ways.

Â I'm going to talk a little bit about a couple of different ways you can color

Â these dendrograms.

Â To do that, I'm going to turn it into a dendrogram object,

Â the clustering we just did, and

Â then what we can do is we can color the labels in various different ways.

Â One way is to say, I just want to have four clusters.

Â And they're colored with colors, one to four.

Â And then if I plot that dendogram, you can see that it's now Now draw on the cutoff

Â basically at the place along the dendogram that splits this into four clusters.

Â And so it turns out that the place that that happens is right here

Â across this line.

Â So you end up with, once you do that cut,

Â you end up with one cluster that's this purple cluster, and

Â then one cluster that's this cluster here, and then this pink cluster here.

Â And so, you can tell it the number of clusters to make.

Â You could, if you, instead, wanted to see three clusters,

Â you could just change the number of clusters to three,

Â the number of colors to three, and make a plot.

Â And so now, she has broken it up into three different clusters,

Â instead of four different clusters.

Â Okay, so another thing that you might want to do is instead of

Â labeling the clusters according to some cut off here,

Â you might actually have a previously defined set of labels for the samples.

Â So you might know that say, the first ten samples come from one

Â case, and the last nine come from another different case.

Â And so what you can do is you can define labels, directly.

Â So it says, make the first 10, one and the second nine, two.

Â And then once you've done that, you can plot those by just seeing like here.

Â It's split into the two groups for you.

Â So you can either tell it to figure out how many clusters to color it by,

Â by telling it to use the color labels command, or

Â you can use this labels colors command to basically define which samples get what.

Â So that's a little bit about hierarchical clustering.

Â So now about k-means clustering,

Â was the other clustering technique we talked about.

Â So we can define that k-means cluster by using the k-means function.

Â So here I'm going to apply it to our filtered data set.

Â I'm going to tell it, I want three clusters.

Â So if I do that, it returns an object that tells me what cluster it belongs to, what

Â the centers of those clusters are, some information about how close the clusters

Â fit, and then some information about the model fitting process.

Â And so the first thing I might want to do is like see what the cluster

Â centers look like.

Â And so what I can do is I'm going to do matplot, which is basically going to

Â plot a sequence of each of the columns of this dataset.

Â And since I want the columns of the dataset to be plotted,

Â I am going to take the transpose of that centers matrix and

Â I'll plot out with the colors one to three since I told it there were three centers.

Â And what I see is, here are the three different cluster centers.

Â So you can see that there's one cluster that seems to be these points

Â in particular for these couple of samples in the middle are much higher then for

Â the other samples.

Â So that's the cluster centers.

Â There were three different cluster centers and so each gene is compared to each

Â of these three cluster centers, and it is assigned to the one that's closest to it.

Â So the other thing I can do is I can look at which cluster,

Â how many belong to each cluster, and so if I look at this k-means

Â one cluster variable, it basically shows which cluster each gene belongs to.

Â So if I make a table of that, that variable I can see that 396 of

Â the genes belong to this sort of third cluster.

Â 739 belong to the second cluster and so forth.

Â So the other thing that I can do is I can reorder,

Â if I'm going to make a plot, I can reorder the data according to cluster membership.

Â So I can say, put all the, so what this does is if I run this command here

Â So, I'm saying take the e data matrix and

Â then I'm reordering the rows according to the cluster relationship.

Â And now I have this new data matrix, and I can do a heat map of that new data matrix.

Â And it will be a clustered version of this, where I've clustered it with

Â k-mean's clustering as opposed to a hierarchical clustering.

Â So now I can see that genes that are similar to each other have sort of been

Â clustered together.

Â So the other thing to keep in mind when you're doing this is it's

Â not actually an algorithm that's deterministic.

Â It begins with a random start.

Â And so if I recalculate those k-means clusters and

Â I make a table of the resultant cluster membership for the two cases,

Â you can see that in this case the ones that get called two are actually

Â called one in the other sample and called one are called two and so forth.

Â So in general, they don't always have to be the same and so

Â you can look at k-means documentation to see that if you want to

Â you can look at the total number of iterations that you'd like it to use but

Â more importantly, the number of starts that you'd like it to do.

Â The number of randoms, clusters, centers you'd like it to start with and

Â if you increase the number high enough then you'll get much, much,

Â more similar results between multiple runs or the k-means clustering of it.

Â So that's a little bit about clustering R.

Â Coursera provides universal access to the worldâ€™s best education,
partnering with top universities and organizations to offer courses online.