Davide Cittaro avatar Davide Cittaro committed 8dbf29b

initial work on input functions

Comments (0)

Files changed (4)

 import sys
 import argparse
 
-_version = '0.0.1'
+from dsptools.actions import *
+from dsptools.misc import *
+
+_version = "0.0.1"
+
+def check_options(args):
+  if args.predicate == "pileup":
+    if args.file_format in ["bed", "wig", "bar"] and not args.chrom_size:
+      debug("You must provide chromosome table with bed and wiggle format")
+    if args.quality_filter < 0:
+      debug("WARNING: you specified negative quality, defaulting to 0")
+      args.quality_filter = 0
+  elif args.predicate == "dump":
+    if args.step_size < 0:
+      debug("WARNING: you specified negative step size, defaulting to 0")
+      args.step_size = 0
+  elif args.predicate == "wltdenoise":
+    if args.window_size < 0:
+      debug("WARNING: you specified negative window size, defaulting to 10000")
+      args.quality_filter = 10000
+  elif args.predicate ==  "firdenoise" :
+    if args.window_size < 0:
+      debug("WARNING: you specified negative window size, defaulting to 10000")
+      args.quality_filter = 10000
+  elif args.predicate == "threshold":
+    1
+  elif args.predicate == "evaluate":
+    print(args.files)
+    print(args.expression)
+  elif args.predicate == "peaks":
+    if args.dbscan_eps < 0:
+      debug("WARNING: you specified negative epsilon, defaulting to 500")
+      args.dbscan_eps = 500
+    if args.dbscan_min < 0:
+      debug("WARNING: you specified negative min. peaks, defaulting to 1")
+      args.dbscam_min = 1
+      
+
 
 def main():
+  options = dsptools.Options()
 
   parser = argparse.ArgumentParser(prog="dsptools", description="A set of tools to operate on genomic signals", version=_version)
   subparsers = parser.add_subparsers(dest="predicate")
   pileup_parser.add_argument("-f", "--format", dest="file_format",  help="File format", choices=['bam', 'bigwig', 'bed', 'bar', 'wig'], default='bam')
   pileup_parser.add_argument("-c", "--csize", dest="chrom_size",  help="File containing chromosome sizes", default=None)
   pileup_parser.add_argument("-n", "--nodup", dest="nodup", action="store_true", help="Naive duplicate removal")
-  pileup_parser.add_argument("-q", "--quality", dest="qual_filter", type=int, help="Quality filter for bam or bed", default=0)
+  pileup_parser.add_argument("-q", "--quality", dest="quality_filter", type=int, help="Quality filter for bam or bed", default=0)
+  pileup_parser.add_argument("--include", dest="include_chrom", help="comma separated list of chroms to include")
+  pileup_parser.add_argument("--exclude", dest="exclude_chrom", help="comma separated list of chroms to exclude")
+  pileup_parser.add_argument("--exchar", dest="invalid_chars", help="Chars that defines invalid chromosomes", default="_")
+  
 
   # dump predicate will convert serialized arrays into data format widely used in genomic research
   dump_parser = subparsers.add_parser("dump", help="Convert serialized data into convenient file formats")
   
   
   # expr parser will evaluate a mathematical operation
-  eval_parser = subparsers.add_parser("eval", help="Evaluates arithmetical expression on serialized data")
+  eval_parser = subparsers.add_parser("evaluate", help="Evaluates arithmetical expression on serialized data")
   eval_parser.add_argument("-o", "--fileout", dest="output_file",  help="Output file prefix", default="dspout")
+  eval_parser.add_argument("-e", "--expr", dest="expression", help="Arithmentical expression, spaces should be escaped, variables are a, b, c...", default=None)
+  eval_parser.add_argument("files", nargs="+", help="List of serialized files")
 
 
   # threshold parser will calculate a threshold
   threshold_parser.add_argument("-f", "--fixedt", dest="fixed_t", help="Fixed float threshold", type=float, default=0.0)
   
   # peak parser will find peak boundaries
-  peaks_parser = subparsers.add_parser("peak", help="Find peaks in quantitative data")
+  peaks_parser = subparsers.add_parser("peaks", help="Find peaks in quantitative data")
   peaks_parser.add_argument("-i", "--filein", dest="input_file",  help="Input file", required=True, default=None)
   peaks_parser.add_argument("-o", "--fileout", dest="output_file",  help="Output file prefix", default="dspout")
   peaks_parser.add_argument("-e", "--epsilon", dest="dbscan_eps", help="DBScan Epsilon vale (distance)", type=int, default=500)
   peaks_parser.add_argument("-t", "--feature", dest="score_feature", help="Feature to score", choices=["height", "area", "width"], default="height")
   peaks_parser.add_argument("-d", "--distribution", dest="score_dist", help="Score distribution model (leave blank for best fit)", choices=["norm", "lognorm", "powerlaw", "gamma"], default=None)
   
-  args = parser.parse_args(sys.argv[1:])
+  args = parser.parse_args(sys.argv[1:], namespace=options)
+  check_options(args)
   
-  print args
+  command = args.predicate + "(args)"
+  eval(command)
+  
+  sys.exit(0)
   
   
 if __name__ == '__main__':
     try:
         main()
     except KeyboardInterrupt:
-        sys.stderr.write("Exiting" + os.linesep)
+        debug("Exiting")
         sys.exit(1)

lib/dsptools/IO/__init__.py

+import File
+import BamFile
+import BigFile

lib/dsptools/__init__.py

-__version__ = '0.1'
+#from actions import *
+#from misc import *
+__all__ = ['IO']
+
+
+
+class Options(object):
+  pass
+
Add a comment to this file

lib/dsptools/__init__.pyc

Binary file modified.

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.