comparison macs21_wrapper.py @ 8:78c15c0a96ae draft

Uploaded new version with minor fixes and updates to help text.
author pjbriggs
date Tue, 21 Apr 2015 10:33:52 -0400
parents 0c6b14f3fefc
children 4e85d68a2347
comparison
equal deleted inserted replaced
7:0c6b14f3fefc 8:78c15c0a96ae
78 chrom_sizes = os.path.basename(chrom_sizes) 78 chrom_sizes = os.path.basename(chrom_sizes)
79 genome_build = chrom_sizes.split('.')[0] 79 genome_build = chrom_sizes.split('.')[0]
80 if genome_build == '?': 80 if genome_build == '?':
81 # No genome build set 81 # No genome build set
82 sys.stderr.write("ERROR genome build not set, cannot get sizes for '?'\n") 82 sys.stderr.write("ERROR genome build not set, cannot get sizes for '?'\n")
83 sys.stderr.write("Assign a genome build to your input dataset and rerun\n")
83 sys.exit(1) 84 sys.exit(1)
84 print "Missing chrom sizes file, attempting to fetch for '%s'" % genome_build 85 print "Missing chrom sizes file, attempting to fetch for '%s'" % genome_build
85 # Run fetchChromSizes 86 # Run fetchChromSizes
86 chrom_sizes = os.path.join(working_dir,chrom_sizes) 87 chrom_sizes = os.path.join(working_dir,chrom_sizes)
87 stderr_file = os.path.join(working_dir,"fetchChromSizes.stderr") 88 stderr_file = os.path.join(working_dir,"fetchChromSizes.stderr")
92 stderr=open(stderr_file,'wb')) 93 stderr=open(stderr_file,'wb'))
93 proc.wait() 94 proc.wait()
94 # Copy stderr from fetchChromSizes for information only 95 # Copy stderr from fetchChromSizes for information only
95 for line in open(stderr_file,'r'): 96 for line in open(stderr_file,'r'):
96 print line.strip() 97 print line.strip()
98 os.remove(stderr_file)
97 # Check that the sizes file was downloaded 99 # Check that the sizes file was downloaded
98 if not os.path.exists(chrom_sizes): 100 if not os.path.exists(chrom_sizes):
99 sys.stderr.write("Failed to download chrom sizes for '%s'" % genome_build) 101 sys.stderr.write("Failed to download chrom sizes for '%s'\n" % genome_build)
100 sys.exit(1) 102 sys.exit(1)
101 # Run bedClip 103 # Run bedClip
102 treat_clipped = "%s.clipped" % os.path.basename(bedgraph_file) 104 treat_clipped = "%s.clipped" % os.path.basename(bedgraph_file)
103 cmd = "bedClip %s %s %s" % (bedgraph_file,chrom_sizes,treat_clipped) 105 cmd = "bedClip %s %s %s" % (bedgraph_file,chrom_sizes,treat_clipped)
104 print "Running %s" % cmd 106 print "Running %s" % cmd
105 proc = subprocess.Popen(args=cmd,shell=True,cwd=working_dir) 107 proc = subprocess.Popen(args=cmd,shell=True,cwd=working_dir)
106 proc.wait() 108 proc.wait()
107 # Check that clipped file exists 109 # Check that clipped file exists
108 treat_clipped = os.path.join(working_dir,treat_clipped) 110 treat_clipped = os.path.join(working_dir,treat_clipped)
109 if not os.path.exists(treat_clipped): 111 if not os.path.exists(treat_clipped):
110 sys.stderr.write("Failed to create clipped bed file") 112 sys.stderr.write("Failed to create clipped bed file\n")
111 sys.exit(1) 113 sys.exit(1)
112 # Run bedGraphToBigWig 114 # Run bedGraphToBigWig
113 cmd = "bedGraphToBigWig %s %s %s" % (treat_clipped,chrom_sizes, 115 cmd = "bedGraphToBigWig %s %s %s" % (treat_clipped,chrom_sizes,
114 bigwig_file) 116 bigwig_file)
115 print "Running %s" % cmd 117 print "Running %s" % cmd
116 proc = subprocess.Popen(args=cmd,shell=True,cwd=working_dir) 118 proc = subprocess.Popen(args=cmd,shell=True,cwd=working_dir)
117 proc.wait() 119 proc.wait()
120 # Clean up temporary chrom length file
121 if os.path.dirname(chrom_sizes) == working_dir:
122 print "Removing temporary chrom sizes file"
123 os.remove(chrom_sizes)
118 124
119 if __name__ == "__main__": 125 if __name__ == "__main__":
120 126
121 # Echo the command line 127 # Echo the command line
122 print ' '.join(sys.argv) 128 print ' '.join(sys.argv)