annotate MatrixEQTL/man/MatrixEQTL_cis_code.Rd @ 0:cd4c8e4a4b5b draft

Uploaded
author jasonxu
date Fri, 12 Mar 2021 08:12:46 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
1 \name{MatrixEQTL_cis_code}
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
2 \alias{MatrixEQTL_cis_code}
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
3
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
4 \title{Sample code for cis/trans-eQTL analysis with Matrix eQTL}
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
5 \description{
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
6 The following code is the best starting point for those who want to perform cis-/trans-eQTL analysis with Matrix eQTL.
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
7 }
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
8 \references{
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
9 The package website: \url{http://www.bios.unc.edu/research/genomic_software/Matrix_eQTL/}
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
10 }
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
11 \seealso{
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
12 See \code{\link{Matrix_eQTL_engine}} for reference and other sample code.
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
13 }
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
14 \author{
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
15 Andrey Shabalin \email{ashabalin@vcu.edu}
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
16 }
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
17 \examples{
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
18 # Matrix eQTL by Andrey A. Shabalin
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
19 # http://www.bios.unc.edu/research/genomic_software/Matrix_eQTL/
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
20 #
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
21 # Be sure to use an up to date version of R and Matrix eQTL.
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
22
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
23 # source("Matrix_eQTL_R/Matrix_eQTL_engine.r");
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
24 library(MatrixEQTL)
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
25
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
26 ## Location of the package with the data files.
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
27 base.dir = find.package('MatrixEQTL');
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
28
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
29 ## Settings
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
30
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
31 # Linear model to use, modelANOVA, modelLINEAR, or modelLINEAR_CROSS
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
32 useModel = modelLINEAR; # modelANOVA, modelLINEAR, or modelLINEAR_CROSS
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
33
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
34 # Genotype file name
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
35 SNP_file_name = paste(base.dir, "/data/SNP.txt", sep="");
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
36 snps_location_file_name = paste(base.dir, "/data/snpsloc.txt", sep="");
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
37
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
38 # Gene expression file name
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
39 expression_file_name = paste(base.dir, "/data/GE.txt", sep="");
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
40 gene_location_file_name = paste(base.dir, "/data/geneloc.txt", sep="");
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
41
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
42 # Covariates file name
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
43 # Set to character() for no covariates
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
44 covariates_file_name = paste(base.dir, "/data/Covariates.txt", sep="");
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
45
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
46 # Output file name
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
47 output_file_name_cis = tempfile();
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
48 output_file_name_tra = tempfile();
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
49
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
50 # Only associations significant at this level will be saved
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
51 pvOutputThreshold_cis = 2e-2;
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
52 pvOutputThreshold_tra = 1e-2;
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
53
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
54 # Error covariance matrix
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
55 # Set to numeric() for identity.
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
56 errorCovariance = numeric();
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
57 # errorCovariance = read.table("Sample_Data/errorCovariance.txt");
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
58
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
59 # Distance for local gene-SNP pairs
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
60 cisDist = 1e6;
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
61
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
62 ## Load genotype data
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
63
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
64 snps = SlicedData$new();
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
65 snps$fileDelimiter = "\t"; # the TAB character
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
66 snps$fileOmitCharacters = "NA"; # denote missing values;
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
67 snps$fileSkipRows = 1; # one row of column labels
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
68 snps$fileSkipColumns = 1; # one column of row labels
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
69 snps$fileSliceSize = 2000; # read file in slices of 2,000 rows
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
70 snps$LoadFile(SNP_file_name);
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
71
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
72 ## Load gene expression data
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
73
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
74 gene = SlicedData$new();
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
75 gene$fileDelimiter = "\t"; # the TAB character
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
76 gene$fileOmitCharacters = "NA"; # denote missing values;
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
77 gene$fileSkipRows = 1; # one row of column labels
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
78 gene$fileSkipColumns = 1; # one column of row labels
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
79 gene$fileSliceSize = 2000; # read file in slices of 2,000 rows
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
80 gene$LoadFile(expression_file_name);
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
81
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
82 ## Load covariates
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
83
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
84 cvrt = SlicedData$new();
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
85 cvrt$fileDelimiter = "\t"; # the TAB character
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
86 cvrt$fileOmitCharacters = "NA"; # denote missing values;
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
87 cvrt$fileSkipRows = 1; # one row of column labels
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
88 cvrt$fileSkipColumns = 1; # one column of row labels
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
89 if(length(covariates_file_name)>0) {
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
90 cvrt$LoadFile(covariates_file_name);
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
91 }
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
92
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
93 ## Run the analysis
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
94 snpspos = read.table(snps_location_file_name, header = TRUE, stringsAsFactors = FALSE);
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
95 genepos = read.table(gene_location_file_name, header = TRUE, stringsAsFactors = FALSE);
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
96
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
97 me = Matrix_eQTL_main(
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
98 snps = snps,
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
99 gene = gene,
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
100 cvrt = cvrt,
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
101 output_file_name = output_file_name_tra,
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
102 pvOutputThreshold = pvOutputThreshold_tra,
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
103 useModel = useModel,
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
104 errorCovariance = errorCovariance,
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
105 verbose = TRUE,
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
106 output_file_name.cis = output_file_name_cis,
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
107 pvOutputThreshold.cis = pvOutputThreshold_cis,
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
108 snpspos = snpspos,
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
109 genepos = genepos,
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
110 cisDist = cisDist,
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
111 pvalue.hist = TRUE,
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
112 min.pv.by.genesnp = FALSE,
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
113 noFDRsaveMemory = FALSE);
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
114
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
115 unlink(output_file_name_tra);
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
116 unlink(output_file_name_cis);
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
117
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
118 ## Results:
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
119
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
120 cat('Analysis done in: ', me$time.in.sec, ' seconds', '\n');
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
121 cat('Detected local eQTLs:', '\n');
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
122 show(me$cis$eqtls)
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
123 cat('Detected distant eQTLs:', '\n');
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
124 show(me$trans$eqtls)
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
125
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
126 ## Make the histogram of local and distant p-values
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
127
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
128 plot(me)
cd4c8e4a4b5b Uploaded
jasonxu
parents:
diff changeset
129 }