/tools/rgenetics/rgManQQ_code.py

https://bitbucket.org/cistrome/cistrome-harvard/ · Python · 50 lines · 36 code · 7 blank · 7 comment · 6 complexity · 30ab84a51b773b7b4e4221176cb5a7f7 MD5 · raw file

  1. from galaxy import datatypes,model
  2. import sys,string,time
  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 get_phecols(i,addNone,hint):
  8. """
  9. return a list of phenotype columns for a multi-select list
  10. """
  11. hint = hint.lower()
  12. fname = i.dataset.file_name
  13. try:
  14. f = open(fname,'r')
  15. except:
  16. return [('get_phecols unable to open file "%s"' % fname,'None',False),]
  17. header = f.next()
  18. h = header.strip().split()
  19. dat = [(x,'%d' % i,False) for i,x in enumerate(h)]
  20. matches = [i for i,x in enumerate(h) if x.lower().find(hint) <> -1]
  21. if len(matches) > 0:
  22. sel = matches[0]
  23. dat[sel] = (dat[sel][0],dat[sel][1],True)
  24. if addNone:
  25. dat.insert(0,('None - no Manhattan plot','0', False ))
  26. return dat
  27. def exec_after_process(app, inp_data, out_data, param_dict, tool, stdout, stderr):
  28. """Sets the name of the data
  29. <outputs>
  30. <data format="pdf" name="allqq" />
  31. <data format="pdf" name="lowqq" parent="allqq"/>
  32. </outputs>
  33. """
  34. outfile = 'out_html'
  35. job_name = param_dict.get( 'name', 'Manhattan QQ plots' )
  36. killme = string.punctuation + string.whitespace
  37. trantab = string.maketrans(killme,'_'*len(killme))
  38. newname = '%s.html' % job_name.translate(trantab)
  39. data = out_data[outfile]
  40. data.name = newname
  41. data.info='%s run at %s' % (job_name,timenow())
  42. out_data[outfile] = data
  43. app.model.context.flush()