annotate tools/rgenetics/rgfakePhe.py @ 0:9071e359b9a3

Uploaded
author xuebing
date Fri, 09 Mar 2012 19:37:19 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
1 """
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
2 fakephe.py
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
3 ross lazarus sept 30 2007
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
4 This is available under the LGPL as defined then.
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
5
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
6 use the pedigree data for ids
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
7
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
8 use pythons generators to literally generate a bunch of random phenotype measurements
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
9
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
10 Plink format at http://pngu.mgh.harvard.edu/~purcell/plink/data.shtml#pheno
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
11 is
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
12
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
13 To specify an alternate phenotype for analysis, i.e. other than the one in the *.ped file (or, if using a binary fileset, the
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
14 *.fam file), use the --pheno option:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
15 plink --file mydata --pheno pheno.txt
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
16
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
17 where pheno.txt is a file that contains 3 columns (one row per individual):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
18
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
19 Family ID
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
20 Individual ID
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
21 Phenotype
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
22
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
23 NOTE The original PED file must still contain a phenotype in column 6 (even if this is a dummy phenotype, e.g. all missing),
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
24 unless the --no-pheno flag is given.
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
25
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
26 If an individual is in the original file but not listed in the alternate phenotype file, that person's phenotype will be set to
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
27 missing. If a person is in the alternate phenotype file but not in the original file, that entry will be ignored. The order of
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
28 the alternate phenotype file need not be the same as for the original file.
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
29
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
30 If the phenotype file contains more than one phenotype, then use the --mpheno N option to specify the Nth phenotype is the one
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
31 to be used:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
32 plink --file mydata --pheno pheno2.txt --mpheno 4
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
33
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
34 where pheno2.txt contains 5 different phenotypes (i.e. 7 columns in total), this command will use the 4th for analysis
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
35 (phenotype D):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
36
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
37 Family ID
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
38 Individual ID
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
39 Phenotype A
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
40 Phenotype B
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
41 Phenotype C
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
42 Phenotype D
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
43 Phenotype E
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
44
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
45 Alternatively, your alternate phenotype file can have a header row, in which case you can use variable names to specify which
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
46 phenotype to use. If you have a header row, the first two variables must be labelled FID and IID. All subsequent variable names
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
47 cannot have any whitespace in them. For example,
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
48
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
49 FID IID qt1 bmi site
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
50 F1 1110 2.3 22.22 2
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
51 F2 2202 34.12 18.23 1
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
52 ...
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
53
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
54 then
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
55 plink --file mydata --pheno pheno2.txt --pheno-name bmi --assoc
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
56
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
57 will select the second phenotype labelled "bmi", for analysis
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
58
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
59 Finally, if there is more than one phenotype, then for basic association tests, it is possible to specify that all phenotypes
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
60 be tested, sequentially, with the output sent to different files: e.g. if bigpheno.raw contains 10,000 phenotypes, then
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
61 plink --bfile mydata --assoc --pheno bigpheno.raw --all-pheno
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
62
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
63 will loop over all of these, one at a time testing for association with SNP, generating a lot of output. You might want to use
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
64 the --pfilter command in this case, to only report results with a p-value less than a certain value, e.g. --pfilter 1e-3.
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
65
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
66 WARNING Currently, all phenotypes must be numerically coded, including missing values, in the alternate phenotype file. The
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
67 default missing value is -9, change this with --missing-phenotype, but it must be a numeric value still (in contrast to the
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
68 main phenotype in the PED/FAM file. This issue will be fixed in future releases.
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
69 Covariate files
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
70
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
71 ===========================
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
72 rgfakePhe.xml
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
73 <tool id="fakePhe1" name="Fake phenos">
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
74 <description>for multiple null fake phenotype</description>
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
75 <command interpreter="python2.4">rgfakePhe.py $input1 '$title1' $out_file1 $log_file1 $script_file</command>
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
76 <inputs>
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
77 <page>
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
78 <param name="input1"
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
79 type="library" format="lped"
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
80 label="Pedigree from Dataset"/>
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
81 <param name="title1" type="text"
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
82 value="My fake phenos" size="60"
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
83 label="Title for outputs"/>
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
84 </page>
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
85 <page>
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
86 <repeat name="fakePhe" title="Phenotypes to Fake">
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
87 <param name="pName" type="text" label="Phenotype Name">
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
88 </param>
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
89 <conditional name="series">
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
90 <param name="phetype" type="select" label="Phenotype Type">
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
91 <option value="rnorm" selected="true">Random normal variate</option>
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
92 <option value="cat">Random categorical</option>
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
93 </param>
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
94 <when value="rnorm">
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
95 <param name="Mean" type="float" value="0.0" label="Mean">
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
96 </param>
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
97 <param name="SD" type="float" label="SD" value="1.0">
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
98 </param>
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
99 </when>
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
100 <when value="cat">
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
101 <param name="values" type="text" value="1,2,3,fiddle" label="comma separated values to choose from">
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
102 </param>
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
103 </when>
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
104 </conditional>
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
105 </repeat>
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
106 </page>
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
107 </inputs>
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
108 <configfiles>
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
109 <configfile name="script_file">
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
110 #for $n, $f in enumerate($fakePhe)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
111 #if $f.series.phetype=='rnorm'
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
112 {'pN':'$f.pName','pT':'$f.series.phetype','pP':"{'Mean':'$f.series.Mean', 'SD':'$f.series.SD'}"}
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
113 #elif $f.series.phetype=='cat'
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
114 {'pN':'$f.pName','pT':'$f.series.phetype','pP':"{'values':'$f.series.values'}"}
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
115 #end if
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
116 #end for
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
117 </configfile>
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
118 </configfiles>
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
119
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
120 <outputs>
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
121 <data format="pphe" name="out_file1" />
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
122 <data format="text" name="log_file1" parent="out_file1"/>
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
123 </outputs>
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
124
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
125 <help>
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
126 .. class:: infomark
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
127
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
128 This tool allows you to generate an arbitrary (sort of)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
129 synthetic phenotype file with measurements drawn from normal,
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
130 gamma, or categorical distributions. These are for testing under
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
131 the null hypothesis of no association - the values are random but
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
132 from user specified distributions.
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
133
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
134 -----
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
135
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
136 .. class:: warningmark
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
137
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
138 This tool is very experimental
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
139
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
140 -----
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
141
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
142 - **Pedigree** is a library pedigree file - the id's will be used in the synthetic null phenotypes
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
143 - **Title** is a name to give to the output phenotype file
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
144
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
145 On the next page, you can add an unlimited number of various kinds of phenotypes including choices for
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
146 categorical ones or distributions with specific parameters
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
147
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
148 Just keep adding new ones until you're done then use the Execute button to run the generation
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
149
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
150
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
151
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
152
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
153 **Example from another tool to keep you busy and in awe**
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
154
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
155 Input file::
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
156
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
157 1 68 4.1
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
158 2 71 4.6
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
159 3 62 3.8
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
160 4 75 4.4
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
161 5 58 3.2
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
162 6 60 3.1
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
163 7 67 3.8
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
164 8 68 4.1
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
165 9 71 4.3
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
166 10 69 3.7
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
167
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
168 Create a two series XY plot on the above data:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
169
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
170 - Series 1: Red Dashed-Line plot between columns 1 and 2
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
171 - Series 2: Blue Circular-Point plot between columns 3 and 2
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
172
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
173 .. image:: ./static/images/xy_example.jpg
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
174 </help>
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
175 </tool>
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
176
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
177
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
178
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
179 """
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
180
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
181 import random,copy,sys,os,time,string,math
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
182
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
183 doFbatphe = False
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
184
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
185 galhtmlprefix = """<?xml version="1.0" encoding="utf-8" ?>
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
186 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
187 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
188 <head>
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
189 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
190 <meta name="generator" content="Galaxy %s tool output - see http://g2.trac.bx.psu.edu/" />
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
191 <title></title>
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
192 <link rel="stylesheet" href="/static/style/base.css" type="text/css" />
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
193 </head>
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
194 <body>
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
195 <div class="document">
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
196 """
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
197
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
198
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
199 def timenow():
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
200 """return current time as a string
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
201 """
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
202 return time.strftime('%d/%m/%Y %H:%M:%S', time.localtime(time.time()))
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
203
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
204
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
205 def poisson(lamb=2):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
206 """
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
207 algorithm poisson random number (Knuth):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
208 init:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
209 Let L = e^-lamb, k = 0 and p = 1.
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
210 do:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
211 k = k + 1.
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
212 Generate uniform random number u in [0,1] and let p = p u.
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
213 while p >= L.
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
214 return k - 1.
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
215 """
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
216 lamb = float(lamb)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
217 l = math.e**(-lamb)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
218 k=0
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
219 p=1
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
220 while 1:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
221 while p >= l:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
222 k += 1
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
223 u = random.uniform(0.0,1.0)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
224 p *= u
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
225 yield '%e' % (k - 1)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
226
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
227 def gammaPhe(alpha=1,beta=1):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
228 """generator for random values from a gamma
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
229 """
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
230 while 1: # an iterator for a random phenotype
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
231 dat = random.gammavariate(float(alpha),float(beta))
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
232 yield '%e' % dat
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
233
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
234 def weibullPhe(alpha=1,beta=1):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
235 """generator for random values from a weibull distribution
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
236 """
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
237 while 1: # an iterator for a random phenotype
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
238 dat = random.weibullvariate(float(alpha),float(beta))
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
239 yield '%e' % dat
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
240
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
241 def normPhe(mean=0,sd=1):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
242 """generator for random values from a normal distribution
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
243 """
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
244 while 1:# an iterator for a random phenotype
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
245 dat = random.normalvariate(float(mean),float(sd))
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
246 yield '%e' % dat
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
247
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
248 def expoPhe(mean=1):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
249 """generator for random values from an exponential distribution
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
250 """
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
251 lamb = 1.0/float(mean)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
252 while 1:# an iterator for a random phenotype
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
253 dat = random.expovariate(lamb)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
254 yield '%e' % dat
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
255
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
256
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
257 def catPhe(values='1,2,3'):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
258 """ Schrodinger's of course.
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
259 """
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
260 v = values.split(',')
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
261 while 1:# an iterator for a random phenotype
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
262 dat = random.choice(v)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
263 yield dat
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
264
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
265 def uniPhe(low=0.0,hi=1.0):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
266 """generator for a uniform distribution
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
267 what if low=-5 and hi=-2
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
268 """
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
269 low = float(low)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
270 hi = float(hi)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
271 while 1: # unif phenotype
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
272 v = random.uniform(low,hi) # 0-1
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
273 yield '%e' % v
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
274
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
275 def getIds(indir='foo'):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
276 """read identifiers - first 2 cols from a pedigree file or fam file
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
277 """
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
278 inpath = os.path.split(indir)[0] # get root
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
279 infam = '%s.fam' % indir
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
280 inped = '%s.ped' % indir # if there's a ped
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
281 flist = os.listdir(inpath)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
282 if len(flist) == 0:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
283 print >> sys.stderr, '### Error - input path %s is empty' % indir
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
284 sys.exit(1)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
285 if os.path.exists(infam):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
286 pfname = infam
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
287 elif os.path.exists(inped):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
288 pfname = inped
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
289 else:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
290 print >> sys.stderr, '### Error - input path %s contains no ped or fam' % indir
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
291 sys.exit(1)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
292 f = file(pfname,'r')
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
293 ids = []
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
294 for l in f:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
295 ll = l.split()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
296 if len(ll) > 5: # ok line?
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
297 ids.append(ll[:2])
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
298 return ids
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
299
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
300 def makePhe(phes = [],ids=[]):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
301 """Create the null phenotype values and append them to the case id
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
302 phes is the (generator, headername) for each column
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
303 for a phe file, ids are the case identifiers for the phenotype file
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
304 res contains the final strings for the file
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
305 each column is derived by iterating
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
306 over the generator actions set up by makePhes
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
307 """
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
308 header = ['FID','IID'] # for plink
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
309 res = copy.copy(ids)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
310 for (f,fname) in phes:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
311 header.append(fname)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
312 for n,subject in enumerate(ids):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
313 res[n].append(f.next()) # generate the right value
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
314 res.insert(0,header)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
315 res = [' '.join(x) for x in res] # must be space delim for fbat
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
316 return res
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
317
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
318 def makePhes(pheTypes=[], pheNames=[], pheParams=[]):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
319 """set up phes for makePhe
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
320 each has to have an iterator (action) and a name
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
321 """
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
322 action = None
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
323 phes = []
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
324 for n,pt in enumerate(pheTypes):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
325 name = pheNames[n]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
326 if pt == 'rnorm':
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
327 m = pheParams[n].get('Mean',0.0)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
328 s = pheParams[n].get('SD',1.0)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
329 action = normPhe(mean=m,sd=s) # so we can just iterate over action
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
330 elif pt == 'rgamma':
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
331 m = pheParams[n].get('Alpha',0.0)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
332 s = pheParams[n].get('Beta',1.0)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
333 action = gammaPhe(alpha=m,beta=s)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
334 if pt == 'exponential':
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
335 m = pheParams[n].get('Mean',1.0)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
336 action = expoPhe(mean=m) # so we can just iterate over action
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
337 elif pt == 'weibull':
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
338 m = pheParams[n].get('Alpha',0.0)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
339 s = pheParams[n].get('Beta',1.0)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
340 action = weibullPhe(alpha=m,beta=s)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
341 elif pt == 'cat':
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
342 v = pheParams[n].get('values',['?',])
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
343 action = catPhe(values=v)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
344 elif pt == 'unif':
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
345 low = pheParams[n].get('low',0.0)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
346 hi = pheParams[n].get('hi',1.0)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
347 action = uniPhe(low=low,hi=hi)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
348 elif pt == 'poisson':
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
349 lamb = pheParams[n].get('lamb',1.0)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
350 action = poisson(lamb=lamb)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
351 phes.append((action,name))
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
352 return phes
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
353
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
354 def doImport(outfile='test',flist=[],expl='',mylog=[]):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
355 """ import into one of the new html composite data types for Rgenetics
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
356 Dan Blankenberg with mods by Ross Lazarus
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
357 October 2007
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
358 """
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
359 outf = open(outfile,'w')
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
360 progname = os.path.basename(sys.argv[0])
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
361 outf.write(galhtmlprefix % progname)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
362 if len(flist) > 0:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
363 outf.write('<ol>\n')
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
364 for i, data in enumerate( flist ):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
365 outf.write('<li><a href="%s">%s %s</a></li>\n' % (os.path.split(data)[-1],os.path.split(data)[-1],expl))
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
366 outf.write('</ol>\n')
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
367 else:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
368 outf.write('No files found')
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
369 outf.write('<hr/><h4>Log of run follows:</h4><br/><pre>%s\n</pre><br/><hr/>' % ('\n'.join(mylog)))
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
370 outf.write("</div></body></html>\n")
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
371 outf.close()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
372
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
373
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
374 def test():
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
375 """test case
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
376 need to get these out of a galaxy form - series of pages - get types
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
377 on first screen, names on second, params on third?
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
378 holy shit. this actually works I think
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
379 """
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
380 pT = ['rnorm','rnorm','rnorm','rnorm','cat','unif']
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
381 pN = ['SysBP','DiaBP','HtCM','WtKG','Race','age']
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
382 pP = [{'Mean':'120','SD':'10'},{'Mean':'90','SD':'15'},{'Mean':'160','SD':'20'},{'Mean':'60','SD':'20'}, \
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
383 {'values':'Blink,What,Yours,green'},{'low':16,'hi':99}]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
384 phes = makePhes(pheTypes=pT, pheNames=pN, pheParams=pP)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
385 ids = []
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
386 for i in range(10):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
387 ids.append(['fid%d' % i,'iid%d' % i])
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
388 pheres = makePhe(phes=phes,ids=ids)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
389 res = [''.join(x) for x in pheres]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
390 print '\n'.join(res)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
391
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
392
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
393
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
394 if __name__ == "__main__":
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
395 """
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
396 <command interpreter="python">rgfakePhe.py '$infile1.extra_files_path/$infile1.metadata.base_name'
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
397 "$title1" '$ppheout' '$ppheout.files_path' '$script_file '
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
398 </command>
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
399 The xml file for this tool is complex, and allows any arbitrary number of
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
400 phenotype columns to be specified from a couple of optional types - rnorm, cat
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
401 are working now.
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
402
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
403 Note that we create new files in their respective library directories and link to them in the output file
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
404 so they can be displayed and downloaded separately
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
405
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
406 """
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
407 killme = string.punctuation + string.whitespace
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
408 trantab = string.maketrans(killme,'_'*len(killme))
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
409 progname = os.path.basename(sys.argv[0])
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
410 cl = '## at %s, %s got cl= %s' % (timenow(),progname,' '.join(sys.argv))
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
411 print >> sys.stdout,cl
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
412 if len(sys.argv) < 5:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
413 test()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
414 else:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
415 inped = sys.argv[1]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
416 title = sys.argv[2].translate(trantab)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
417 ppheout = sys.argv[3]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
418 pphe_path = sys.argv[4]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
419 scriptfile = sys.argv[5]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
420 ind = file(scriptfile,'r').readlines()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
421 mylog = []
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
422 s = '## %s starting at %s<br/>\n' % (progname,timenow())
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
423 mylog.append(s)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
424 mylog.append(cl)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
425 s = '## params = %s<br/>\n' % (' '.join(sys.argv[1:]))
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
426 mylog.append(s)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
427 s = '\n'.join(ind)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
428 mylog.append('Script file %s contained %s<br/>\n' % (scriptfile,s))
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
429 pT = []
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
430 pN = []
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
431 pP = []
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
432 for l in ind:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
433 l = l.strip()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
434 if len(l) > 1:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
435 adict = eval(l)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
436 pT.append(adict.get('pT',None))
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
437 pN.append(adict.get('pN',None))
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
438 pP.append(eval(adict.get('pP',None)))
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
439 s = '## pt,pn,pp=%s,%s,%s<br/>\n' % (str(pT),str(pN),str(pP))
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
440 mylog.append(s)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
441 phes = makePhes(pheTypes=pT, pheNames=pN, pheParams=pP)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
442 ids = getIds(indir=inped) # for labelling rows
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
443 pheres = makePhe(phes=phes,ids=ids) # random values from given distributions
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
444 try:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
445 os.makedirs(pphe_path)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
446 except:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
447 pass
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
448 outname = os.path.join(pphe_path,title)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
449 pphefname = '%s.pphe' % outname
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
450 f = file(pphefname, 'w')
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
451 f.write('\n'.join(pheres))
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
452 f.write('\n')
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
453 f.close()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
454 if doFbatphe:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
455 try:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
456 os.makedirs(fphe_path)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
457 except:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
458 pass
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
459 outname = os.path.join(fphe_path,title)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
460 fphefname = '%s.phe' % outname
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
461 f = file(fphefname, 'w')
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
462 header = pheres[0].split()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
463 pheres[0] = ' '.join(header[2:])# remove iid fid from header for fbat
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
464 f.write('\n'.join(pheres))
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
465 f.close()
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
466 doImport(outfile=fpheout,flist=[fphefname,],expl='(FBAT phenotype format)',mylog=mylog)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
467 #doImport(outfile='test',flist=[],expl='',mylog=[]):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
468 doImport(outfile=ppheout,flist=[pphefname,],expl='(Plink phenotype format)',mylog=mylog)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
469