/tools/maf/maf_to_bed_code.py

https://bitbucket.org/h_morita_dbcls/galaxy-central · Python · 59 lines · 58 code · 1 blank · 0 comment · 8 complexity · ea994634e481a618c58d30c058bf67d3 MD5 · raw file

  1. import pkg_resources; pkg_resources.require( "bx-python" )
  2. from bx.align import maf
  3. from galaxy import datatypes, config, jobs
  4. from shutil import move
  5. def exec_after_process(app, inp_data, out_data, param_dict, tool, stdout, stderr):
  6. output_data = out_data.items()[0][1]
  7. history = output_data.history
  8. if history == None:
  9. print "unknown history!"
  10. return
  11. new_stdout = ""
  12. split_stdout = stdout.split("\n")
  13. basic_name = output_data.name
  14. output_data_list = []
  15. for line in split_stdout:
  16. if line.startswith("#FILE1"):
  17. fields = line.split("\t")
  18. dbkey = fields[1]
  19. filepath = fields[2]
  20. output_data.dbkey = dbkey
  21. output_data.name = basic_name + " (" + dbkey + ")"
  22. app.model.context.add( output_data )
  23. app.model.context.flush()
  24. output_data_list.append(output_data)
  25. elif line.startswith("#FILE"):
  26. fields = line.split("\t")
  27. dbkey = fields[1]
  28. filepath = fields[2]
  29. newdata = app.model.HistoryDatasetAssociation( create_dataset = True, sa_session = app.model.context )
  30. newdata.set_size()
  31. newdata.extension = "bed"
  32. newdata.name = basic_name + " (" + dbkey + ")"
  33. app.model.context.add( newdata )
  34. app.model.context.flush()
  35. history.add_dataset( newdata )
  36. app.security_agent.copy_dataset_permissions( output_data.dataset, newdata.dataset )
  37. app.model.context.add( history )
  38. app.model.context.flush()
  39. try:
  40. move(filepath,newdata.file_name)
  41. newdata.info = newdata.name
  42. newdata.state = newdata.states.OK
  43. except:
  44. newdata.info = "The requested file is missing from the system."
  45. newdata.state = newdata.states.ERROR
  46. newdata.dbkey = dbkey
  47. newdata.init_meta()
  48. newdata.set_meta()
  49. newdata.set_peek()
  50. app.model.context.flush()
  51. output_data_list.append(newdata)
  52. else:
  53. new_stdout = new_stdout + line
  54. for data in output_data_list:
  55. if data.state == data.states.OK:
  56. data.info = new_stdout
  57. app.model.context.add( data )
  58. app.model.context.flush()