1 | from galaxy import app |
---|
2 | import galaxy.util,string,os,glob,time |
---|
3 | |
---|
4 | librepos = '/usr/local/galaxy/data/rg/library' |
---|
5 | myrepos = '/home/rerla/galaxy' |
---|
6 | |
---|
7 | |
---|
8 | #Provides Upload tool with access to list of available builds |
---|
9 | |
---|
10 | builds = [] |
---|
11 | #Read build names and keys from galaxy.util |
---|
12 | for dbkey, build_name in galaxy.util.dbnames: |
---|
13 | builds.append((build_name,dbkey,False)) |
---|
14 | |
---|
15 | def timenow(): |
---|
16 | """return current time as a string |
---|
17 | """ |
---|
18 | return time.strftime('%d/%m/%Y %H:%M:%S', time.localtime(time.time())) |
---|
19 | |
---|
20 | #Return available builds |
---|
21 | def get_available_builds(defval='hg18'): |
---|
22 | for i,x in enumerate(builds): |
---|
23 | if x[1] == defval: |
---|
24 | x = list(x) |
---|
25 | x[2] = True |
---|
26 | builds[i] = tuple(x) |
---|
27 | return builds |
---|
28 | |
---|
29 | #return available datasets for build |
---|
30 | def get_available_data( file_type_dir, build='hg18' ): |
---|
31 | #we need to allow switching of builds, and properly set in post run hook |
---|
32 | import_files = [('Use the History file chosen below','',True),] |
---|
33 | flist = glob.glob(os.path.join(librepos,file_type_dir,'*.ped')) |
---|
34 | maplist = glob.glob(os.path.join(librepos,file_type_dir,'*.map')) |
---|
35 | maplist = [os.path.splitext(x)[0] for x in maplist] # get unique filenames |
---|
36 | mapdict = dict(zip(maplist,maplist)) |
---|
37 | flist = [os.path.splitext(x)[0] for x in flist] # get unique filenames |
---|
38 | flist = list(set(flist)) # remove dupes |
---|
39 | flist = [x for x in flist if mapdict.get(x,None)] |
---|
40 | flist.sort() |
---|
41 | for i, data in enumerate( flist ): |
---|
42 | #import_files.append( (os.path.split(data)[-1], os.path.split(data)[-1], False) ) |
---|
43 | import_files.append((data,data, False) ) |
---|
44 | if len(import_files) < 1: |
---|
45 | import_files = [('No %s data available - please choose a History file below' |
---|
46 | % file_type_dir,'',True),] |
---|
47 | return import_files |
---|
48 | |
---|
49 | def get_available_outexts(uid): |
---|
50 | userId = uid |
---|
51 | print 'userId=',userId |
---|
52 | flib = os.path.join(librepos,userId,'fped') |
---|
53 | plib = os.path.join(librepos,userId,'lped') |
---|
54 | e = [('Fbat style (header row has marker names)',flib,False),('Linkage style (separate .map file)',plib,True)] |
---|
55 | return e |
---|
56 | |
---|
57 | def getcols(fname="/usr/local/galaxy/data/camp2007/camp2007.xls"): |
---|
58 | """return column names other than chr offset as a select list""" |
---|
59 | head = open(fname,'r').next() |
---|
60 | c = head.strip().split() |
---|
61 | res = [(cname,'%d' % n,False) for n,cname in enumerate(c)] |
---|
62 | for i in range(4): |
---|
63 | x,y,z = res[i] |
---|
64 | res[i] = (x,y,True) # set first couple as selected |
---|
65 | return res |
---|
66 | |
---|
67 | |
---|
68 | def exec_after_process(app, inp_data, out_data, param_dict, tool, stdout, stderr): |
---|
69 | """Sets the name of the html output file - that's all we need |
---|
70 | for a html file result set |
---|
71 | """ |
---|
72 | ts = '%s%s' % (string.punctuation,string.whitespace) |
---|
73 | ptran = string.maketrans(ts,'_'*len(ts)) |
---|
74 | job_name = param_dict.get( 'title', 'LD_Plot' ) |
---|
75 | job_name = job_name.encode().translate(ptran) |
---|
76 | ofname = 'out_file1' |
---|
77 | data = out_data[ofname] |
---|
78 | newname = job_name |
---|
79 | data.name = '%s.html' % newname |
---|
80 | info = '%s created by rgHaploView at %s' % (job_name,timenow()) |
---|
81 | out_data[ofname] = data |
---|
82 | app.model.context.flush() |
---|
83 | |
---|
84 | |
---|