PageRenderTime 47ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/scripts/gimme_motifs.py

https://github.com/astatham/gimmemotifs
Python | 83 lines | 64 code | 13 blank | 6 comment | 13 complexity | fc83dc445ff793a9d7153b406666b079 MD5 | raw file
  1. #!/usr/bin/env python
  2. # Copyright (c) 2009-2010 Simon van Heeringen <s.vanheeringen@ncmls.ru.nl>
  3. #
  4. # This module is free software. You can redistribute it and/or modify it under
  5. # the terms of the MIT License, see the file COPYING included with this
  6. # distribution.
  7. from optparse import OptionParser
  8. from gimmemotifs.core import *
  9. from gimmemotifs.config import *
  10. VERSION = "0.50"
  11. config = MotifConfig()
  12. params = config.get_default_params()
  13. parser = OptionParser(version="%prog " + VERSION)
  14. parser.add_option("-i", "--inputfile", dest="inputfile", help="Inputfile in bed format", metavar="FILE")
  15. parser.add_option("-k", "--keepintermediate", dest="keep_intermediate", help="Don't delete intermediate files", default=False, action="store_true")
  16. parser.add_option("-n", "--name", dest="name", help="Give your analysis a name", metavar="NAME")
  17. parser.add_option("-a", "--analysis",dest="analysis", help="Analysis type: small, medium, large, xl (%s)" % params["analysis"], metavar="ANALYSIS", default=params["analysis"])
  18. parser.add_option("-g", "--genome", dest="genome", help="Genome version (%s)" % (params["genome"]), metavar="VERSION", default=params["genome"])
  19. parser.add_option("-s", "--singlestrand", dest="single", help="Only predict motifs for single + strand (default is both)", action="store_true", default=False)
  20. parser.add_option("-f", "--fraction", dest="fraction", help="Fraction of peaks to use for motif predicton (%s)" % params["fraction"], metavar="FRACTION", default=params["fraction"], type=float)
  21. parser.add_option("-w", "--width", dest="width", help="Width to use for motif prediction (%s)" % params["width"], metavar="N", default=params["width"], type=int)
  22. parser.add_option("-e", "--enrichment", dest="enrichment", help="Motif significance: enrichment cutoff (>%s)" % params["enrichment"], metavar="N", default=params["enrichment"], type=float)
  23. parser.add_option("-p", "--pvalue", dest="pvalue", help="Motif significance: p-value cutoff (<%s)" % params["pvalue"], metavar="N", default=params["pvalue"], type=float)
  24. parser.add_option("-b", "--background", dest="background", help="Background to determine significance genomic_matched,random (%s)" % params["background"], metavar="N", default=params["background"])
  25. parser.add_option("-l", "--localization_width", dest="lwidth", help="Width to use for motif localization graphs (%s)" % params["lwidth"], metavar="N", default=params["lwidth"], type=int)
  26. parser.add_option("-t", "--tools", dest="tools", help="Tools to use, any combination of %s (default %s)" % (params["available_tools"], params["tools"]), metavar="N", default=params["tools"])
  27. parser.add_option("-x", dest="weird_option", help="Do NOT use this!", default=False, action="store_true")
  28. (options, args) = parser.parse_args()
  29. if not options.inputfile:
  30. parser.print_help()
  31. sys.exit()
  32. if not os.path.exists(options.inputfile):
  33. print "File %s does not exist!" % options.inputfile
  34. sys.exit()
  35. background = [x.strip() for x in options.background.split(",")]
  36. for bg in background:
  37. if not bg in ["genomic", "random", "genomic_matched"]:
  38. print "Invalid value for background argument"
  39. sys.exit()
  40. if options.lwidth < options.width:
  41. sys.stderr.write("Warning: localization width is smaller than motif prediction width!")
  42. available_tools = [t.strip() for t in params["available_tools"].split(",")]
  43. tools = dict([(t,0) for t in available_tools])
  44. for t in options.tools.split(","):
  45. tools[t.strip()] = 1
  46. for tool in tools.keys():
  47. if tool not in available_tools:
  48. print "Sorry, motif prediction tool %s is not supported" % (tool)
  49. sys.exit()
  50. if "matched_genomic" in background:
  51. gene_file = os.path.join(config.get_gene_dir(), options.genome)
  52. if not os.path.exists(gene_file):
  53. print "Sorry, genomic background for %s is not supported!" % options.genome
  54. sys.exit()
  55. params = {
  56. "genome": options.genome,
  57. "width": options.width,
  58. "lwidth": options.lwidth,
  59. "tools": options.tools,
  60. "analysis": options.analysis,
  61. "pvalue": options.pvalue,
  62. "background": options.background,
  63. "enrichment": options.enrichment,
  64. "fraction": options.fraction,
  65. "use_strand": options.single,
  66. "keep_intermediate": options.keep_intermediate,
  67. "weird_option": options.weird_option
  68. }
  69. gm = GimmeMotifs(options.name)
  70. gm.run_full_analysis(options.inputfile, params)