Merge branch 'master' of mus.cacr.caltech.edu:htsworkflow
authorDiane Trout <diane@caltech.edu>
Tue, 27 Mar 2012 21:59:56 +0000 (14:59 -0700)
committerDiane Trout <diane@caltech.edu>
Tue, 27 Mar 2012 21:59:56 +0000 (14:59 -0700)
1  2 
encode_submission/ucsc_gather.py

index d8c30039c70028e770c890ce343f4a8aa460a6bf,5967eb734611ca93415efef08828065324bcd27e..8ad4f3ee297427c3d9c26252b4aa57718cd61bdb
@@@ -17,6 -17,7 +17,7 @@@ import type
  import urllib
  import urllib2
  import urlparse
+ from zipfile import ZipFile
  
  import RDF
  
@@@ -90,6 -91,9 +91,9 @@@ def main(cmdline=None)
      if opts.make_ddf:
          make_all_ddfs(mapper, library_result_map, opts.daf, force=opts.force)
  
+     if opts.zip_ddf:
+         zip_ddfs(mapper, library_result_map, opts.daf)
      if opts.sparql:
          sparql_query(model, opts.sparql)
  
@@@ -126,6 -130,9 +130,9 @@@ def make_parser()
                          help="link daf into submission directories")
      commands.add_option('--make-ddf', help='make the ddfs', default=False,
                        action="store_true")
+     commands.add_option('--zip-ddf', default=False, action='store_true',
+                         help='zip up just the metadata')
      parser.add_option_group(commands)
  
      parser.add_option('--force', default=False, action="store_true",
@@@ -190,6 -197,7 +197,7 @@@ def scan_submission_dirs(view_map, libr
          except MetadataLookupException, e:
              logger.error("Skipping %s: %s" % (lib_id, str(e)))
  
  def make_all_ddfs(view_map, library_result_map, daf_name, make_condor=True, force=False):
      dag_fragment = []
      for lib_id, result_dir in library_result_map:
@@@ -250,7 -258,7 +258,7 @@@ ORDER BY  ?submitView""
          logger.error("Need name for %s" % (str(submissionNode)))
          return []
  
-     ddf_name = name + '.ddf'
+     ddf_name = make_ddf_name(name)
      if outdir is not None:
          outfile = os.path.join(outdir, ddf_name)
          output = open(outfile,'w')
      return dag_fragments
  
  
+ def zip_ddfs(view_map, library_result_map, daf_name):
+     """zip up just the ddf & daf files
+     """
+     rootdir = os.getcwd()
+     for lib_id, result_dir in library_result_map:
+         submissionNode = view_map.get_submission_node(result_dir)
+         nameNode = view_map.model.get_target(submissionNode,
+                                              submissionOntology['name'])
+         name = fromTypedNode(nameNode)
+         if name is None:
+             logger.error("Need name for %s" % (str(submissionNode)))
+             continue
+         zip_name = '../{0}.zip'.format(lib_id)
+         os.chdir(os.path.join(rootdir, result_dir))
+         with ZipFile(zip_name, 'w') as stream:
+             stream.write(make_ddf_name(name))
+             stream.write(daf_name)
+         os.chdir(rootdir)
  def read_library_result_map(filename):
      """
      Read a file that maps library id to result directory.
@@@ -425,6 -454,18 +454,6 @@@ def get_library_info(host, apidata, lib
      return contents
  
  
 -def make_submission_section(line_counter, files, attributes):
 -    """
 -    Create a section in the submission ini file
 -    """
 -    inifile = [ "[line%s]" % (line_counter,) ]
 -    inifile += ["files=%s" % (",".join(files))]
 -
 -    for k,v in attributes.items():
 -        inifile += ["%s=%s" % (k,v)]
 -    return inifile
 -
 -
  def make_base_name(pathname):
      base = os.path.basename(pathname)
      name, ext = os.path.splitext(base)