In this session we'll discuss using the packets rtracklayer to import data. Rtracklayer is a packet that provides functionality for interfacing with a genome browser, specifically the UCSC genome browser. And it's bidirectional interfacing, which means we can both take data in R and put it onto the genome browser, and we can take data from the genome browser and put it into R. In this session, we'll discuss the latter, the import of certain type of data into R. Because it can access data from UCSC, it can read a lot of the file formats that are traditionally associated with UCSC. Examples include, something like GFF format, this is all of the general feature folders, BIT files, WPL files And big and big weight files. The main way you read in these files into R is through the import function. And the import function has a Different. It's a method. It has different versions depending on what type of value importing. Let's start by loading up our track layer. Let's look at the help for the import function and here, you see a general help file for the import function. It tells you a little bit about what you can read in, GFF, BED, BIGWIG, and so on, and so forth. What's a little confusing, or a little important to pay attention to, is that there is also help pages that are specific to a given format. So, if I really want to know all the options for reading the BigWig file, I click her on the BigWig thing, and I read about BigWig import and export. Some of these specific file formats have other options to the import call. Files are very easy to read in. They are usually small files and they are very similar to G-ranges. Do an example of reading in a BigWig file. A BigWig file you can think of as a wiggle, first a wiggle file is a file that just changes at some kind of signal along the genome. Some kind of numeric quantity along the genome. The guys, the people at UCSC realize that just having a single long vector that's the size of the human genome is pretty inefficient, so they constructed these new file formats called BigWig. BigWig contains a single vector across the entire genome. But it's compressed and it's easy to extract the values for a given region. Now let's get a BigWig file. And the way we get a BigWig file is we're going to use AnnotationHub. We're going to return AnnotationHub. And we're going to set our hub. And here's our hub as you know it, and we're going to look very briefly at the The R data class slot. So this is the different types of data that you can connect to and we can see there's ten thousand BigWig files. We're also going to briefly discuss chain files. There's fast day files, data frame and g ranges. So there's no bit files here. Bit files are just going to be mapped directly into g ranges. So let's take about let's take a pick wick file. You're going to subset on [INAUDIBLE] rdataclass, should be BigWigFile and the species should be Homo sapiens. Okay, we need a dollar equals. And I'm just going to get the first dataset in this In this, in this list of BigWig files. I don't really care too much about what it really is Okay, we're back. That file took a while to download. And let's look at what came out. Bw, bw turns out just to be appointed down to a file. It has this weird. So let's say we want to read it. We could just say import with what really read in this entire Beta into memory. Most of the time we are really interested in just reading in part of the file or sometimes we're interesting in reading a part of the file. And let's say we do that using the wits acumen which is a g majors and let's for example say we just want to read in Chromosome 22, And I can never remember how big chromosome 22 is, but I know it's definitely less than 10 to the 8th. So this here will basically read in all of the data, chromosome 22. Relatively fast, and we see here we read it in as a GRanges with a lot of ranges, right. There's a third 1.3 million ranges in this object here. We have discussed run length encoding, and this here seems like it might be irrelevant to have as a run length encoder vector. So, we can use the s argument to the input function, and say instead of we run it back as a run length encoder vector. [NOISE] so I get back in ali list because again that one makes up for each chromosome, we only really need chromosome 22. So the only thing that really matters is chromosome 22 which gives us this nice one length coda. You can see that there's again 1.4 million runs, so it's not really clear that the run length in coding is any faster, more efficient than the GRanges we had [INAUDIBLE]. So this is the way you read in parts of the big file. Now let's just go on something slightly different. Let's discuss liftOver. Lift over is a tool from ucsc that allows you to convert between different genome versions. And we use that a lot in order to we can use that we can use we can do that using lift over has provided us part of that track layer In order to use a we have to have something that is known as a chain file. A chain file contains information about converting one specific genome to one other specific genome. So lets, and these are accessible from annotation. So let's look at an adjacent. Let's say rdataclass is equal to ChainFile. Oh, subset. And in this case here we could change files, we could recognize there's two different versions, and two genomes. it's genome two, genome. There's a mix of human data and in this case we see yeast data, all the different species that we have in USCSC. So we may want to subset this here further to only contain human data. And now we see a number of different Genome versions. We also recognized [COUGH] a couple of nonhuman genomes where we can lift over region from the human genome to various monkeys for example. Now lets get the lift-over chain from hg18 to hg19. So let's do a query of this a hop dot chain. [NOISE] And we've got to look for hta gene and we're going to look for hg and i gene. And, if we want to convert hg19 to hg18, we want to get the first one of these two here. So, now I'm downloading and I have the chain. All I need now is the set of GRanges. [COUGH] Let us just use what we got out of the BigWig before. Let's read in here. Make sure we have a GRange that's not a big break. So we have gr.chr22 and we want to convert that into. And we want to convert this from hg19 to hg18. Just say liftOver and then we get the chain. There's really no check that the genomes are correct here. So you are really trusting yourself to have done this correctly. Now what comes out of this? Let's do a class instead of printing it. Now it turns out what comes out of this is a GRanges list. And the reason why it's a GRanges list is that each of these ranges could conceivably be split into one or more pieces when we move it from one genome to another. So the length of the GRangesList is the same as the length of the original GRanges we. We can ask how often did our ranges get broken up, and for that we just need to know well, how long are each element in the GRanges list? So let's do that with element lengths of GI.HG18 and that's going to do a table of this and we see that by far most of the intervals we have drifted over got mapped one to one, there's 1100 intervals that we couldn't lift over from HTHG, 19 to HTHG. And then there's 15 intervals that got broken down in to two or three pieces. The html page associated with this system has a little bit of information about something tab it big indexing. Which allows you to pass parts of certain file formats Much faster. If you are in that situation, like you want to read in very big files and very big graph files. I suggest you read that little section. And that covers that covers of using layer to import data from. I have one final thing I forgot to say. Which is that all of this is about reading in files in our session. It's also plausible to use our track layer to import tables and tracks directly from UCFC. That is very, very convenient, but it turns out that these days most of you see a C. And I'm not actually sure but that's all of you see a C or it's just most of you see a C. It's available through annotation hog. And that's a much easier and a much more convenient interface for getting the tables and the tracks from UCSC. But if you find that there is some information that you are lacking. From UCSC in [INAUDIBLE] you can look at the vignette for the rtracklayer packets and see how you directly download the data from UCSC.