[hg] galaxy 3783: Add track definition to bedgraph files generat...
details: http://www.bx.psu.edu/hg/galaxy/rev/e972d3f8413e changeset: 3783:e972d3f8413e user: jeremy goecks <jeremy.goecks@emory.edu> date: Thu May 13 15:35:41 2010 -0400 description: Add track definition to bedgraph files generated by gtf2bedgraph. diffstat: test-data/gtf2bedgraph_out.bedgraph | 2 +- tools/filters/gtf_to_bedgraph_converter.py | 25 ++++++++++++++++--------- 2 files changed, 17 insertions(+), 10 deletions(-) diffs (61 lines): diff -r 0c1cb2c76b84 -r e972d3f8413e test-data/gtf2bedgraph_out.bedgraph --- a/test-data/gtf2bedgraph_out.bedgraph Thu May 13 14:10:37 2010 -0400 +++ b/test-data/gtf2bedgraph_out.bedgraph Thu May 13 15:35:41 2010 -0400 @@ -1,3 +1,4 @@ +track type=bedGraph chr1 36425949 36426026 4.8386844109 chr1 46891971 46892996 8.4688567539 chr1 71654477 71654594 0.4686878995 @@ -98,4 +99,3 @@ chr9 57867099 57867303 0.5359102332 chr9 106815437 106815604 5.4023275754 chr9 119703053 119703292 0.0814657030 -track type=bedGraph diff -r 0c1cb2c76b84 -r e972d3f8413e tools/filters/gtf_to_bedgraph_converter.py --- a/tools/filters/gtf_to_bedgraph_converter.py Thu May 13 14:10:37 2010 -0400 +++ b/tools/filters/gtf_to_bedgraph_converter.py Thu May 13 15:35:41 2010 -0400 @@ -9,16 +9,14 @@ output_name = sys.argv[2] attribute_name = sys.argv[3] - # Create temp file. - tmp_name = tempfile.NamedTemporaryFile().name + # Create temp files. + tmp_name1 = tempfile.NamedTemporaryFile().name + tmp_name2 = tempfile.NamedTemporaryFile().name # Do conversion. skipped_lines = 0 first_skipped_line = 0 - out = open( tmp_name, 'w' ) - - # Write track definition line. - out.write( "track type=bedGraph\n") + out = open( tmp_name1, 'w' ) # Write track data to temporary file. i = 0 @@ -56,11 +54,20 @@ first_skipped_line = i + 1 out.close() - # Sort tmp file to create bedgraph file; sort by chromosome name and chromosome start. - cmd = "sort -k1,1 -k2,2n < %s > %s" % ( tmp_name, output_name ) + # Sort tmp file by chromosome name and chromosome start to create ordered track data. + cmd = "sort -k1,1 -k2,2n < %s > %s" % ( tmp_name1, tmp_name2 ) try: os.system(cmd) - os.remove(tmp_name) + os.remove(tmp_name1) + except Exception, ex: + sys.stderr.write( "%s\n" % ex ) + sys.exit(1) + + # Create bedgraph file by combining track definition with ordered track data. + cmd = "echo 'track type=bedGraph' | cat - %s > %s " % ( tmp_name2, output_name ) + try: + os.system(cmd) + os.remove(tmp_name2) except Exception, ex: sys.stderr.write( "%s\n" % ex ) sys.exit(1)
participants (1)
-
Nate Coraor