Example #1
0
def run_unzip(filepath, newpath=None, singleFile=False, **kwargs):
    '''run unzip program as a sub process,
    save to single file newpath if desired.'''
    if newpath is None:
        newpath = filepath[:-4] # DROP THE .zip SUFFIX
    if singleFile: # concatenate all files into newpath
        ifile = file(newpath, 'wb') # copy as binary file
        try:
            status = call_subprocess(['unzip', '-p', filepath], stdout=ifile)
        finally:
            ifile.close()
    else: # just unzip the package as usual
        status = call_subprocess(['unzip', filepath])
    if status != 0:
        raise OSError('unzip "%s" failed!' % filepath)
    return newpath
Example #2
0
def run_unzip(filepath, newpath=None, singleFile=False, **kwargs):
    '''run unzip program as a sub process,
    save to single file newpath if desired.'''
    if newpath is None:
        newpath = filepath[:-4]  # DROP THE .zip SUFFIX
    if singleFile:  # concatenate all files into newpath
        ifile = file(newpath, 'wb')  # copy as binary file
        try:
            status = call_subprocess(['unzip', '-p', filepath], stdout=ifile)
        finally:
            ifile.close()
    else:  # just unzip the package as usual
        status = call_subprocess(['unzip', filepath])
    if status != 0:
        raise OSError('unzip "%s" failed!' % filepath)
    return newpath
Example #3
0
def run_gunzip(filepath, newpath=None):
    'run gunzip program as a sub process'
    if newpath is None:
        newpath = filepath[:-3]
    ifile = open(newpath, 'w+b')
    try:
        if call_subprocess(['gunzip', '-c', filepath], stdout=ifile):
            raise OSError('gunzip "%s" failed!' % filepath)
    finally:
        ifile.close()
    return newpath
Example #4
0
def run_gunzip(filepath, newpath=None):
    'run gunzip program as a sub process'
    if newpath is None:
        newpath = filepath[:-3]
    ifile = open(newpath, 'w+b')
    try:
        if call_subprocess(['gunzip', '-c', filepath], stdout=ifile):
            raise OSError('gunzip "%s" failed!' % filepath)
    finally:
        ifile.close()
    return newpath
Example #5
0
 def run_formatdb(self, filepath):
     'ATTEMPT TO BUILD BLAST DATABASE INDEXES at filepath'
     dirname = classutil.file_dirpath(filepath)
     if not os.access(dirname, os.W_OK): # check if directory is writable
         raise IOError('run_formatdb: directory %s is not writable!'
                       % dirname)
     cmd = ['formatdb', '-i', self.filepath, '-n', filepath, '-o', 'T']
     if self.seqDB._seqtype != PROTEIN_SEQTYPE:
         cmd += ['-p', 'F'] # special flag required for nucleotide seqs
     logger.info('Building index: ' + ' '.join(cmd))
     if classutil.call_subprocess(cmd): # bad exit code, so command failed
         raise OSError('command %s failed' % ' '.join(cmd))
     self.blastReady=True
     if filepath!=self.filepath:
         self.blastIndexPath = filepath
Example #6
0
 def run_formatdb(self, testpath):
     'ATTEMPT TO BUILD BLAST DATABASE INDEXES at testpath'
     dirname = classutil.file_dirpath(testpath)
     if not os.access(dirname, os.W_OK): # check if directory is writable
         raise IOError('run_formatdb: directory %s is not writable!'
                       % dirname)
     cmd = ['formatdb', '-i', self.filepath, '-n', testpath, '-o', 'T']
     if self.seqDB._seqtype != PROTEIN_SEQTYPE:
         cmd += ['-p', 'F'] # special flag required for nucleotide seqs
     logger.info('Building index: ' + ' '.join(cmd))
     if self.showFormatdbMessages:
         kwargs = {}
     else: # suppress formatdb messages by redirecting them
         kwargs = dict(stdout=classutil.PIPE, stderr=classutil.PIPE)
     if classutil.call_subprocess(cmd, **kwargs):
         # bad exit code, so command failed
         warn_if_whitespace(self.filepath) \
              or warn_if_whitespace(testpath) # only issue one warning
         raise OSError('command %s failed' % ' '.join(cmd))
     self.blastReady=True
     if testpath!=self.filepath:
         self.blastIndexPath = testpath