示例#1
0
 def createOutputFile(self, ext, contents=""):
     """create an output file, filling it with contents."""
     fpath = self.getOutputFile(ext)
     fileOps.ensureFileDir(fpath)
     fh = open(fpath, "w")
     try:
         fh.write(contents)
     finally:
         fh.close()
 def make_jobtree_dir(self, jobtree_path):
     """
     jobTree wants the parent directory for a given jobTree to exist, but not the directory itself.
     """
     try:
         rmTree(jobtree_path)
     except OSError:
         pass
     ensureFileDir(jobtree_path)
示例#3
0
 def createOutputFile(self, ext, contents=""):
     """create an output file, filling it with contents."""
     fpath = self.getOutputFile(ext)
     fileOps.ensureFileDir(fpath)
     fh = open(fpath, "w")
     try:
         fh.write(contents)
     finally:
         fh.close()
示例#4
0
 def _touch(self, fp):
     "create a file product"
     self.tester.assertTrue(isinstance(fp, File))
     fileOps.ensureFileDir(fp.getOutPath())
     fh = open(fp.getOutPath(), "w")
     try:
         fh.write(self.pset.contents.get(fp))
     finally:
         fh.close()
         self.touchCnt += 1
def pipelineCompress(cmds, outFile):
    """execute the pipeline commands, which must write to stdout, optionally
    compressing based on extension of outFile.  cmds can be a single command
    as a list or a list of lists". Create outFile atomically"""
    if isinstance(cmds[0], str):
        cmds = [cmds]
    outFileTmp = fileOps.atomicTmpFile(outFile)
    fileOps.ensureFileDir(outFileTmp)
    procOps.runProc(cmds + [[getCompressCmd(outFile)]], stdout=outFileTmp)
    fileOps.atomicInstall(outFileTmp, outFile)
示例#6
0
 def _touch(self, fp):
     "create a file product"
     self.tester.failUnless(isinstance(fp, File))
     ext = os.path.splitext(fp.path)[1]
     fileOps.ensureFileDir(fp.getOutPath())
     fh = open(fp.getOutPath(), "w")
     try:
         fh.write(self.pset.contents.get(fp))
     finally:
         fh.close()
         self.touchCnt += 1
示例#7
0
def main():
    args = parse_args()
    target_file_template = "trackDb/{0}/Mus{0}_{1}/consensus.trackDb.ra"
    if args.assembly_version == "1509":
        target_file = target_file_template.format(args.genome,
                                                  args.assembly_version)
        fileOps.ensureFileDir(target_file)
        with open(target_file, "w") as outf:
            make_track(outf)
    else:
        print "This script was called on a release that was not 1509. Did nothing."
示例#8
0
 def _touch(self, fp):
     "create a file product"
     self.tester.failUnless(isinstance(fp, File))
     ext = os.path.splitext(fp.path)[1]
     fileOps.ensureFileDir(fp.getOutPath())
     fh = open(fp.getOutPath(), "w")
     try:
         fh.write(self.pset.contents.get(fp))
     finally:
         fh.close()
         self.touchCnt += 1
示例#9
0
 def getOutPath(self, autoCompress=True):
     """Get the output name for the file, which is newPath until the rule
     terminates. This will also create the output directory for the file,
     if it does not exist.  One wants to use FileOut() to define
     a command argument.  This should not be used to get the path to a file
     to be opened in the ExRun process, use openOut() instead."""
     if self.installed:
         raise ExRunException("output file already installed: " + self.path)
     if self.outPath == None:
         fileOps.ensureFileDir(self.path)
         self.outPath = self.exrun.getAtomicPath(self.path)
     return self.outPath
示例#10
0
 def getOutPath(self, autoCompress=True):
     """Get the output name for the file, which is newPath until the rule
     terminates. This will also create the output directory for the file,
     if it does not exist.  One wants to use FileOut() to define
     a command argument.  This should not be used to get the path to a file
     to be opened in the ExRun process, use openOut() instead."""
     if self.installed:
         raise ExRunException("output file already installed: " + self.path)
     if self.outPath == None:
         fileOps.ensureFileDir(self.path)
         self.outPath = self.exrun.getAtomicPath(self.path)
     return self.outPath
def construct_counts_tables(data, base_path):
    for g, d in data.iteritems():
        counts_path = os.path.join(base_path, g + '.counts.txt')
        conds_path = os.path.join(base_path, g + '.conds.txt')
        ensureFileDir(counts_path)
        cleaned_d = filter_data(d)
        with open(counts_path, 'w') as counts:
            first_line = cleaned_d.values()[0]
            assert len(first_line[0]) == len(first_line[1])
            header = ['ref{}'.format(i) for i in range(len(first_line[0]))] + ['tgt{}'.format(i) for i in range(len(first_line[0]))]
            counts.write('\t'.join(header) + "\n")
            for ens_id, vals in cleaned_d.iteritems():
                f = [item for sublist in vals for item in sublist]
                l = [ens_id] + f
                counts.write('\t'.join(l) + '\n')
        with open(conds_path, 'w') as outf:
            outf.write('condition\n')
            for x in header:
                outf.write('\t'.join([x, ''.join([q for q in x if q.isalpha()])]) + "\n")
def parse_args():
    """
    Build argparse object, parse arguments. See the parsing library for a lot of the features used here.
    """
    parser = FileArgumentParser(description=__doc__)
    parser.add_argument('--bamFiles', action=NamespaceDictAction, nargs='+', mode='defaultdict', required=True,
                        metavar='KEY=VALUE',
                        help='for each key:value pair, give a genome and a bamfile or a bam fofn.')
    parser.add_argument('--genomeFastas', action=NamespaceDictAction, nargs='+', mode='dict',
                        required=True, metavar='KEY=VALUE',
                        help='for each key:value pair, give a genome and a fasta.')
    parser.add_argument("--database", required=True, metavar='FILE', help='path to write database to.')
    parser.add_argument_with_mkdir_p('--workDir', default='hints_work', metavar='DIR',
                                     help='Work directory. Will contain intermediate files that may be useful.')
    parser.add_argument('--norestart', action='store_true', default=False,
                        help='Set to force jobtree pipeline components to start from the beginning instead of '
                             'attempting a restart.')
    parser.add_argument('--localCores', default=12, metavar='INT',
                        help='Number of local cores to use. (default: %(default)d)')
    jobtree = parser.add_argument_group('jobTree options. Read the jobTree documentation for other options not shown')
    jobtree.add_argument('--batchSystem', default='parasol', help='jobTree batch system.')
    jobtree.add_argument('--parasolCommand', default='./bin/remparasol',
                         help='Parasol command used by jobTree. Used to remap to host node.')
    jobtree.add_argument('--maxThreads', default=4,
                         help='maxThreads for jobTree. If not using a cluster, this should be --localCores/# genomes')
    jobtree_parser = argparse.ArgumentParser(add_help=False)
    Stack.addJobTreeOptions(jobtree_parser)
    args = parser.parse_args(namespace=HashableNamespace())
    args.jobTreeOptions = jobtree_parser.parse_known_args(namespace=HashableNamespace())[0]
    args.jobTreeOptions.jobTree = None
    args.jobTreeOptions.__dict__.update({x: y for x, y in vars(args).iteritems() if x in args.jobTreeOptions})
    # munge parsed args, verify, make hashable
    args.genomes = frozenset(vars(args.genomeFastas).keys())
    assert len(args.genomes) > 0
    args.fasta_map = frozendict(vars(args.genomeFastas))
    assert all([os.path.exists(p) for p in args.fasta_map.itervalues()])
    args.bam_map = generate_bam_map(args.bamFiles, args.genomes)
    ensureFileDir(args.database)
    return args
示例#13
0
 def execute(self):
     "create file product"
     for fp in self.produces:
         fileOps.ensureFileDir(fp.path)
         open(fp.path, "w").close()
示例#14
0
 def execute(self):
     "create file product"
     for fp in self.produces:
         fileOps.ensureFileDir(fp.path)
         open(fp.path, "w").close()
示例#15
0
 def getOutputFile(self, ext):
     """Get path to the output file, using the current test id and append
     ext, which should contain a dot"""
     f = self.getOutputDir() + "/" + self.getId() + ext;
     fileOps.ensureFileDir(f)
     return f
示例#16
0
 def getOutputFile(self, ext):
     """Get path to the output file, using the current test id and append
     ext, which should contain a dot"""
     f = self.getOutputDir() + "/" + self.getId() + ext
     fileOps.ensureFileDir(f)
     return f