4 ##A banch of r and r/qtl commands for reading input data,
5 ##running qtl analysis, and writing output data. Input data are feed to R
6 ##from and output data from R feed to a perl script called
7 ##../phenome/population_indls.
8 ##QTL mapping visualization is done by the perl script mentioned above.
9 ## r/qtl has functions for data visualization but the perl script
10 ## allows more control for publishing on the browser,
11 ##cross-referencing to other SGN datasets and CONSISTENT formatting/appearance
15 ## Isaak Y Tecle (iyt2@cornell.edu)
22 allargs
<-commandArgs()
25 infile
<- grep("infile_list", allargs
, ignore
.case
=TRUE, perl
=TRUE, value
=TRUE)
27 outfile
<-grep("outfile_list", allargs
, ignore
.case
=TRUE, perl
=TRUE, value
=TRUE)
29 statfile
<-grep("stat", allargs
, ignore
.case
=TRUE, perl
=TRUE, value
=TRUE)
33 statfiles
<-scan(statfile
, what
="character")
36 ###### QTL mapping method ############
37 qtlmethodfile
<-grep("stat_qtl_method", statfiles
, ignore
.case
=TRUE, fixed
= FALSE, value
=TRUE)
38 qtlmethod
<-scan(qtlmethodfile
, what
="character", sep
="\n")
40 if (qtlmethod
== "Maximum Likelihood") {
46 if (qtlmethod
== "Haley-knott Regression") {
51 if (qtlmethod
== "Multiple Imputation") {
56 ###### QTL model ############
57 qtlmodelfile
<-grep("stat_qtl_model", statfiles
, ignore
.case
=TRUE, fixed
= FALSE, value
=TRUE)
59 qtlmodel
<-scan(qtlmodelfile
, what
="character", sep
="\n")
61 if (qtlmodel
== "Single-QTL Scan") {
62 qtlmodel
<-c("scanone")
65 if (qtlmodel
== "Two-QTL Scan") {
66 qtlmodel
<-c("scantwo")
69 ###### permutation############
70 userpermufile
<-grep("stat_permu_test", statfiles
, ignore
.case
=TRUE, fixed
= FALSE, value
=TRUE)
72 userpermuvalue
<-scan(userpermufile
, what
="numeric", dec
= ".", sep
="\n")
73 #print(userpermuvalue)
74 if (userpermuvalue
== "None") {
77 userpermuvalue
<-as
.numeric(userpermuvalue
)
82 ######genome step size############
83 stepsizefile
<-grep("stat_step_size", statfiles
, ignore
.case
=TRUE, fixed
= FALSE, value
=TRUE)
84 stepsize
<-scan(stepsizefile
, what
="numeric", dec
= ".", sep
="\n")
85 stepsize
<-as
.numeric(stepsize
)
88 ######genotype calculation method############
89 genoprobmethodfile
<-grep("stat_prob_method", statfiles
, ignore
.case
=TRUE, fixed
= FALSE, value
=TRUE)
90 genoprobmethod
<-scan(genoprobmethodfile
, what
="character", dec
= ".", sep
="\n")
93 ########No. of draws for sim.geno method###########
95 if (is
.logical(grep("stat_no_draws", statfiles
))==TRUE) {
96 drawsnofile
<-(grep("stat_no_drwas", statfiles
, ignore
.case
=TRUE, fixed
= FALSE, value
=TRUE))
99 if (is
.logical(drawsnofile
) ==TRUE) {
100 drawsno
<-scan(drawsnofile
, what
="numeric", dec
= ".", sep
="\n")
101 drawsno
<-as
.numeric(drawsno
)
103 ########significance level for genotype probablity calculation###########
104 genoproblevelfile
<-grep("stat_prob_level", statfiles
, ignore
.case
=TRUE, fixed
= FALSE, value
=TRUE)
105 genoproblevel
<-scan(genoproblevelfile
, what
="numeric", dec
= ".", sep
="\n")
106 genoproblevel
<-as
.numeric(genoproblevel
)
109 ########significance level for permutation test###########
110 permuproblevelfile
<-grep("stat_permu_level", statfiles
, ignore
.case
=TRUE, fixed
= FALSE, value
=TRUE)
111 permuproblevel
<-scan(permuproblevelfile
, what
="numeric", dec
= ".", sep
="\n")
112 permuproblevel
<-as
.numeric(permuproblevel
)
116 infile
<-scan(file
=infile
, what
="character")#container for the ff
118 cvtermfile
<-infile
[1]#file that contains the cvtername
119 popid
<-infile
[2]#population dataset identifier
120 genodata
<-infile
[3] #file name for genotype dataset
121 phenodata
<-infile
[4] #file name for phenotype dataset
126 cross
<-scan(crossfile
, what
="character", sep
="\n")
131 popdata
<- read
.cross("csvs", genfile
=genodata
, phefile
=phenodata
, na
.strings
=c("NA"), genotypes
=c("1", "2", "3", "4", "5"), estimate
.map
=TRUE, convertXdata
=TRUE)
132 popdata
<-jittermap(popdata
)
135 popdata
<- read
.cross("csvs", genfile
=genodata
, phefile
=phenodata
, na
.strings
=c("NA"), genotypes
=c("1", "2"), estimate
.map
=TRUE, convertXdata
=TRUE)
136 popdata
<-jittermap(popdata
)
141 if (genoprobmethod
== "Calculate") {
142 popdata
<-calc
.genoprob(popdata
, step
=stepsize
, error
.prob
=genoproblevel
)
143 #calculates the qtl genotype probablity at the specififed step size and probability level
145 if (genoprobmethod
== "Simulate") {
146 popdata
<-sim
.genoprob(popdata
, n
.draws
= drawsno
, step
=stepsize
, error
.prob
=genoproblevel
, stepwidth
="fixed")
147 #calculates the qtl genotype probablity at the specififed step size
152 cvterm
<-scan(file
=cvtermfile
, what
="character") #reads the cvterm
153 cv
<-find
.pheno(popdata
, cvterm
)#returns the col no. of the cvterm
156 permuvalues
<-scan(file
=permufile
, what
="character")
158 permuvalue1
<-permuvalues
[1]
159 permuvalue2
<-permuvalues
[2]
160 if ((is
.logical(permuvalue1
) == FALSE)) {
161 if (qtlmodel
== "scanone") {
162 if (userpermuvalue
== 0 ) {
163 popdataperm
<-scanone(popdata
, pheno
.col
=cv
, model
="normal", method
=qtlmethod
)
164 #permu<-summary(popdataperm, alpha=c(0.05))
166 if (userpermuvalue
!= 0) {
167 popdataperm
<-scanone(popdata
, pheno
.col
=cv
, model
="normal", n
.perm
= userpermuvalue
, method
=qtlmethod
)
168 permu
<-summary(popdataperm
, alpha
=permuproblevel
)
172 if (qtlmodel
== "scantwo") {
173 if (userpermuvalue
== 0 ) {
174 popdataperm
<-scantwo(popdata
, pheno
.col
=cv
, model
="normal", method
=qtlmethod
)
175 #permu<-summary(popdataperm)
177 if (userpermuvalue
!= 0) {
178 popdataperm
<-scantwo(popdata
, pheno
.col
=cv
, model
="normal", n
.perm
= userpermuvalue
, method
=qtlmethod
)
179 permu
<-summary(popdataperm
, alpha
=permuproblevel
)
190 chr
<-paste("chr", no
, sep
="")
191 chrlist
<-append(chrlist
, chr
)
194 chrdata
<-paste(cvterm
, popid
, "chr1", sep
="_")
196 for (ch
in chrlist
) {
198 chrdata
<-paste(cvterm
, popid
, ch
, sep
="_");
202 n
<-paste(cvterm
, popid
, ch
, sep
="_");
203 chrdata
<-append(chrdata
, n
)
217 filedata
<-paste(cvterm
, popid
, chrno
, sep
="_");
218 filedata
<-paste(filedata
,"txt", sep
=".");
220 i
<-scanone(popdata
, chr
=chrno
, pheno
.col
=cv
)
221 position
<-max(i
, chr
=chrno
)
225 peakmarker
<-find
.marker(popdata
, chr
=chrno
, pos
=p
)
226 confidenceint
<-bayesint(i
, chr
=chrno
, prob
=0.95, expandtomarkers
=TRUE)
227 confidenceint
<-rownames(confidenceint
)
228 print (confidenceint
)
229 confidenceint
<-c(chrno
, confidenceint
, peakmarker
)
233 confidenceints
<-confidenceint
236 datasummary
<-rbind(datasummary
, i
)
237 confidenceints
<-rbind(confidenceints
, confidenceint
)
244 #print(confidenceints)
245 #print("data summary")
248 outfiles
<-scan(file
=outfile
, what
="character")
250 confidenceintfile
<-outfiles
[2]
252 write
.table(datasummary
, file
=qtlfile
, sep
="\t", col
.names
=NA, quote
=FALSE, append
=FALSE)
253 write
.table(confidenceints
, file
=confidenceintfile
, sep
="\t", col
.names
=NA, quote
=FALSE, append
=FALSE)
255 if (userpermuvalue
!= 0) {
256 if ((is
.logical(permuvalue1
) == FALSE)) {
257 write
.table(permu
, file
=permufile
, sep
="\t", col
.names
=NA, quote
=FALSE, append
=FALSE)