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