7dffb168f2f0b18afc943b273c4d1853a5408bc8
[qpalma.git] / scripts / grid_predict.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 import cPickle
5 import sys
6 import pdb
7 import os
8 import os.path
9 import math
10
11 import pythongrid
12
13 from qpalma_main import *
14
15
16 def get_slices(dataset_size,num_nodes):
17 all_instances = []
18
19 part = dataset_size / num_nodes
20 begin = 0
21 end = 0
22 for idx in range(1,num_nodes+1):
23
24 if idx == num_nodes:
25 begin = end
26 end = dataset_size
27 else:
28 begin = end
29 end = begin+part
30
31 params = (begin,end)
32
33 all_instances.append(params)
34
35 return all_instances
36
37
38 def makeJobs(run,dataset_fn,chunks,param):
39 """
40 """
41
42 jobs=[]
43
44 for current_chunk in chunks:
45 current_job = KybJob(predict,[run,prediction_set,param])
46 current_job.h_vmem = '5.0G'
47 current_job.express = 'True'
48
49 print "job #1: ", j1.nativeSpecification
50
51 jobs.append(j1)
52
53 return jobs
54
55
56 def create_and_submit():
57 """
58
59 """
60
61 jp = os.path.join
62
63 run_dir = '/fml/ag-raetsch/home/fabio/tmp/newest_run/alignment/run_enable_quality_scores_+_enable_splice_signals_+_enable_intron_length_+'
64
65 run = cPickle.load(jp(run_dir,'run_obj.pickle'))
66 param = cPickle.load(jp(run_dir,'param_526.pickle'))
67
68 dataset_fn = ''
69 prediction_keys = ''
70
71 num_splits = 10
72 slices = get_slices(prediction_keys,num_splits)
73 chunks = []
74 for slice in slices:
75 chunks.append(prediction_keys[slice[0]:slice[1]])
76
77
78 functionJobs = makeJobs(run,dataset_fn,chunks,param)
79
80 print "output ret field in each job before sending it onto the cluster"
81 for (i, job) in enumerate(functionJobs):
82 print "Job with id: ", i, "- ret: ", job.ret
83
84 print ""
85 print "sending function jobs to cluster"
86 print ""
87
88 #processedFunctionJobs = processJobs(functionJobs)
89
90 print "ret fields AFTER execution on cluster"
91 for (i, job) in enumerate(processedFunctionJobs):
92 print "Job with id: ", i, "- ret: ", job.ret
93
94
95 def predict(run,prediction_set,param):
96 """
97
98 """
99
100 qp = QPalma()
101 qp.predict(run,dataset_fn,prediction_keys,param):
102
103
104 if __name__ == '__main__':
105 create_and_submit():