/usr/share/pyshared/MACS2/OptValidator.py is in macs 2.0.9.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 | # Time-stamp: <2011-11-02 14:21:20 Tao Liu>
"""Module Description
Copyright (c) 2010,2011 Tao Liu <taoliu@jimmy.harvard.edu>
This code is free software; you can redistribute it and/or modify it
under the terms of the BSD License (see the file COPYING included with
the distribution).
@status: experimental
@version: $Revision$
@author: Tao Liu
@contact: taoliu@jimmy.harvard.edu
"""
# ------------------------------------
# python modules
# ------------------------------------
import sys
import os
import re
import logging
from subprocess import Popen, PIPE
from math import log
from MACS2.IO.cParser import BEDParser, ELANDResultParser, ELANDMultiParser, ELANDExportParser, SAMParser, BAMParser, BowtieParser, guess_parser
# ------------------------------------
# constants
# ------------------------------------
efgsize = {"hs":2.7e9,
"mm":1.87e9,
"ce":9e7,
"dm":1.2e8}
# ------------------------------------
# Misc functions
# ------------------------------------
def opt_validate ( optparser ):
"""Validate options from a OptParser object.
Ret: Validated options object.
"""
(options,args) = optparser.parse_args()
# gsize
try:
options.gsize = efgsize[options.gsize]
except:
try:
options.gsize = float(options.gsize)
except:
logging.error("Error when interpreting --gsize option: %s" % options.gsize)
logging.error("Available shortcuts of effective genome sizes are %s" % ",".join(efgsize.keys()))
sys.exit(1)
# treatment file
if not options.tfile: # only required argument
optparser.print_help()
sys.exit(1)
# format
options.gzip_flag = False # if the input is gzip file
options.format = options.format.upper()
if options.format == "ELAND":
options.parser = ELANDResultParser
elif options.format == "BED":
options.parser = BEDParser
elif options.format == "ELANDMULTI":
options.parser = ELANDMultiParser
elif options.format == "ELANDEXPORT":
options.parser = ELANDExportParser
elif options.format == "SAM":
options.parser = SAMParser
elif options.format == "BAM":
options.parser = BAMParser
options.gzip_flag = True
elif options.format == "BOWTIE":
options.parser = BowtieParser
elif options.format == "AUTO":
options.parser = guess_parser
else:
logging.error("Format \"%s\" cannot be recognized!" % (options.format))
sys.exit(1)
# duplicate reads
if options.keepduplicates != "auto" and options.keepduplicates != "all":
if not options.keepduplicates.isdigit():
logging.error("--keep-dup should be 'auto', 'all' or an integer!")
sys.exit(1)
# shiftsize>0
if options.shiftsize <=0 :
logging.error("--shiftsize must > 0!")
sys.exit(1)
if options.pvalue:
# if set, ignore qvalue cutoff
options.log_qvalue = None
options.log_pvalue = log(options.pvalue,10)*-1
else:
options.log_qvalue = log(options.qvalue,10)*-1
options.log_pvalue = None
if options.broad:
options.log_broadcutoff = log(options.broadcutoff,10)*-1
# uppercase the format string
options.format = options.format.upper()
# upper and lower mfold
try:
(options.lmfold,options.umfold) = map(int, options.mfold.split(","))
except:
logging.error("mfold format error! Your input is '%s'. It should be like '10,30'." % options.mfold)
sys.exit(1)
# output filenames
options.peakxls = options.name+"_peaks.xls"
options.peakbed = options.name+"_peaks.bed"
options.peakNarrowPeak = options.name+"_peaks.encodePeak"
options.peakBroadPeak = options.name+"_broad_peaks.bed"
options.summitbed = options.name+"_summits.bed"
options.zwig_tr = options.name+"_treat"
options.zwig_ctl= options.name+"_control"
#options.negxls = options.name+"_negative_peaks.xls"
#options.diagxls = options.name+"_diag.xls"
options.modelR = options.name+"_model.r"
options.pqtable = options.name+"_pq_table.txt"
# logging object
logging.basicConfig(level=(4-options.verbose)*10,
format='%(levelname)-5s @ %(asctime)s: %(message)s ',
datefmt='%a, %d %b %Y %H:%M:%S',
stream=sys.stderr,
filemode="w"
)
options.error = logging.critical # function alias
options.warn = logging.warning
options.debug = logging.debug
options.info = logging.info
options.argtxt = "\n".join((
"# ARGUMENTS LIST:",\
"# name = %s" % (options.name),\
"# format = %s" % (options.format),\
"# ChIP-seq file = %s" % (options.tfile),\
"# control file = %s" % (options.cfile),\
"# effective genome size = %.2e" % (options.gsize),\
#"# tag size = %d" % (options.tsize),\
"# band width = %d" % (options.bw),\
"# model fold = %s\n" % (options.mfold),\
))
if options.pvalue:
options.argtxt += "# pvalue cutoff = %.2e\n" % (options.pvalue)
else:
options.argtxt += "# qvalue cutoff = %.2e\n" % (options.qvalue)
if options.downsample:
options.argtxt += "# Larger dataset will be randomly sampled towards smaller dataset.\n"
else:
if options.tolarge:
options.argtxt += "# Smaller dataset will be scaled towards larger dataset.\n"
else:
options.argtxt += "# Larger dataset will be scaled towards smaller dataset.\n"
if options.cfile:
options.argtxt += "# Range for calculating regional lambda is: %d bps and %d bps\n" % (options.smalllocal,options.largelocal)
else:
options.argtxt += "# Range for calculating regional lambda is: %d bps\n" % (options.largelocal)
if options.broad:
options.argtxt += "# Broad region calling is on\n"
else:
options.argtxt += "# Broad region calling is off\n"
if options.halfext:
options.argtxt += "# MACS will make 1/2d size fragments\n"
return options
def opt_validate_diff ( optparser ):
"""Validate options from a OptParser object.
This parser is for macsdiffrun.
Ret: Validated options object.
"""
(options,args) = optparser.parse_args()
# gsize
try:
options.gsize = efgsize[options.gsize]
except:
try:
options.gsize = float(options.gsize)
except:
logging.error("Error when interpreting --gsize option: %s" % options.gsize)
logging.error("Available shortcuts of effective genome sizes are %s" % ",".join(efgsize.keys()))
sys.exit(1)
# treatment file
if not options.tfile1 or not options.tfile2: # only required argument
logging.error("--t1 and --t2 are required!")
optparser.print_help()
sys.exit(1)
# control file
if not options.cfile1 and not options.cfile2:
logging.error("At least, either --c1 or --c2 should be set!")
optparser.print_help()
sys.exit(1)
if not options.cfile1 and options.cfile2:
options.cfile1 = options.cfile2
elif options.cfile1 and not options.cfile2:
options.cfile2 = options.cfile1
# Check file assessibility.
flag = True
for fn in (options.tfile1, options.tfile2, options.cfile1, options.cfile2):
if os.path.isfile(fn):
pass
else:
logging.error("Can't access file: %s" % fn)
flag = False
if not flag:
sys.exit(1)
# format
options.gzip_flag = False # if the input is gzip file
options.format = options.format.upper()
if options.format == "ELAND":
options.parser = ELANDResultParser
elif options.format == "BED":
options.parser = BEDParser
elif options.format == "ELANDMULTI":
options.parser = ELANDMultiParser
elif options.format == "ELANDEXPORT":
options.parser = ELANDExportParser
elif options.format == "SAM":
options.parser = SAMParser
elif options.format == "BAM":
options.parser = BAMParser
options.gzip_flag = True
elif options.format == "BOWTIE":
options.parser = BowtieParser
elif options.format == "AUTO":
options.parser = guess_parser
else:
logging.error("Format \"%s\" cannot be recognized!" % (options.format))
sys.exit(1)
# duplicate reads
if options.keepduplicates != "auto" and options.keepduplicates != "all":
if not options.keepduplicates.isdigit():
logging.error("--keep-dup should be 'auto', 'all' or an integer!")
sys.exit(1)
# shiftsize>0
if options.shiftsize <=0 :
logging.error("--shiftsize must > 0!")
sys.exit(1)
if options.pvalue:
# if set, ignore qvalue cutoff
options.log_qvalue = None
options.log_pvalue = log(options.pvalue,10)*-1
else:
options.log_qvalue = log(options.qvalue,10)*-1
options.log_pvalue = None
# uppercase the format string
options.format = options.format.upper()
# upper and lower mfold
try:
(options.lmfold,options.umfold) = map(int, options.mfold.split(","))
except:
logging.error("mfold format error! Your input is '%s'. It should be like '10,30'." % options.mfold)
sys.exit(1)
# output filenames
options.condition1_peakbed = options.name+"_condition1_unique_peaks.bed"
options.condition2_peakbed = options.name+"_condition2_unique_peaks.bed"
options.consistent_peakbed = options.name+"_consistent_peaks.bed"
options.zbdg_tr = options.name+"_treat"
options.zbdg_ctl= options.name+"_control"
# logging object
logging.basicConfig(level=(4-options.verbose)*10,
format='%(levelname)-5s @ %(asctime)s: %(message)s ',
datefmt='%a, %d %b %Y %H:%M:%S',
stream=sys.stderr,
filemode="w"
)
options.error = logging.critical # function alias
options.warn = logging.warning
options.debug = logging.debug
options.info = logging.info
options.argtxt = "\n".join((
"# ARGUMENTS LIST:",\
"# name = %s" % (options.name),\
"# format = %s" % (options.format),\
"# ChIP-seq file for condition 1 = %s" % (options.tfile1),\
"# ChIP-seq file for condition 2 = %s" % (options.tfile2),\
"# control file for condition 1 = %s" % (options.cfile1),\
"# control file for condition 2 = %s" % (options.cfile2),\
"# effective genome size = %.2e" % (options.gsize),\
"# band width = %d" % (options.bw),\
"# model fold = %s\n" % (options.mfold),\
))
if options.pvalue:
options.argtxt += "# pvalue cutoff = %.2e\n" % (options.pvalue)
else:
options.argtxt += "# qvalue cutoff = %.2e\n" % (options.qvalue)
# if options.tolarge:
# options.argtxt += "# Smaller dataset will be scaled towards larger dataset.\n"
# else:
# options.argtxt += "# Larger dataset will be scaled towards smaller dataset.\n"
if options.cfile1 or options.cfile2:
options.argtxt += "# Range for calculating regional lambda is: %d bps and %d bps\n" % (options.smalllocal,options.largelocal)
else:
options.argtxt += "# Range for calculating regional lambda is: %d bps\n" % (options.largelocal)
return options
def opt_validate_filterdup ( optparser ):
"""Validate options from a OptParser object.
Ret: Validated options object.
"""
(options,args) = optparser.parse_args()
# gsize
try:
options.gsize = efgsize[options.gsize]
except:
try:
options.gsize = float(options.gsize)
except:
logging.error("Error when interpreting --gsize option: %s" % options.gsize)
logging.error("Available shortcuts of effective genome sizes are %s" % ",".join(efgsize.keys()))
sys.exit(1)
# treatment file
if not options.tfile: # only required argument
optparser.print_help()
sys.exit(1)
# format
options.gzip_flag = False # if the input is gzip file
options.format = options.format.upper()
if options.format == "ELAND":
options.parser = ELANDResultParser
elif options.format == "BED":
options.parser = BEDParser
elif options.format == "ELANDMULTI":
options.parser = ELANDMultiParser
elif options.format == "ELANDEXPORT":
options.parser = ELANDExportParser
elif options.format == "SAM":
options.parser = SAMParser
elif options.format == "BAM":
options.parser = BAMParser
options.gzip_flag = True
elif options.format == "BOWTIE":
options.parser = BowtieParser
elif options.format == "AUTO":
options.parser = guess_parser
else:
logging.error("Format \"%s\" cannot be recognized!" % (options.format))
sys.exit(1)
# duplicate reads
if options.keepduplicates != "auto" and options.keepduplicates != "all":
if not options.keepduplicates.isdigit():
logging.error("--keep-dup should be 'auto', 'all' or an integer!")
sys.exit(1)
# uppercase the format string
options.format = options.format.upper()
# logging object
logging.basicConfig(level=(4-options.verbose)*10,
format='%(levelname)-5s @ %(asctime)s: %(message)s ',
datefmt='%a, %d %b %Y %H:%M:%S',
stream=sys.stderr,
filemode="w"
)
options.error = logging.critical # function alias
options.warn = logging.warning
options.debug = logging.debug
options.info = logging.info
return options
def opt_validate_randsample ( optparser ):
"""Validate options from a OptParser object.
Ret: Validated options object.
"""
(options,args) = optparser.parse_args()
# treatment file
if not options.tfile: # only required argument
optparser.print_help()
sys.exit(1)
# format
options.gzip_flag = False # if the input is gzip file
options.format = options.format.upper()
if options.format == "ELAND":
options.parser = ELANDResultParser
elif options.format == "BED":
options.parser = BEDParser
elif options.format == "ELANDMULTI":
options.parser = ELANDMultiParser
elif options.format == "ELANDEXPORT":
options.parser = ELANDExportParser
elif options.format == "SAM":
options.parser = SAMParser
elif options.format == "BAM":
options.parser = BAMParser
options.gzip_flag = True
elif options.format == "BOWTIE":
options.parser = BowtieParser
elif options.format == "AUTO":
options.parser = guess_parser
else:
logging.error("Format \"%s\" cannot be recognized!" % (options.format))
sys.exit(1)
# uppercase the format string
options.format = options.format.upper()
# percentage or number
if options.percentage and options.number:
logging.error("Can't specify -p and -n at the same time! Please check your options and retry!")
sys.exit(1)
else:
if options.percentage:
if options.percentage > 100.0:
logging.error("Percentage can't be bigger than 100.0. Please check your options and retry!")
sys.exit(1)
elif options.number:
if options.number <= 0:
logging.error("Number of tags can't be smaller than or equal to 0. Please check your options and retry!")
sys.exit(1)
# logging object
logging.basicConfig(level=(4-options.verbose)*10,
format='%(levelname)-5s @ %(asctime)s: %(message)s ',
datefmt='%a, %d %b %Y %H:%M:%S',
stream=sys.stderr,
filemode="w"
)
options.error = logging.critical # function alias
options.warn = logging.warning
options.debug = logging.debug
options.info = logging.info
return options
|