/usr/lib/R/site-library/GenomicRanges/doc/GRanges_and_GRangesList_slides.Rnw is in r-bioc-genomicranges 1.26.2-1+b1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 | %\VignetteIndexEntry{A quick introduction to GRanges and GRangesList objects (slides)}
%\VignetteDepends{IRanges, GenomicRanges, pasillaBamSubset, GenomicAlignments, TxDb.Dmelanogaster.UCSC.dm3.ensGene}
\SweaveOpts{keep.source=TRUE, eps=FALSE, width=9, height=3}
\documentclass[8pt]{beamer}
\usepackage{slides}
\renewcommand\Rclass[1]{{\texttt{#1}\index{#1 (class)}}}
% A Beamer Quickstart:
% http://www.math.umbc.edu/~rouben/beamer/
\newcommand\DefaultBackground{\setbeamertemplate{background canvas}[vertical shading][bottom=black!10,top=black!10]\setbeamertemplate{background canvas}[vertical shading][bottom=blue!40,top=blue!15]}
\DefaultBackground
\setbeamercolor{block body example}{bg=white}
\definecolor{YESgreen}{RGB}{0, 160, 80}
\newcommand\YES{\textcolor{YESgreen}{\textbf{YES}}}
\newcommand\PartiallySupported{\textcolor{YESgreen}{\textbf{partially supported}}}
\definecolor{NOgray}{RGB}{144, 144, 144}
\newcommand\NO{\textcolor{NOgray}{\textbf{NO}}}
%\AtBeginSection[]
%{
% \setbeamertemplate{background canvas}[vertical shading][bottom=black!47,top=black!47]
% \begin{frame}<beamer>{}
% \tableofcontents[currentsection,currentsubsection]
% \end{frame}
% \DefaultBackground
%}
%\AtBeginSubsection[]
%{
% \setbeamertemplate{background canvas}[vertical shading][bottom=black!47,top=black!47]
% \begin{frame}<beamer>{}
% \tableofcontents[currentsection,currentsubsection]
% \end{frame}
% \DefaultBackground
%}
\title{A quick introduction to GRanges and GRangesList objects}
\author{Herv\'e Pag\`es\\
\href{mailto:hpages@fredhutch.org}{hpages@fredhutch.org}\\
\---\\
Michael Lawrence\\
\href{mailto:lawrence.michael@gene.com}{lawrence.michael@gene.com}}
%\institute[FHCRC]{Fred Hutchinson Cancer Research Center\\
% Seattle, WA}
\date{July 2015}
\begin{document}
<<setup,echo=FALSE>>=
options(width=84)
plotRanges <- function(x, xlim = x, main = deparse(substitute(x)),
col = "black", sep = 0.5, ...)
{
height <- 1
if (is(xlim, "Ranges"))
xlim <- c(min(start(xlim)), max(end(xlim)))
bins <- disjointBins(IRanges(start(x), end(x) + 1))
plot.new()
par(mai=c(0.5, 0.2, 1.2, 0.2))
plot.window(xlim, c(0, max(bins)*(height + sep)))
ybottom <- bins * (sep + height) - height
rect(start(x)-0.5, ybottom, end(x)+0.5, ybottom + height, col = col, ...)
title(main, cex.main=2.8, font.main=1)
axis(1)
}
@
\maketitle
\frame{\tableofcontents}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{\Rclass{GRanges} objects}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile]
\frametitle{The \Rclass{GRanges} class is a container for...}
... storing a set of {\em genomic ranges} (a.k.a. {\em genomic regions}
or {\em genomic intervals}).
\begin{block}{}
\begin{itemize}
\item Each genomic range is described by a chromosome name,
a {\em start}, an {\em end}, and a strand.
\item {\em start} and {\em end} are both {\bf 1-based} positions
relative to the 5' end of the plus strand of the chromosome,
even when the range is on the minus strand.
\item {\em start} and {\em end} are both considered to be included
in the interval (except when the range is empty).
\item The {\em width} of the range is the number of genomic positions
included in it. So {\em width} = {\em end} - {\em start} + 1.
\item {\em end} is always >= {\em start}, except for empty ranges
(a.k.a. zero-width ranges) where {\em end} = {\em start} - 1.
\end{itemize}
Note that the {\em start} is always the leftmost position and the
{\em end} the rightmost, even when the range is on the minus strand.
Gotcha: A TSS is at the {\em end} of the range associated with a
transcript located on the minus strand.
\end{block}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{The \Rcode{GRanges()} constructor}
\begin{frame}[fragile]
\frametitle{The \Rcode{GRanges()} constructor}
\begin{exampleblock}{}
{\small
<<GRanges_constructor>>=
library(GenomicRanges)
gr1 <- GRanges(seqnames=Rle(c("ch1", "chMT"), c(2, 4)),
ranges=IRanges(16:21, 20),
strand=rep(c("+", "-", "*"), 2))
gr1
@
}
\end{exampleblock}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{\Rclass{GRanges} accessors}
\begin{frame}[fragile]
\frametitle{\Rclass{GRanges} accessors: \Rcode{length()},
\Rcode{seqnames()}, \Rcode{ranges()}}
\begin{exampleblock}{}
{\small
<<GRanges_accessors1>>=
length(gr1)
seqnames(gr1)
ranges(gr1)
@
}
\end{exampleblock}
\end{frame}
\begin{frame}[fragile]
\frametitle{\Rclass{GRanges} accessors: \Rcode{start()}, \Rcode{end()},
\Rcode{width()}, \Rcode{strand()}}
\begin{exampleblock}{}
{\small
<<GRanges_accessors2>>=
start(gr1)
end(gr1)
width(gr1)
strand(gr1)
strand(gr1) <- c("-", "-", "+")
strand(gr1)
@
}
\end{exampleblock}
\end{frame}
\begin{frame}[fragile]
\frametitle{\Rclass{GRanges} accessors: \Rcode{names()}}
\begin{exampleblock}{}
{\small
<<GRanges_accessors3>>=
names(gr1) <- LETTERS[1:6]
gr1
names(gr1)
@
}
\end{exampleblock}
\end{frame}
\begin{frame}[fragile]
\frametitle{\Rclass{GRanges} accessors: \Rcode{mcols()}}
Like with most \Bioconductor{} vector-like objects, {\em metadata columns}
can be added to a \Rclass{GRanges} object:
\begin{exampleblock}{}
{\small
<<GRanges_accessors4>>=
mcols(gr1) <- DataFrame(score=11:16, GC=seq(1, 0, length=6))
gr1
mcols(gr1)
@
}
\end{exampleblock}
\end{frame}
\begin{frame}[fragile]
\frametitle{\Rclass{GRanges} accessors: \Rcode{seqinfo()},
\Rcode{seqlevels()}, \Rcode{seqlengths()}}
\begin{exampleblock}{}
<<GRanges_accessors5>>=
seqinfo(gr1)
seqlevels(gr1)
seqlengths(gr1)
seqlengths(gr1) <- c(50000, 800)
seqlengths(gr1)
@
\end{exampleblock}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Vector operations on \Rclass{GRanges} objects}
\setbeamertemplate{background canvas}[vertical shading][bottom=green!20,top=green!20]
\begin{frame}[fragile]
\frametitle{Vector operations on \Rclass{GRanges} objects}
\begin{block}{}
What we call {\em vector operations} are operations that work on any
ordinary vector:
\begin{itemize}
\item \Rcode{length()}, \Rcode{names()}
\item Single-bracket subsetting: \Rcode{[}
\item Combining: \Rcode{c()}
\item \Rcode{split()}, \Rcode{relist()}
\item Comparing: \Rcode{==}, \Rcode{!=}, \Rcode{match()}, \Rcode{\%in\%},
\Rcode{duplicated()}, \Rcode{unique()}
\item Ordering: \Rcode{<=}, \Rcode{>=}, \Rcode{<}, \Rcode{>},
\Rcode{order()}, \Rcode{sort()}, \Rcode{rank()}
\end{itemize}
\Rclass{GRanges} objects support all these {\em vector operations}
$==>$ They're considered {\em vector-like} objects.
\end{block}
\end{frame}
\DefaultBackground
\begin{frame}[fragile]
\frametitle{Vector operations on \Rclass{GRanges} objects:
Single-bracket subsetting}
\begin{exampleblock}{}
{\small
<<GRanges_Vector_ops1>>=
gr1[c("F", "A")]
gr1[strand(gr1) == "+"]
@
}
\end{exampleblock}
\end{frame}
\begin{frame}[fragile]
\frametitle{Vector operations on \Rclass{GRanges} objects:
Single-bracket subsetting}
\begin{exampleblock}{}
{\small
<<GRanges_Vector_ops2>>=
gr1 <- gr1[-5]
gr1
@
}
\end{exampleblock}
\end{frame}
\begin{frame}[fragile]
\frametitle{Vector operations on \Rclass{GRanges} objects: Combining}
\begin{exampleblock}{}
{\small
<<GRanges_Vector_ops3>>=
gr2 <- GRanges(seqnames="ch2",
ranges=IRanges(start=c(2:1,2), width=6),
score=15:13,
GC=seq(0, 0.4, length=3))
gr12 <- c(gr1, gr2)
gr12
@
}
\end{exampleblock}
\end{frame}
\begin{frame}[fragile]
\frametitle{Vector operations on \Rclass{GRanges} objects: Comparing}
\begin{exampleblock}{}
{\small
<<GRanges_Vector_ops4>>=
gr12[length(gr12)] == gr12
duplicated(gr12)
unique(gr12)
@
}
\end{exampleblock}
\end{frame}
\begin{frame}[fragile]
\frametitle{Vector operations on \Rclass{GRanges} objects: Ordering}
\begin{exampleblock}{}
{\small
<<GRanges_sort>>=
sort(gr12)
@
}
\end{exampleblock}
\end{frame}
\begin{frame}[fragile]
\frametitle{Splitting a \Rclass{GRanges} object}
\begin{exampleblock}{}
{\small
<<GRanges_split>>=
split(gr12, seqnames(gr12))
@
}
\end{exampleblock}
\end{frame}
\setbeamertemplate{background canvas}[vertical shading][bottom=orange!40,top=orange!20]
\begin{frame}[fragile]
\frametitle{Exercise 1}
\setbeamertemplate{enumerate items}{\alph{enumi}.}
\begin{enumerate}
\item Load the \Rpackage{GenomicRanges} package.
\item Open the man page for the \Rclass{GRanges} class and run the
examples in it.
\item Extract from \Rclass{GRanges} object \Rcode{gr} the elements (i.e.
ranges) with a score between 4 and 8.
\item Split \Rcode{gr} by strand.
\end{enumerate}
\end{frame}
\DefaultBackground
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Range-based operations on \Rclass{GRanges} objects}
\setbeamertemplate{background canvas}[vertical shading][bottom=green!20,top=green!20]
\begin{frame}[fragile]
\frametitle{An overview of {\em range-based} operations}
\begin{columns}[t]
\begin{column}{0.44\textwidth}
\begin{block}{}
{\bf Intra range transformations}
\Rcode{shift()}, \Rcode{narrow()}, \Rcode{resize()}, \Rcode{flank()}
\end{block}
\begin{block}{}
{\bf Inter range transformations}
\Rcode{range()}, \Rcode{reduce()}, \Rcode{gaps()}, \Rcode{disjoin()}
\end{block}
\begin{block}{}
{\bf Range-based set operations}
\Rcode{union()}, \Rcode{intersect()}, \Rcode{setdiff()},
\Rcode{punion()}, \Rcode{pintersect()}, \Rcode{psetdiff()},
\Rcode{pgap()}
\end{block}
\end{column}
\begin{column}{0.44\textwidth}
\begin{block}{}
{\bf Coverage and slicing}
\Rcode{coverage()}, \Rcode{slice()}
\end{block}
\begin{block}{}
{\bf Finding/counting overlapping ranges}
\Rcode{findOverlaps()}, \Rcode{countOverlaps()}
\end{block}
\begin{block}{}
{\bf Finding the nearest range neighbor}
\Rcode{nearest()}, \Rcode{precede()}, \Rcode{follow()}
\end{block}
\begin{block}{}
and more...
\end{block}
\end{column}
\end{columns}
\end{frame}
\begin{frame}[fragile]
\frametitle{Examples of some common {\em range-based} operations}
\begin{exampleblock}{}
<<ranges-ir0-plot,results=hide,echo=FALSE,fig=FALSE>>=
library(IRanges)
ir0 <- IRanges(start=c(7, 9, 12, 14, 22:24),
end=c(15, 11, 12, 18, 26, 27, 28))
png("ranges-ir0-plot.png", width=800, height=170)
plotRanges(ir0, xlim=c(5, 35), main="ir0", col="blue")
dev.off()
@
<<ranges-shift-ir0-plot,results=hide,echo=FALSE,fig=FALSE>>=
png("ranges-shift-ir0-plot.png", width=800, height=170)
plotRanges(shift(ir0, 5), xlim=c(5, 35), main="shift(ir0, 5)", col="blue")
dev.off()
@
<<ranges-reduce-ir0-plot,results=hide,echo=FALSE,fig=FALSE>>=
png("ranges-reduce-ir0-plot.png", width=800, height=170)
plotRanges(reduce(ir0), xlim=c(5, 35), main="reduce(ir0)", col="blue")
dev.off()
@
<<ranges-disjoin-ir0-plot,results=hide,echo=FALSE,fig=FALSE>>=
png("ranges-disjoin-ir0-plot.png", width=800, height=170)
plotRanges(disjoin(ir0), xlim=c(5, 35), main="disjoin(ir0)", col="blue")
dev.off()
@
\begin{figure}
\centering
\includegraphics[width=0.8\textwidth,height=!]{ranges-ir0-plot}\\
\includegraphics[width=0.8\textwidth,height=!]{ranges-shift-ir0-plot}\\
\includegraphics[width=0.8\textwidth,height=!]{ranges-reduce-ir0-plot}\\
\includegraphics[width=0.8\textwidth,height=!]{ranges-disjoin-ir0-plot}
%\caption{Range-based operations}
\end{figure}
\end{exampleblock}
\end{frame}
\DefaultBackground
\begin{frame}[fragile]
\frametitle{Range-based operations on \Rclass{GRanges} objects}
\begin{exampleblock}{}
{\small
<<GRanges_Ranges_ops1>>=
gr2
shift(gr2, 50)
@
}
\end{exampleblock}
\end{frame}
\begin{frame}[fragile]
\frametitle{Range-based operations on \Rclass{GRanges} objects (continued)}
\begin{exampleblock}{}
{\small
<<GRanges_Ranges_ops2>>=
gr1
resize(gr1, 12)
@
}
\end{exampleblock}
\end{frame}
\begin{frame}[fragile]
\frametitle{Range-based operations on \Rclass{GRanges} objects (continued)}
\begin{exampleblock}{}
{\small
<<GRanges_Ranges_ops3>>=
gr1
flank(gr1, 3)
@
}
\end{exampleblock}
\end{frame}
\begin{frame}[fragile]
\frametitle{Range-based operations on \Rclass{GRanges} objects (continued)}
\begin{exampleblock}{}
{\small
<<GRanges_range>>=
gr3 <- shift(gr1, c(35000, rep(0, 3), 100))
width(gr3)[c(3,5)] <- 117
gr3
range(gr3)
@
}
\end{exampleblock}
\end{frame}
\begin{frame}[fragile]
\frametitle{Range-based operations on \Rclass{GRanges} objects (continued)}
\begin{exampleblock}{}
{\small
<<GRanges_reduce>>=
gr3
reduce(gr3)
@
}
\end{exampleblock}
\end{frame}
\begin{frame}[fragile]
\frametitle{Range-based operations on \Rclass{GRanges} objects (continued)}
\begin{exampleblock}{}
{\scriptsize
<<GRanges_gaps>>=
gr3
gaps(gr3)
@
}
\end{exampleblock}
\end{frame}
\begin{frame}[fragile]
\frametitle{Range-based operations on \Rclass{GRanges} objects (continued)}
\begin{exampleblock}{}
{\scriptsize
<<GRanges_disjoin>>=
gr3
disjoin(gr3)
@
}
\end{exampleblock}
\end{frame}
\setbeamertemplate{background canvas}[vertical shading][bottom=orange!40,top=orange!20]
\begin{frame}[fragile]
\frametitle{Exercise 2}
\setbeamertemplate{enumerate items}{\alph{enumi}.}
Using \Rclass{GRanges} object \Rcode{gr} created at Exercise 1:
\begin{enumerate}
\item Shift the ranges in \Rcode{gr} by 1000 positions to the right.
\item What method is called when doing \Rcode{shift()} on a
\Rclass{GRanges} object? Find the man page for this method.
\end{enumerate}
\end{frame}
\DefaultBackground
\begin{frame}[fragile]
\frametitle{Coverage}
\begin{exampleblock}{}
{\small
<<GRanges_coverage1>>=
cvg12 <- coverage(gr12)
cvg12
@
}
\end{exampleblock}
\end{frame}
\begin{frame}[fragile]
\frametitle{Coverage (continued)}
\begin{exampleblock}{}
{\small
<<GRanges_coverage2>>=
mean(cvg12)
max(cvg12)
@
}
\end{exampleblock}
\end{frame}
\begin{frame}[fragile]
\frametitle{Slicing the coverage}
\begin{exampleblock}{}
{\small
<<slice_coverage>>=
sl12 <- slice(cvg12, lower=1)
sl12
elementNROWS(sl12)
sl12$chMT
mean(sl12$chMT)
max(sl12$chMT)
@
}
\end{exampleblock}
\end{frame}
\begin{frame}[fragile]
\frametitle{findOverlaps()}
\begin{block}{}
Load aligned reads from a BAM file:
\end{block}
\begin{exampleblock}{}
{\small
<<findOverlaps1>>=
library(pasillaBamSubset)
untreated1_chr4()
library(GenomicAlignments)
reads <- readGAlignments(untreated1_chr4())
@
}
\end{exampleblock}
\begin{block}{}
and store them in a \Rclass{GRanges} object:
\end{block}
\begin{exampleblock}{}
{\small
<<findOverlaps2>>=
reads <- as(reads, "GRanges")
reads[1:4]
@
}
\end{exampleblock}
\end{frame}
\begin{frame}[fragile]
\frametitle{findOverlaps() (continued)}
\begin{block}{}
Load the gene ranges from a {\em TxDb} package:
\end{block}
\begin{exampleblock}{}
{\small
<<findOverlaps3>>=
library(TxDb.Dmelanogaster.UCSC.dm3.ensGene)
txdb <- TxDb.Dmelanogaster.UCSC.dm3.ensGene
dm3_genes <- genes(txdb)
@
}
\end{exampleblock}
\begin{block}{}
and find the overlaps between the reads and the genes:
\end{block}
\begin{exampleblock}{}
{\small
<<findOverlaps4>>=
hits <- findOverlaps(reads, dm3_genes)
head(hits)
@
}
\end{exampleblock}
\end{frame}
\setbeamertemplate{background canvas}[vertical shading][bottom=orange!40,top=orange!20]
\begin{frame}[fragile]
\frametitle{Exercise 3}
\setbeamertemplate{enumerate items}{\alph{enumi}.}
\begin{enumerate}
\item Recreate \Rclass{GRanges} objects \Rcode{reads} and
\Rcode{dm3\_genes} from previous slides.
\item What method is called when calling \Rcode{findOverlaps()} on
them? Open the man page for this method.
\item Find the overlaps between the 2 objects but this time the strand
should be ignored.
\end{enumerate}
\end{frame}
\DefaultBackground
\setbeamertemplate{background canvas}[vertical shading][bottom=orange!40,top=orange!20]
\begin{frame}[fragile]
\frametitle{Exercise 4}
\setbeamertemplate{enumerate items}{\alph{enumi}.}
In this exercise we want to get the exon sequences for the dm3 genome.
\begin{enumerate}
\item Extract the exon ranges from \Rcode{txdb}.
\item Load the \Rpackage{BSgenome.Dmelanogaster.UCSC.dm3} package.
\item Use \Rcode{getSeq()} to extract the exon sequences from the
\Rcode{BSgenome} object in \Rpackage{BSgenome.Dmelanogaster.UCSC.dm3}.
\end{enumerate}
\end{frame}
\DefaultBackground
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{\Rclass{GRangesList} objects}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile]
\frametitle{The \Rclass{GRangesList} class is a container for...}
storing a list of {\em compatible} \Rclass{GRanges} objects.
\begin{block}{}
{\em compatible} means:
\begin{itemize}
\item they are relative to the same genome,
\item AND they have the same metadata columns (accessible with
the \Rcode{mcols()} accessor).
\end{itemize}
\end{block}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{The \Rcode{GRangesList()} constructor}
\begin{frame}[fragile]
\frametitle{The \Rcode{GRangesList()} constructor}
\begin{exampleblock}{}
{\small
<<GRangesList_constructor>>=
grl <- GRangesList(gr3, gr2)
grl
@
}
\end{exampleblock}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{\Rclass{GRangesList} accessors}
\begin{frame}[fragile]
\frametitle{\Rclass{GRangesList} accessors}
\begin{exampleblock}{}
<<GRangesList_accessors1>>=
length(grl)
@
\end{exampleblock}
\begin{columns}[t]
\begin{column}{0.44\textwidth}
\begin{exampleblock}{}
{\small
<<GRangesList_accessors2>>=
seqnames(grl)
@
}
\end{exampleblock}
\end{column}
\begin{column}{0.44\textwidth}
\begin{exampleblock}{}
{\small
<<GRangesList_accessors3>>=
strand(grl)
@
}
\end{exampleblock}
\end{column}
\end{columns}
\end{frame}
\begin{frame}[fragile]
\frametitle{\Rclass{GRangesList} accessors (continued)}
\begin{columns}[t]
\begin{column}{0.44\textwidth}
\begin{exampleblock}{}
{\small
<<GRangesList_accessors4>>=
ranges(grl)
@
}
\end{exampleblock}
\end{column}
\begin{column}{0.44\textwidth}
\begin{exampleblock}{}
{\small
<<GRangesList_accessors5>>=
start(grl)
end(grl)
width(grl)
@
}
\end{exampleblock}
\end{column}
\end{columns}
\end{frame}
\begin{frame}[fragile]
\frametitle{\Rclass{GRangesList} accessors (continued)}
\begin{exampleblock}{}
{\small
<<GRangesList_accessors6>>=
names(grl) <- c("TX1", "TX2")
grl
@
}
\end{exampleblock}
\end{frame}
\begin{frame}[fragile]
\frametitle{\Rclass{GRangesList} accessors (continued)}
\begin{exampleblock}{}
{\scriptsize
<<GRangesList_accessors7>>=
mcols(grl)$geneid <- c("GENE1", "GENE2")
mcols(grl)
grl
@
}
\end{exampleblock}
\end{frame}
\begin{frame}[fragile]
\frametitle{\Rclass{GRangesList} accessors (continued)}
\begin{exampleblock}{}
<<GRangesList_accessors8>>=
seqinfo(grl)
@
\end{exampleblock}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Vector operations on \Rclass{GRangesList} objects}
\setbeamertemplate{background canvas}[vertical shading][bottom=green!20,top=green!20]
\begin{frame}[fragile]
\frametitle{Vector operations on \Rclass{GRangesList} objects}
\begin{block}{}
Only the following {\em vector operations} are supported on
\Rclass{GRangesList} objects:
\begin{itemize}
\item \Rcode{length()}, \Rcode{names()}
\item Single-bracket subsetting: \Rcode{[}
\item Combining: \Rcode{c()}
\end{itemize}
\end{block}
\end{frame}
\DefaultBackground
\begin{frame}[fragile]
\frametitle{Vector operations on \Rclass{GRangesList} objects}
\begin{exampleblock}{}
{\small
<<GRangesList_Vector_ops1>>=
grl[c("TX2", "TX1")]
@
}
\end{exampleblock}
\end{frame}
\begin{frame}[fragile]
\frametitle{Vector operations on \Rclass{GRangesList} objects (continued)}
\begin{exampleblock}{}
{\scriptsize
<<GRangesList_Vector_ops2>>=
c(grl, GRangesList(gr3))
@
}
\end{exampleblock}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{List operations on \Rclass{GRangesList} objects}
\setbeamertemplate{background canvas}[vertical shading][bottom=green!20,top=green!20]
\begin{frame}[fragile]
\frametitle{List operations on \Rclass{GRangesList} objects}
\begin{block}{}
What we call {\em list operations} are operations that work on an
ordinary list:
\begin{itemize}
\item Double-bracket subsetting: \Rcode{[[}
\item \Rcode{elementNROWS()}, \Rcode{unlist()}
\item \Rcode{lapply()}, \Rcode{sapply()}, \Rcode{endoapply()}
\item \Rcode{mendoapply()} (not covered in this presentation)
\end{itemize}
\Rclass{GRangesList} objects support all these {\em list operations}
$==>$ They're considered {\em list-like} objects.
\end{block}
\end{frame}
\DefaultBackground
\begin{frame}[fragile]
\frametitle{elementNROWS() and unlist()}
\begin{exampleblock}{}
{\scriptsize
<<GRangesList_List_ops1>>=
grl[[2]]
elementNROWS(grl)
unlisted <- unlist(grl, use.names=FALSE) # same as c(grl[[1]], grl[[2]])
unlisted
@
}
\end{exampleblock}
\end{frame}
\begin{frame}[fragile]
\frametitle{relist()}
\begin{exampleblock}{}
{\small
<<GRangesList_List_ops2>>=
grl100 <- relist(shift(unlisted, 100), grl)
grl100
@
}
\end{exampleblock}
\end{frame}
\begin{frame}[fragile]
\frametitle{endoapply()}
\begin{exampleblock}{}
{\scriptsize
<<GRangesList_List_ops3>>=
grl100b <- endoapply(grl, shift, 100)
grl100b
mcols(grl100)
mcols(grl100b)
@
}
\end{exampleblock}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Range-based operations on \Rclass{GRangesList} objects}
\begin{frame}[fragile]
\frametitle{Range-based operations on \Rclass{GRangesList} objects}
\begin{columns}[t]
\begin{column}{0.49\textwidth}
\begin{exampleblock}{}
{\scriptsize
<<GRangesList_Ranges_ops1>>=
grl
@
}
\end{exampleblock}
\end{column}
\begin{column}{0.49\textwidth}
\begin{exampleblock}{}
{\scriptsize
<<GRangesList_Ranges_ops2>>=
shift(grl, 100)
@
}
\end{exampleblock}
\end{column}
\end{columns}
\begin{block}{}
\Rcode{shift(grl, 100)} is equivalent to \Rcode{endoapply(grl, shift, 100)}
\end{block}
\end{frame}
\begin{frame}[fragile]
\frametitle{Range-based operations on \Rclass{GRangesList}
objects (continued)}
\begin{columns}[t]
\begin{column}{0.49\textwidth}
\begin{exampleblock}{}
{\scriptsize
<<GRangesList_Ranges_ops3>>=
grl
@
}
\end{exampleblock}
\end{column}
\begin{column}{0.49\textwidth}
\begin{exampleblock}{}
{\scriptsize
<<GRangesList_Ranges_ops4>>=
flank(grl, 10)
@
}
\end{exampleblock}
\end{column}
\end{columns}
\begin{block}{}
\Rcode{flank(grl, 10)} is equivalent to \Rcode{endoapply(grl, flank, 10)}
\end{block}
\end{frame}
\begin{frame}[fragile]
\frametitle{Range-based operations on \Rclass{GRangesList}
objects (continued)}
\begin{columns}[t]
\begin{column}{0.49\textwidth}
\begin{exampleblock}{}
{\scriptsize
<<GRangesList_Ranges_ops5>>=
grl
@
}
\end{exampleblock}
\end{column}
\begin{column}{0.49\textwidth}
\begin{exampleblock}{}
{\scriptsize
<<GRangesList_Ranges_ops6>>=
range(grl)
@
}
\end{exampleblock}
\end{column}
\end{columns}
\begin{block}{}
\Rcode{range(grl)} is equivalent to \Rcode{endoapply(grl, range)}
\end{block}
\end{frame}
\begin{frame}[fragile]
\frametitle{Range-based operations on \Rclass{GRangesList}
objects (continued)}
\begin{columns}[t]
\begin{column}{0.49\textwidth}
\begin{exampleblock}{}
{\scriptsize
<<GRangesList_Ranges_ops7>>=
grl
@
}
\end{exampleblock}
\end{column}
\begin{column}{0.49\textwidth}
\begin{exampleblock}{}
{\scriptsize
<<GRangesList_Ranges_ops8>>=
reduce(grl)
@
}
\end{exampleblock}
\end{column}
\end{columns}
\begin{block}{}
\Rcode{reduce(grl)} is equivalent to \Rcode{endoapply(grl, reduce)}
\end{block}
\end{frame}
\begin{frame}[fragile]
\frametitle{Range-based operations on \Rclass{GRangesList}
objects (continued)}
<<GRangesList_Ranges_ops9,results=hide,echo=FALSE>>=
grl2 <- grl
grl2[[1]] <- grl2[[1]][3]; grl2[[2]] <- grl2[[2]][1]
grl3 <- unname(grl2)
grl3[[1]] <- narrow(unname(grl3[[1]]), start=5, end=-5)
@
\begin{columns}[t]
\begin{column}{0.49\textwidth}
\begin{exampleblock}{}
{\scriptsize
<<GRangesList_Ranges_ops10>>=
grl2
grl3
@
}
\end{exampleblock}
\end{column}
\begin{column}{0.49\textwidth}
\begin{exampleblock}{}
{\scriptsize
<<GRangesList_Ranges_ops11>>=
setdiff(grl2, grl3)
@
}
\end{exampleblock}
\end{column}
\end{columns}
\begin{block}{}
\Rcode{setdiff(grl2, grl)} is equivalent to
\Rcode{mendoapply(setdiff, grl2, grl)}
\end{block}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Other resources}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[fragile]
\frametitle{Other resources}
\begin{itemize}
\item Great slides from Michael on ranges sequences and alignments:
\url{http://bioconductor.org/help/course-materials/2014/CSAMA2014/2_Tuesday/lectures/Ranges_Sequences_and_Alignments-Lawrence.pdf}
\item Vignettes in the \Rpackage{GenomicRanges} package
(\Rcode{browseVignettes("GenomicRanges")}).
\item \Rclass{GRanges} and \Rclass{GRangesList} man pages in the
\Rpackage{GenomicRanges} package.
\item Vignettes and \Rclass{GAlignments} man page in the
\Rpackage{GenomicAlignments} package.
\item \Bioconductor{} support site:
\url{http://support.bioconductor.org/}
\item The {\em genomic ranges} paper:
Michael Lawrence, Wolfgang Huber, Herv\'e Pag\`es, Patrick Aboyoun,
Marc Carlson, Robert Gentleman, Martin T. Morgan, Vincent J. Carey.
Software for Computing and Annotating Genomic Ranges.
{\em PLOS Computational Biology}, 4(3), 2013.
\end{itemize}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}
|