/tools/rgenetics/rgGRR_code.py

https://bitbucket.org/h_morita_dbcls/galaxy-central · Python · 37 lines · 31 code · 2 blank · 4 comment · 3 complexity · 8ef80cf450578576021dc0ed954fc054 MD5 · raw file

  1. from galaxy import datatypes,model
  2. import sys,time,string,os,shutil
  3. def timenow():
  4. """return current time as a string
  5. """
  6. return time.strftime('%d/%m/%Y %H:%M:%S', time.localtime(time.time()))
  7. def exec_after_process(app, inp_data, out_data, param_dict, tool, stdout, stderr):
  8. """Sets the name of the html output file
  9. """
  10. killme = string.punctuation + string.whitespace
  11. trantab = string.maketrans(killme,'_'*len(killme))
  12. job_name = param_dict.get( 'title1', 'rgGRR' )
  13. job_name = job_name.encode()
  14. newname = '%s.html' % job_name.translate(trantab)
  15. indatname = inp_data['i'].name
  16. info = '%s Mean allele sharing on %s at %s' % (job_name,indatname,timenow())
  17. ofname = 'out_file1'
  18. data = out_data[ofname]
  19. data.name = newname
  20. data.info = info
  21. out_data[ofname] = data
  22. fromdir = data.extra_files_path
  23. indat = inp_data['i']
  24. indatname = indat.name
  25. base_name = indat.metadata.base_name
  26. todir = indat.extra_files_path # where the ldreduced stuff should be
  27. ldfname = '%s_INDEP_THIN' % base_name # we store ld reduced and thinned data
  28. ldout = os.path.join(todir,ldfname)
  29. ldin = os.path.join(fromdir,ldfname)
  30. if os.path.exists('%s.bed' % ldin) and not os.path.exists('%s.bed' % ldout): # copy ldreduced to input for next time
  31. for ext in ['bim','bed','fam']:
  32. src = '%s.%s' % (ldin,ext)
  33. dest = '%s.%s' % (ldout,ext)
  34. shutil.copy(src,dest)
  35. app.model.context.flush()