Hey guys, in this video I wanted to go over how you can plot a Manhattan plot and QQ plot using
summary statistics in R. For this video, I'm going to assume that you already have some kind of text
file that has your summary statistics. I'm going to use this sample data set, which I got online
which are the summary statistics from a GWAS on ADHD. And this was a publicly available data set
from the psychiatric genomics consortium. I just downloaded this data set. So it's
the summary statistics results from a GWAS and all you need really are association results
that have the chromosome, base pair position, and a p-value for running this code. And in order to plot
a Manhattan plot and QQ plot in R I'm going to use a package called fastman and I'm also
going to load in a package called data.table just to read in the summary statistics file.
Let's go ahead and go over how you would plot the Manhattan plot and QQ plot in R. The first couple of
lines of code just read in the data set. So I set the working directory to the folder that has my
adhd.txt file and then I load in that file using this line of code. I already ran that line of code
so I have the data frame loaded in already here and I called the summary statistics data
"data". So my data variable has results for about 809,000 SNP association tests. I just have
loaded in the data here. Then to plot a Manhattan plot, you just run one line of code called fastman,
which stands for fast Manhattan plot. I'm going to pass in the variable that has my data frame and
this is the only required variable. If you just pass in data, the data variable, it will try to
find the correct columns of your data frame but sometimes that does not work, so I just
like to manually put in the optional parameters as well. You're going to need to put in what
the header name is for the chromosome column, the position, which is the base pair column, and also
the p value column. If I check my data frame, chromosome is called CHR in capital as the header
the base pair position is called BP and then the p-value is labeled P. These are the values that
I passed in here. And then those are the only values you have to pass in and you're ready to
run this line of code. This line of code will then plot a Manhattan plot in the plots tab, if you're
running the R code in Rstudio and it does take a minute to run. So it will take a minute to run,
then it will look like it's ready, and then it'll take about an extra minute to actually plot in
the plot window. I'm just going to wait for that result. Okay so that took about a minute or
two to run and then the Manhattan plot was plotted here. We see by default it will put the title as
"Manhattan plot" and it will also by default plot the suggestive significance line, which is here
in dashed blue and the genome-wide significant p-value line in red. So there's options in the fastman
function to either keep or remove these lines but usually what you'll do is you will check for
any SNPs that are above this significant line and you will check the locus for each of these values.
One option is you can just be done with this plot and you can keep this scheme of alternating
gray and black for the chromosomes but another thing you might want to do is you can optionally
change the colors of the Manhattan plot. You can do that just by adding an additional optional
parameter which is called "color". For color, you just pass in the colors that you want and you can
either do this by passing in a hex code directly or R has some built-in color names that you can
pass in as well. For example, I got one hex code color from just some random website. So I want to
use this red color and then I also looked at some colors that are default in R and I picked a couple
colors from these options here and you can pass in as many colors as you want. The number that
you pass in, it will just alternate. So I'm going to pass in three different colors and so it will
alternate the three different colors in the plot. I'm just going to run this next line of code
to show you the new Manhattan plot with colors and again that will take a minute or two to run.
Okay and then after that's finished running, we see the result here. These are the three colors that
I wanted to customize the plot with. And then after running a Manhattan plot, another major plot that
you always want to have when you're plotting your summary statistics results is a QQ plot.
I usually like to plot those on a square grid or with a square axis.
To do that, I'm first going to run this line of code which will make sure
that the next plot is square. And then to plot a QQ plot, you can again use the fastman package
and the function for that is fastqq. Then for this function all you have to do is pass in
your data variable and that will again take a minute to run. And when that's done you should
see the result plotted here. I have the QQ plot plotted on a square grid and we basically
would expect to see that the black dots should mostly follow this red line up to the larger p
values and that's when they should start diverting from the red line. And we also see the genomic
inflation factor value here. This factor value should be close to 1 and if you have a problem
with this or if you have inflation that might be a sign of having population structure problem
in your GWAS. And that's everything I wanted to go over in this video and thank you guys for watching~
*chiptune music*