annotate tools/maf/maf_to_bed_code.py @ 2:c2a356708570

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