def bgzip_and_tabix(cnf, vcf_fpath, tabix_parameters='', **kwargs):
    gzipped_fpath = join(vcf_fpath + '.gz')
    tbi_fpath = gzipped_fpath + '.tbi'

    if cnf.reuse_intermediate and \
           file_exists(gzipped_fpath) and \
           file_exists(tbi_fpath) and getctime(tbi_fpath) >= getctime(gzipped_fpath):
        info('Actual compressed VCF and index exist, reusing')
        return gzipped_fpath

    info('Compressing and tabixing VCF file, writing ' + gzipped_fpath + '(.tbi)')
    bgzip = get_system_path(cnf, 'bgzip')
    tabix = get_system_path(cnf, 'tabix')
    if not bgzip:
        err('Cannot index VCF because bgzip is not found in PATH or ' + cnf.sys_cnf)
    if not tabix:
        err('Cannot index VCF because tabix is not found in PATH or ' + cnf.sys_cnf)
    if not bgzip and not tabix:
        return vcf_fpath

    retrying = False
    while True:
        if isfile(tbi_fpath): os.remove(tbi_fpath)
        if isfile(vcf_fpath):
            if isfile(gzipped_fpath):
                 os.remove(gzipped_fpath)
            info('BGzipping VCF')
            cmdline = '{bgzip} {vcf_fpath}'.format(**locals())
            call(cnf, cmdline, None, **kwargs)
        else:
            if not verify_file(gzipped_fpath):
                err('Neither uncompressed ' + vcf_fpath + ' nor ' + gzipped_fpath + ' exist')
                return None

        info('Tabixing VCF')
        cmdline = '{tabix} {tabix_parameters} {gzipped_fpath}'.format(**locals())

        exit_on_error = False
        if retrying:
            exit_on_error = True
        kwargs['exit_on_error'] = exit_on_error
        call(cnf, cmdline, **kwargs)
        if isfile(gzipped_fpath + '.tbi'):
            break
        if retrying:
            critical('Cannot tabix ' + vcf_fpath)
        if not isfile(vcf_fpath):
            call(cnf, 'gunzip ' + gzipped_fpath, None)
        retrying = True

    return gzipped_fpath
Esempio n. 2
0
    def test_time(self):
        f = open(support.TESTFN, "wb")
        try:
            f.write(b"foo")
            f.close()
            f = open(support.TESTFN, "ab")
            f.write(b"bar")
            f.close()
            f = open(support.TESTFN, "rb")
            d = f.read()
            f.close()
            self.assertEqual(d, b"foobar")

            self.assert_(
                genericpath.getctime(support.TESTFN) <= genericpath.getmtime(
                    support.TESTFN))
        finally:
            if not f.closed:
                f.close()
            os.remove(support.TESTFN)
    def test_time(self):
        f = open(support.TESTFN, "wb")
        try:
            f.write(b"foo")
            f.close()
            f = open(support.TESTFN, "ab")
            f.write(b"bar")
            f.close()
            f = open(support.TESTFN, "rb")
            d = f.read()
            f.close()
            self.assertEqual(d, b"foobar")

            self.assertLessEqual(
                genericpath.getctime(support.TESTFN),
                genericpath.getmtime(support.TESTFN)
            )
        finally:
            if not f.closed:
                f.close()
            os.remove(support.TESTFN)
Esempio n. 4
0
 def update_event(self, inp=-1):
     self.set_output_val(0, genericpath.getctime(self.input(0)))
Esempio n. 5
0
@author: VTX
"""
import os
import operator
from genericpath import getctime

rootDir = r"E:\pyTest"

os.chdir(rootDir)
dirs = os.listdir(rootDir)
for i in dirs:
    os.chdir(os.path.join(rootDir, i))
    subs = os.listdir(os.getcwd())
#    print subs
    fileList = []
    for f in subs:
        creaTime = getctime(f)
        obj = {"name":f, "creaTime":creaTime}
        fileList.append(obj)
    fileList.sort(key=operator.itemgetter('creaTime'))
    print fileList
    ind = 0
    for fn in fileList:
        os.rename(fn['name'], str(ind) + os.path.splitext(fn['name'])[1])
        ind += 1