This file is indexed.

/usr/lib/R/site-library/snpStats/doc/data-input-vignette.Rnw is in r-bioc-snpstats 1.24.0+dfsg-1.

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
\documentclass[12pt]{article}
\usepackage{fullpage}
\usepackage{graphicx}

\usepackage[pdftex,
bookmarks,
bookmarksopen,
pdfauthor={David Clayton},
pdftitle={Data input}]
{hyperref}

\title{Data input vignette\\Reading genotype data in {\tt snpStats}}
\author{David Clayton}
\date{\today}

\usepackage{Sweave}
\SweaveOpts{echo=TRUE, pdf=TRUE, eps=FALSE}

\begin{document}
\setkeys{Gin}{width=1.0\textwidth}

%\VignetteIndexEntry{Data input}
%\VignettePackage{snpStats}

\maketitle

<<lib,echo=FALSE>>=
require(snpStats)
@ 
\section*{Memory limitations}
Before we start it is important to emphasise that the {\tt SnpMatrix}
objects that hold genotype data in {\tt snpStats} 
are resident in memory, and limitations
of the computer and of the R language impose limits on the maximum
size of datasets that can be held at any one time. Each genotype
reading uses only a single byte of memory so that large datasets can
be read given the large memory capacity of modern
computers. Originally, 
R imposed a limit of  $2^{31}-1 \sim 2\times 10^9$ elements in a single
array. This limit applied in both the 32-bit and 64-bit versions
  of R, these versions differing only in the {\em total} memory that could
  be used. For example, this would correspond to one million loci for two
thousand subjects and would occupy two gigabytes of machine
memory. However, version 3 of R removed the restriction on single
arrays in the 64-bit version,  and this was implemented for
{\tt SnpMatrix} and {\tt XSnpMatrix} objects in version
1.19.2 of {\tt snpStats}. However, experience of this code is limited
and some caution is advised.
 
\section*{Reading pedfiles}
A commonly encountered format for storing genotype data is the
``pedfile'' format, which originated some years ago  in the LINKAGE
package. Pedfiles are text files containing one line per genotyped
sample, with fields separated by ``white space'' ( TAB
characters or SPACEs). The first six fields contain:
\begin{enumerate}
\item a pedigree or family identifier, unique to the family of which
  this subject is a member,
\item a further identifier, unique (within the family) to each family member,
\item the member identifier of the father of the subject if the father
  is also present in the data, otherwise an arbitrary code (usually
  {\tt 0}),
\item similarly, an identifier for the mother of the subject,
\item the sex of the subject ({\tt 1 =} Male, {\tt 2 =} Female), and
\item a binary trait indicator ({\tt 1 =} Absent, {\tt 2 =} Present).
\end{enumerate}
Missing values in the last two fields are usually coded as zero. 

The first few rows and columns of a sample file is shown below:
\begin{verbatim}
IBD054	430	0	0	1	0	1  3	3  1	4  1	4  2
IBD054	412	430	431	2	2	1  3	1  3	4  1	4  2
IBD054	431	0	0	2	0	3  3	3  3	1  1	2  2
IBD058	438	0	0	1	0	3  3	3  3	1  1	2  2
IBD058	470	438	444	2	2	3  3	3  3	1  1	2  2
\end{verbatim}
Thus, the subject of line~2 has a father whose data appears on line~1
and a mother whose data is on line~3. The grandparents do not appear
on the file. This subject is affected by the trait, but the trait
status of her parents is not known. The genotypes of this subject 
at the first four loci are {\tt 1/3}, {\tt 1/3}, {\tt 4/1} and {\tt 4/2}.
Note that {\tt snpStats} will only deal with diallelic data and,
although alleles are coded 1 to 4 in this file, only two of these
occur with in any one locus. In fact these data are from the sample
dataset distributed with the HAPLOVIEW program (Barrett et al., 2005)
which uses the numbers 1--4 to denote the four nucleotides:  {\tt 1 =}
A, {\tt 2 =} C, {\tt 3 = } G, {\tt 4 =} . The pedfile contains data for
20 loci on 120 subjects, and is accompanied by
a second file which describes the loci, the first four lines being:
\begin{verbatim}
IGR1118a_1	274044
IGR1119a_1	274541
IGR1143a_1	286593
IGR1144a_1	287261
\end{verbatim}
(this file is rather simple, containing just the locus name and its
position on a chromosome). 

The (gzipped) pedfile and the locus information file are stored in the 
{\tt extdata} sub-directory of the {\tt snpStats} package as, respectively,
{\tt sample.ped.gz} and {\tt sample.info}. Since the precise location
of these files may vary between installations, we first obtain full paths 
to these files  using the {\tt system.file} function
<<sysfile>>=
pedfile <- system.file("extdata/sample.ped.gz", package="snpStats")
pedfile
infofile <- system.file("extdata/sample.info", package="snpStats")
@ 
The data can then be read in using the {\tt read.pedfile} function
<<redpedfile>>=
sample <- read.pedfile(pedfile, snps=infofile)
@ 
The result, {\tt sample}, is a list with three elements. The first is an
object of class {\tt SnpMatrix} containing the genotype data. We shall
show summaries for the first few loci
<<sample1>>=
sample$genotypes
col.summary(sample$genotypes)$MAF
head(col.summary(sample$genotypes))
@ 
The second list element is a dataframe containing the first six fields of the
pedfile. We'll just display the start of this:
<<sample2>>=
head(sample$fam)
@ 
Note that the zero values in the pedfile have been read as
{\tt NA}; this is optional, but default, behaviour of the
function. Here the pedigree-member identifiers have been used as
subject identifiers, since these are not duplicated while pedigree
identifiers (the first choice) were duplicated (if both sets of
identifiers are duplicated, they are combined).
Finally, the third list element is a dataframe containing the
information read from the {\tt sample.info} file, to which have been
added the two alleles found at each locus:
<<sample3>>=
head(sample$map)
@ 
Here we have used the default settings of {\tt read.pedfile}. In
particular, it is not mandatory to supply a locus description file and
there
are further arguments which allow additional flexibility. These
options are described in the on-line help page.
\section*{PLINK files}
Binary PED (BED) files written by the PLINK toolset (Purcell et al., 2007) 
may also be
read as {\tt SnpMatrix} objects. Files of type {\tt .bed} are written
by the {\tt plink --make-bed} command and are accompanied by two text
files: a {\tt .fam} file containing the first six fields of a standard
pedfile as described above, and a {\tt .bim} file which describes the
loci. The package data directory also 
contains {\tt .bed}, {\tt .fam}
and {\tt .bim} files for the sample dataset of the last section; the
following commands recover the full file paths for these files and 
read the files:
<<plink>>=
fam <- system.file("extdata/sample.fam", package="snpStats")
bim <- system.file("extdata/sample.bim", package="snpStats")
bed <- system.file("extdata/sample.bed", package="snpStats")
sample <- read.plink(bed, bim, fam)
@ 
The output object is similar to that produced by {\tt read.pedfile}, a
list with three elements:
<<plinkout>>=
sample$genotypes
col.summary(sample$genotypes)$MAF
head(sample$fam)
head(sample$map)
@ 
Usually the three input files have the same filename stub with
{\tt .bed}, {\tt .fam} and {\tt .bim} extensions added. In this case
it is sufficient to just supply the filename stub to {\tt read.plink}.

A useful feature of {\tt read.plink} is the ability to select a
subset of data from a large PLINK dataset. This is demonstrated
in our small example below
<<plinkselect>>=
subset <- read.plink(bed, bim, fam, select.snps=6:10)
subset$genotypes
col.summary(subset$genotypes)$MAF
subset$map
@ 
Note that, in order to select certain SNPs, the input PLINK
file must be in SNP-major order {\it i.e.\,} all individuals for the
first SNP, all individuals for the second SNP, and so on. This is the
default mode in PLINK. However, to select certain individuals, the
input PLINK file must be in individual-major order.
\section*{Long format data}
The least compact, but perhaps most flexible, input format is the
``long'' format in which each genotype call takes up a single
line. Such data can be read using the function {\tt read.snps.long}.
A simple example is provided by the small gzipped data file {\tt
  sample-long.gz} provided with the package:
<<longfile>>=
longfile <- system.file("extdata/sample-long.gz", package="snpStats")
longfile
@ 
The first 5 lines of the file are listed as follows:
<<longlist>>=
cat(readLines(longfile, 5), sep="\n")
@ 
The first field gives the SNP identifier ({\tt snp1} to {\tt snp18}),
the second gives the sample, or subject, identifier  ({\tt subject1} to 
{\tt subject100}), the third field gives the genotype call ({\tt
  1=A/A}, {\tt 2=A/B}, {\tt 3=B/B}), and the last field gives a
confidence measure for the call (here always {\tt 1.000}).
To read in this file and inspect the data:
<<readlong>>=
gdata <- read.long(longfile, 
   fields=c(snp=1, sample=2, genotype=3, confidence=4),
   gcodes=c("1", "2", "3"), 
   threshold=0.95)
gdata
summary(gdata)
@ 
A few remarks:
\begin{enumerate}
\item In our example, the entire file has been read. However, subsets
  of data may be extracted by specifying the required SNP or sample
  identifiers.
\item Any calls for which the call confidence is less than {\tt
    threshold} is set to {\tt NA} (this did not affect any calls in
  this simple example).
\item Here, calls were represented by a single genotype code. It is
  also possible to read calls as pairs of alleles. The function then
  returns a list whose first argument is the {\tt SnpMatrix} object,
  and whose second object is a dataframe containing the allele
  codes. This option is demonstrated below, using an alternative
  coding of the same data (all SNPs are {\tt CT} SNPs):
\end{enumerate}
<<readlongallele>>=
allelesfile <- system.file("extdata/sample-long-alleles.gz", package="snpStats")
cat(readLines(allelesfile, 5), sep="\n")
gdata <- read.long(allelesfile, 
   fields=c(snp=1, sample=2, allele.A=3, allele.B=4, confidence=5),
   threshold=0.95)
gdata
gdata$genotypes
gdata$alleles
@
Note that the assignment of alleles depends on the order in which they
were encountered.

This function has many options and the online help page needs to be
read carefully.
\section*{Other formats}
\subsection*{Imputation}
A further source of input data is programs which can {\em impute}
genotype data for a set of study individuals, using genome-wide
SNP-chip data for the study subjects plus HapMap or 1,000 genomes
project datasets. {\tt snpStats} provides the functions {\tt
  read.beagle}, {\tt read.impute}, and {\tt read.mach} to read in
files produced by the leading imputation programs. For more details of
such data, see the imputation and meta-analysis vignette.
\subsection*{VCF format}
The 1,000 genomes data are released in the VCF format. {\tt snpStats}
does not yet include a function to read data files in this format, 
but the {\tt GGtools}
package does contain such a function ({\tt vcf2sm}).
\subsection*{X, Y and mitocondrial SNPs}
The {\tt SnpMatrix} class is designed for diploid SNP
genotypes. SNPs which can be haploid are stored in objects of the {\tt
  XSnpMatrix} class, which has an addition slot, named {\tt diploid}. Since,
for the X chromosome, ploidy depends on sex and may vary from row to
row, this (logical) vector has the same number of elements as the
number of rows in the SNP data matrix. Most input routines do not
allow for reading an {\tt XSnpMatrix} and simply read into a {\tt
  SnpMatrix}, coding haploid calls as (homozygous) diploid. Such
objects may then be coerced into the {\tt XSnpMatrix} class using {\tt
  as(\ldots, "XSnpMatrix")} or {\tt new("XSnpMatrix, \ldots,
  diploid=\ldots)}. If {\tt as} is used, ploidy is inferred from
homozygosity while, if {\tt new} is used, it must be supplied (if all
rows have the same ploidy, this argument can be a scalar). In either
case, calls presumed to be haploid but coded as heterozygous will be set
to {\tt NA}.
\section*{Reference}
Barrett JC, Fry B, Maller J, Daly MJ.(2005)  Haploview: analysis
and visualization of LD and haplotype maps. {\it Bioinformatics}, 2005 Jan 15,
[PubMed ID: 15297300]\\[2mm]
Purcell S, Neale B, Todd-Brown K, Thomas L, Ferreira MAR, 
Bender D, Maller J, Sklar P, de Bakker PIW, Daly MJ and Sham PC (2007) 
PLINK: a toolset for whole-genome association and population-based 
linkage analysis. {\it American Journal of Human Genetics}, {\bf 81}
\end{document}