bb3d819885f31adab7cf3129f54962df1fd2e347
lrnassar
  Wed Jun 3 16:27:41 2020 -0700
Changing the three required arguments from keyword arguments to positional arguments refs #25532

diff --git src/utils/trackDbIndexBb/trackDbIndexBb src/utils/trackDbIndexBb/trackDbIndexBb
index bc73d77..f79ccf0 100755
--- src/utils/trackDbIndexBb/trackDbIndexBb
+++ src/utils/trackDbIndexBb/trackDbIndexBb
@@ -13,108 +13,106 @@
 1) wget http://hgdownload.soe.ucsc.edu/admin/exe/<system>.x86_64/<tool>
 
 where: 
 <system> is macOSX or linux
 <tool> is bedToBigBed and bigBedToBed
 
 2) chmod +x <tool>
 
 bedtools can be found here: https://bedtools.readthedocs.io
     
 These dependancies can be in the path, in the local directory the script is run from, or 
 specified using the optional flags.
 
     
 Example run:
-    trackDbIndexBb -t mm10HMMdata -r mm10HMMdata.ra -c mm10chrom.sizes
-    trackDbIndexBb -t hg19peaks -r hg19peaks.ra -c hg19chrom.sizes -o ./hg19peaks/output -p /user/bin
+    trackDbIndexBb mm10HMMdata mm10HMMdata.ra mm10chrom.sizes
+    trackDbIndexBb hg19peaks hg19peaks.ra hg19chrom.sizes -o ./hg19peaks/output -p /user/bin
 """
-import subprocess, os, shutil, tempfile, atexit, argparse
+import subprocess, os, shutil, tempfile, atexit, argparse, sys
 from distutils.spawn import find_executable
 from collections import OrderedDict 
 
 # ==== functions =====
 def parseArgs():
     """
     Parse the command line arguments.
     """
     parser = argparse.ArgumentParser(description = __doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
     optional = parser._action_groups.pop()
     required = parser.add_argument_group('required arguments')
     
-    required.add_argument ("-t", "--trackName", dest = "trackName",
+    required.add_argument ("trackName",
         help = "Track name for top level coposite which contains the bigBed tracks.")
-    required.add_argument ("-r", "--raFile", dest = "trackDbRaFile",
+    required.add_argument ("raFile",
         help = "Relative or absolute path to trackDb.ra file containing the " + \
             "composite track with bigDataUrls.")
-    required.add_argument ("-c", "--chromSizes", dest = "chromSizes",
+    required.add_argument ("chromSizes",
         help = "Chrom.sizes for database which the track belongs to. Needed " + \
             "to build final bigBed file.")
     # Optional arguments
     optional.add_argument ("-o", "--out", dest = "outDir", default = ".",
         help = "Optional: Output directory for files. Default current directory.")
     optional.add_argument ("-p", "--pathTools", dest = "toolsPath", default = ".",
         help = "Optional: Path to directory where bedtools/bedToBigBed/bigBedToBed " + \
             "can be found")
     optional.add_argument ("-n", "--noDelete", dest = "noDelete", default = False, action = "store_true",
         help = "Optional: Do not delete intermediary multibed.bed file. This option will " + \
             "result in both the multibed.bb and multibed.bed files in the output directory.")
     optional.add_argument ("-m", "--metaDataVar", dest = "metaDataVar", default = "subGroups",
         help = "Optional: Used when there are associated tracks to be displayed " + \
             "alongside the primary BB track. Such as peak tracks with related " + \
             "signals. To relate the tracks, trackDbIndexBb expects all except " + \
             "one of the metaData variables to match among associated tracks. " + \
             "By default, trackDbIndexBb attempts to make association between tracks by " + \
             "using the metaData in the 'subGroups' trackDb parameter. Use this " + \
             "flag to change it to a different association, often 'metaData' is " + \
             "also used.") 
     optional.add_argument ("-s", "--subGroupRemove", dest = "subGroupRemove", default = "view",
         help = "Optional: Used when there are associated tracks to be displayed " + \
             "alongside the primary BB track. Such as peak tracks with related " + \
             "signals. To relate the tracks, trackDbIndexBb expects all except one " + \
             "of the metaData variables to match among associated tracks. This " + \
             "metaData often looks likes: 'view=Peaks mark=A6_H3K36me3' for the .bb " + \
             "track, and 'view=Signal mark=A6_H3K36me3' for the .bw track. In this " + \
             "case, you would want to exclude the 'view' varaible to make histone " + \
             "mark associations (A6_H3K36me3). This flag can be used to pass a " + \
             "different exclusionary variable than the default 'view'") 
-    parser._action_groups.append(optional)
-    options = parser.parse_args()
 
-    if options.trackName is None or options.trackDbRaFile is None or options.chromSizes is None:
+    if (len(sys.argv) == 1):
         parser.print_usage()
         # Print concise help message and usage statement when no arguments passed.
         print("\nGiven a track name, a trackDb.ra composite of bigBeds, and a chrom.sizes\n" + \
         "file, will create index files needed to optimize hideEmptySubtracks setting.\n" + \
         "Depending on size and quantity of files, can take over 60 minutes.\n\n" + \
         "For a more verbose help message, run with help flag: trackDbIndexBb -h\n\n" + \
         "Example run:\n" + \
-        "    trackDbIndexBb -t mm10HMMdata -r mm10HMMdata.ra -c mm10chrom.sizes\n" + \
-        "    trackDbIndexBb -t hg19peaks -r hg19peaks.ra -c hg19chrom.sizes " + \
+        "    trackDbIndexBb mm10HMMdata mm10HMMdata.ra mm10chrom.sizes\n" + \
+        "    trackDbIndexBb hg19peaks hg19peaks.ra hg19chrom.sizes -o ./hg19peaks/output -p /user/bin" + \
         "-o ./hg19peaks/output -p /user/bin\n\n" + \
         "required arguments:\n" + \
-        "  -t TRACKNAME, --trackName TRACKNAME\n" + \
-        "                        Track name for top level coposite which contains the\n" + \
+        "  trackName             Track name for top level coposite which contains the\n" + \
         "                        bigBed tracks.\n" + \
-        "  -r TRACKDBRAFILE, --raFile TRACKDBRAFILE\n" + \
-        "                        Relative or absolute path to trackDb.ra file\n" + \
+        "  raFile                Relative or absolute path to trackDb.ra file\n" + \
         "                        containing the composite track with bigDataUrls.\n" + \
-        "  -c CHROMSIZES, --chromSizes CHROMSIZES\n" + \
-        "                        Chrom.sizes for database which the track belongs to.\n" + \
+        "  chromSizes            Chrom.sizes for database which the track belongs to.\n" + \
         "                        Needed to build final bigBed file.\n")
         exit(0)
 
+    parser._action_groups.append(optional)
+    options = parser.parse_args()
+
     return  options
 
 def saveTrackBigDataUrl(bigDataUrls,track,field,raStanza):
     """
     Initialize an ordered Dictionary for a track entry that matches
     queried track, and save the bigDataUrl
     """
     bigDataUrls[track] = OrderedDict()
     bigDataUrls[track][field] = raStanza[track][field][0]
     return(bigDataUrls)
 
 def saveParentTrackRecord(raStanza,track,compositeNames,field,bigDataUrls):
     """
     Mark down parent tracks associated with target track and save bigDataUrls.
     """
@@ -374,26 +372,26 @@
     print("Files successfully created:\n{outDir}/{trackName}.multiBed.bb\n{outDir}" + \
           "/{trackName}.multiBedSources.tab\n\nPlace the files in their final " + \
           "directory and add the following line to the top trackDb stanza" + \
           ":".format(outDir=outDir,trackName=trackName))
     print("hideEmptySubtracks on\n" + \
           "hideEmptySubtracksMultiBedUrl $myPath/{trackName}.multiBed.bb\n" + \
           "hideEmptySubtracksSourcesUrl $myPath/{trackName}.multiBedSources.tab".format(trackName=trackName))  
         
 def main():
     """
     Initialized options and calls other functions.
     """
     options = parseArgs()
 
     trackName = options.trackName
-    trackDbRaFile = options.trackDbRaFile
+    trackDbRaFile = options.raFile
     chromSizes = options.chromSizes
     outDir = options.outDir
     toolsPath  = options.toolsPath
     subGroupsRemove = options.subGroupRemove
     metaDataVar = options.metaDataVar
     noDelete = options.noDelete
 
     trackDbIndexBb(trackName, trackDbRaFile, chromSizes, outDir, toolsPath, subGroupsRemove, metaDataVar, noDelete)
     
 main()