-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtasks.py
executable file
·128 lines (106 loc) · 3.64 KB
/
tasks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
from celery import Celery
import datetime
import time
import os
import optparse
import uuid
import urllib2
import multiprocessing
import sff2otu
import ml_pipeline
from Net import Net
import sys
celery = Celery('tasks', broker = 'amqp://wvlab:[email protected]/', backend = 'amqp')
@celery.task(bind=True , name='prepro')
def prepro(self , uniqueJobID , listofSFFfiles, listOfMappingFiles):
print 'Prepro started'
self.update_state(state='RUNNING')
core = max(multiprocessing.cpu_count() - 1, 1)
start_time = unicode(datetime.datetime.now())
pipeline = sff2otu.SFF2OTU(uniqueJobID, listofSFFfiles, listOfMappingFiles)
result = pipeline.run(processors = core, qtrim = 'F')
finish_time = unicode(datetime.datetime.now())
return {'funct': os.path.abspath(result['txt']), 'st': start_time, 'ft': finish_time}
@celery.task(bind=True , name='ml')
def mlearn(self , job_id, otu_file, class_file, *args, **kwargs):
print 'Classification started'
print self.request.id
self.update_state(state='RUNNING')
start_time = unicode(datetime.datetime.now())
pipeline = ml_pipeline.ML(job_id, otu_file, class_file)
result = pipeline.run(*args, **kwargs)
for key in result:
result[key] = os.path.abspath(result[key])
finish_time = unicode(datetime.datetime.now())
return {'funct': result , 'st': start_time, 'ft': finish_time}
@celery.task(bind=True, name="network_task")
def network_task(self, **kwargs):
"""
Execute Davide Leonessi and Stefano Valentini network
analysis.
args:
*fileData*
(str)
The filesystem path of the `data.txt' file.
*fileLabel*
(str)
The filesystem path of the `label.txt' file.
*fileSamples*
(str)
The filesystem path of the `samples.txt' file.
*fileFeature*
(str)
The filesystem path of the `feature.txt' file.
*fileRank*
(str)
The filesystem path of the `rank.txt' file.
*fileMetrics*
(str)
The filesystem path of the `metrics.txt' file.
*outDir*
(str)
The filesystem path of the directory where store
the output files.
*Numerical Parameter*
float
"""
# keys mandatory in kwargs
path_keys = ['fileData', 'fileLabel', 'fileSamples', 'fileFeature',
'fileRank', 'fileMetrics', 'outDir' , 'numPar']
file_keys = path_keys[:-2]
dir_keys = path_keys[-1]
# check if i get all the args
for key in path_keys:
if key not in kwargs:
e = "Missing path argument `{0}'".format(key)
return NameError(e)
# check paths
for key in file_keys:
path = kwargs[key]
if not os.path.isfile(path):
e = "File not found: {0}".format(path)
return IOError(e)
for d in dir_keys:
if not os.path.isdir(d):
try:
os.makedirs(d)
except Exception, e:
msg = "Error while crating `{0}'. Details: {1}".format(d, e)
return Exception(msg)
# build args list and get instance
args = [kwargs[arg] for arg in path_keys]
# start task
print "Starting celery network task ..."
print self.request.id
#try:
self.update_state(state='RUNNING')
start_time = unicode(datetime.datetime.now())
netAnalysis = Net(*args)
result = netAnalysis.run()
finish_time = unicode(datetime.datetime.now())
return {'result' : result, 'st': start_time, 'ft': finish_time}
#except Exception, e:
# msg = "Error while executing Network Analysis. "
# msg+= "Details: {0}".format(e)
# return Exception(e)
#