annotate pca.py @ 5:8a1147101f85

added 3rd party software
author Richard Burhans <burhans@bx.psu.edu>
date Tue, 10 Apr 2012 12:49:47 -0400
parents 2c498d40ecde
children 248b06e86022
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
1 #!/usr/bin/env python
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
2
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
3 import errno
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
4 import os
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
5 import shutil
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
6 import subprocess
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
7 import sys
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
8 from BeautifulSoup import BeautifulSoup
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
9 import gd_composite
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
10
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
11 ################################################################################
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
12
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
13 def mkdir_p(path):
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
14 try:
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
15 os.makedirs(path)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
16 except OSError, e:
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
17 if e.errno <> errno.EEXIST:
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
18 raise
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
19
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
20 ################################################################################
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
21
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
22 def run_program(prog, args, stdout_file=None):
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
23 #print "args: ", ' '.join(args)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
24 p = subprocess.Popen(args, bufsize=-1, executable=prog, stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
25 (stdoutdata, stderrdata) = p.communicate()
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
26 rc = p.returncode
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
27
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
28 if stdout_file is not None:
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
29 with open(stdout_file, 'w') as ofh:
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
30 print >> ofh, stdoutdata
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
31
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
32 if rc != 0:
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
33 print >> sys.stderr, "FAILED: rc={0}: {1}".format(rc, ' '.join(args))
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
34 print >> sys.stderr, stderrdata
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
35 sys.exit(1)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
36
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
37 ################################################################################
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
38
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
39 def do_ped2geno(input, output):
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
40 lines = []
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
41 with open(input) as fh:
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
42 for line in fh:
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
43 line = line.rstrip('\r\n')
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
44 lines.append(line.split())
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
45
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
46 pair_map = {
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
47 '0':{ '0':'9', '1':'9', '2':'9' },
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
48 '1':{ '0':'1', '1':'2', '2':'1' },
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
49 '2':{ '0':'1', '1':'1', '2':'0' }
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
50 }
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
51 with open(output, 'w') as ofh:
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
52 for a_idx in xrange(6, len(lines[0]), 2):
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
53 b_idx = a_idx + 1
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
54 print >> ofh, ''.join(map(lambda line: pair_map[line[a_idx]][line[b_idx]], lines))
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
55
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
56 def do_map2snp(input, output):
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
57 with open(output, 'w') as ofh:
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
58 with open(input) as fh:
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
59 for line in fh:
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
60 elems = line.split()
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
61 print >> ofh, ' {0} 11 0.002 2000 A T'.format(elems[1])
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
62
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
63 def make_ind_file(ind_file, input):
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
64 pops = []
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
65
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
66 ofh = open(ind_file, 'w')
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
67
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
68 with open(input) as fh:
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
69 soup = BeautifulSoup(fh)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
70 misc = soup.find('div', {'id': 'gd_misc'})
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
71 populations = misc('ul')[0]
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
72
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
73 i = 0
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
74 for entry in populations:
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
75 if i % 2 == 1:
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
76 population_name = entry.contents[0].encode('utf8').strip().replace(' ', '_')
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
77 pops.append(population_name)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
78 individuals = entry.ol('li')
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
79 for individual in individuals:
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
80 individual_name = individual.string.encode('utf8').strip()
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
81 print >> ofh, individual_name, 'M', population_name
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
82 i += 1
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
83
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
84 ofh.close()
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
85 return pops
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
86
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
87 def make_par_file(par_file, geno_file, snp_file, ind_file, evec_file, eval_file):
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
88 with open(par_file, 'w') as fh:
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
89 print >> fh, 'genotypename: {0}'.format(geno_file)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
90 print >> fh, 'snpname: {0}'.format(snp_file)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
91 print >> fh, 'indivname: {0}'.format(ind_file)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
92 print >> fh, 'evecoutname: {0}'.format(evec_file)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
93 print >> fh, 'evaloutname: {0}'.format(eval_file)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
94 print >> fh, 'altnormstyle: NO'
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
95 print >> fh, 'numoutevec: 2'
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
96
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
97 def do_smartpca(par_file):
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
98 prog = 'smartpca'
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
99
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
100 args = [ prog ]
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
101 args.append('-p')
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
102 args.append(par_file)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
103
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
104 #print "args: ", ' '.join(args)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
105 p = subprocess.Popen(args, bufsize=-1, stdin=None, stdout=subprocess.PIPE, stderr=sys.stderr)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
106 (stdoutdata, stderrdata) = p.communicate()
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
107 rc = p.returncode
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
108
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
109 if rc != 0:
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
110 print >> sys.stderr, "FAILED: rc={0}: {1}".format(rc, ' '.join(args))
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
111 print >> sys.stderr, stderrdata
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
112 sys.exit(1)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
113
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
114 stats = []
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
115
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
116 save_line = False
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
117 for line in stdoutdata.split('\n'):
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
118 if line.startswith(('## Average divergence', '## Anova statistics', '## Statistical significance')):
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
119 stats.append('')
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
120 save_line = True
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
121 if line.strip() == '':
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
122 save_line = False
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
123 if save_line:
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
124 stats.append(line)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
125
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
126 return '\n'.join(stats[1:])
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
127
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
128 def do_ploteig(evec_file, population_names):
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
129 prog = 'gd_ploteig'
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
130
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
131 args = [ prog ]
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
132 args.append('-i')
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
133 args.append(evec_file)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
134 args.append('-c')
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
135 args.append('1:2')
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
136 args.append('-p')
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
137 args.append(':'.join(population_names))
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
138 args.append('-x')
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
139
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
140 run_program(None, args)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
141
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
142 def do_eval2pct(eval_file, explained_file):
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
143 prog = 'eval2pct'
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
144
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
145 args = [ prog ]
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
146 args.append(eval_file)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
147
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
148 with open(explained_file, 'w') as ofh:
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
149 #print "args:", ' '.join(args)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
150 p = subprocess.Popen(args, bufsize=-1, stdin=None, stdout=ofh, stderr=subprocess.PIPE)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
151 (stdoutdata, stderrdata) = p.communicate()
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
152 rc = p.returncode
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
153
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
154 if rc != 0:
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
155 print >> sys.stderr, "FAILED: rc={0}: {1}".format(rc, ' '.join(args))
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
156 print >> sys.stderr, stderrdata
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
157 sys.exit(1)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
158
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
159 def do_coords2admix(coords_file):
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
160 prog = 'coords2admix'
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
161
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
162 args = [ prog ]
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
163 args.append(coords_file)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
164
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
165 with open('fake', 'w') as ofh:
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
166 #print "args:", ' '.join(args)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
167 p = subprocess.Popen(args, bufsize=-1, stdin=None, stdout=ofh, stderr=subprocess.PIPE)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
168 (stdoutdata, stderrdata) = p.communicate()
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
169 rc = p.returncode
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
170
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
171 if rc != 0:
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
172 print >> sys.stderr, "FAILED: rc={0}: {1}".format(rc, ' '.join(args))
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
173 print >> sys.stderr, stderrdata
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
174 sys.exit(1)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
175
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
176 shutil.copy2('fake', coords_file)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
177
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
178 ################################################################################
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
179
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
180 if len(sys.argv) != 5:
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
181 print "usage"
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
182 sys.exit(1)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
183
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
184 input, input_files_path, output, output_files_path = sys.argv[1:5]
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
185
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
186 mkdir_p(output_files_path)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
187
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
188 ped_file = os.path.join(input_files_path, 'admix.ped')
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
189 geno_file = os.path.join(output_files_path, 'admix.geno')
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
190 do_ped2geno(ped_file, geno_file)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
191
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
192 map_file = os.path.join(input_files_path, 'admix.map')
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
193 snp_file = os.path.join(output_files_path, 'admix.snp')
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
194 do_map2snp(map_file, snp_file)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
195
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
196 ind_file = os.path.join(output_files_path, 'admix.ind')
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
197 population_names = make_ind_file(ind_file, input)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
198
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
199 par_file = os.path.join(output_files_path, 'par.admix')
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
200 evec_file = os.path.join(output_files_path, 'coordinates.txt')
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
201 eval_file = os.path.join(output_files_path, 'admix.eval')
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
202 make_par_file(par_file, geno_file, snp_file, ind_file, evec_file, eval_file)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
203
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
204 smartpca_stats = do_smartpca(par_file)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
205
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
206 do_ploteig(evec_file, population_names)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
207 plot_file = 'coordinates.txt.1:2.{0}.pdf'.format(':'.join(population_names))
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
208 output_plot_file = os.path.join(output_files_path, 'PCA.pdf')
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
209 shutil.copy2(plot_file, output_plot_file)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
210 os.unlink(plot_file)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
211
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
212 do_eval2pct(eval_file, os.path.join(output_files_path, 'explained.txt'))
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
213 os.unlink(eval_file)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
214
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
215 do_coords2admix(evec_file)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
216
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
217 ################################################################################
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
218
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
219 info_page = gd_composite.InfoPage()
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
220 info_page.set_title('PCA Galaxy Composite Dataset')
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
221
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
222 display_file = gd_composite.DisplayFile()
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
223 display_value = gd_composite.DisplayValue()
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
224
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
225 out_pdf = gd_composite.Parameter(name='PCA.pdf', value='PCA.pdf', display_type=display_file)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
226 out_evec = gd_composite.Parameter(name='coordinates.txt', value='coordinates.txt', display_type=display_file)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
227 out_explained = gd_composite.Parameter(name='explained.txt', value='explained.txt', display_type=display_file)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
228
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
229 evec_prefix = 'coordinates.txt.1:2.{0}'.format(':'.join(population_names))
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
230 ps_file = '{0}.ps'.format(evec_prefix)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
231 xtxt_file = '{0}.xtxt'.format(evec_prefix)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
232
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
233 os.unlink(os.path.join(output_files_path, ps_file))
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
234 os.unlink(os.path.join(output_files_path, xtxt_file))
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
235
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
236 info_page.add_output_parameter(out_pdf)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
237 info_page.add_output_parameter(out_evec)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
238 info_page.add_output_parameter(out_explained)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
239
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
240 in_admix = gd_composite.Parameter(name='par.admix', value='par.admix', display_type=display_file)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
241 in_geno = gd_composite.Parameter(name='admix.geno', value='admix.geno', display_type=display_file)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
242 in_snp = gd_composite.Parameter(name='admix.snp', value='admix.snp', display_type=display_file)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
243 in_ind = gd_composite.Parameter(name='admix.ind', value='admix.ind', display_type=display_file)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
244
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
245 info_page.add_input_parameter(in_admix)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
246 info_page.add_input_parameter(in_geno)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
247 info_page.add_input_parameter(in_snp)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
248 info_page.add_input_parameter(in_ind)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
249
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
250 misc_stats = gd_composite.Parameter(description='Stats<p/><pre>\n{0}\n</pre>'.format(smartpca_stats), display_type=display_value)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
251
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
252 info_page.add_misc(misc_stats)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
253
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
254 with open (output, 'w') as ofh:
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
255 print >> ofh, info_page.render()
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
256
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
257 sys.exit(0)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
258