Example #1
0
File: cli.py Project: jluquette/msi
def rm(workflows,prompt_confirm,stage_number,all_stages_after):
    """
    Deletes a workflow
    """
    workflows = [  Workflow.objects.get(pk=w) if representsInt(w) else Workflow.objects.get(name=w)
                   for w in workflows.split(',') ]
    for wf in workflows:
        if stage_number:
            stage = wf.stages.get(order_in_workflow=stage_number)
            if not prompt_confirm or confirm('Are you sure you want to delete {0}{1}{2}?'.
                                             format(wf,stage,' and all stages after it' if all_stages_after else ''),
                                             default=False,timeout=60):
                for s in wf.stages.filter(order_in_workflow__gt=stage.order_in_workflow-1) if all_stages_after else wf.stages.filter(order_in_workflow = stage.order_in_workflow):
                    s.delete()
        else:
            if not prompt_confirm or confirm('Are you sure you want to delete {0}?'.format(wf),default=False,timeout=60):
                wf.delete()
Example #2
0
def main(input_fastq, output_dir, chunksize, buffersize):
    """
    Chunks a large fastq file into smaller pieces.
    """
    chunk = 0
    log.info('Opening {0}'.format(input_fastq))

    if input_fastq.endswith('.gz'):
        infile = gzip.open(input_fastq)
    else:
        infile = open(input_fastq, 'r')
    output_prefix = os.path.basename(input_fastq)
    output_prefix = re.search("(.+?)(_001)*\.(fastq|fq)(\.gz)*",
                              output_prefix).group(1)

    #write chunks
    while True:
        chunk += 1

        # generate output paths
        new_filename = '{0}_{1:0>3}'.format(output_prefix, chunk)
        output_path = os.path.join(output_dir, new_filename + '.fastq.gz')

        if os.path.exists(output_path):
            if not confirm(
                    '{0} already exists!  Are you sure you want to overwrite the file?'
                    .format(output_path),
                    timeout=0):
                return

        log.info('Reading {0} lines and writing to: {1}'.format(
            chunksize * 4, output_path))

        #Read/Write
        total_read = 0
        outfile = gzip.open(output_path, 'wb')
        while total_read < chunksize * 4:
            data = list(islice(infile, buffersize * 4))  #read data
            if len(data) == 0:
                log.info('Done')
                return

            # Write what was read
            outfile.writelines(data)
            log.info('wrote {0} lines'.format(len(data)))
            del (data)
            total_read += buffersize * 4
        outfile.close()

    infile.close()
Example #3
0
def main(input_fastq,output_dir,chunksize,buffersize):
    """
    Chunks a large fastq file into smaller pieces.
    """
    chunk = 0
    log.info('Opening {0}'.format(input_fastq))

    if input_fastq.endswith('.gz'):
        infile = gzip.open(input_fastq)
    else:
        infile = open(input_fastq,'r')
    output_prefix = os.path.basename(input_fastq)
    output_prefix = re.search("(.+?)(_001)*\.(fastq|fq)(\.gz)*",output_prefix).group(1)

    #write chunks
    while True:
        chunk += 1

        # generate output paths
        new_filename = '{0}_{1:0>3}'.format(output_prefix,chunk)
        output_path = os.path.join(output_dir,new_filename+'.fastq.gz')

        if os.path.exists(output_path):
            if not confirm('{0} already exists!  Are you sure you want to overwrite the file?'.format(output_path), timeout=0):
                return

        log.info('Reading {0} lines and writing to: {1}'.format(chunksize*4,output_path))

        #Read/Write
        total_read=0
        outfile = gzip.open(output_path,'wb')
        while total_read < chunksize*4:
            data = list(islice(infile,buffersize*4)) #read data
            if len(data) == 0:
                log.info('Done')
                return

            # Write what was read
            outfile.writelines(data)
            log.info('wrote {0} lines'.format(len(data)))
            del(data)
            total_read += buffersize*4
        outfile.close()

    infile.close()
Example #4
0
File: config.py Project: p7k/COSMOS
"""
Configuration
"""
from configobj import ConfigObj
import shutil
import os,sys
from cosmos.utils.helpers import confirm

user_home_path = os.path.expanduser('~')
cosmos_path = os.path.join(user_home_path,'.cosmos/')
config_path = os.path.join(cosmos_path,'config.ini')
cosmos_library_path = os.path.dirname(os.path.realpath(__file__))
default_config_path = os.path.join(cosmos_library_path,'default_config.ini')

if not os.path.exists(config_path):
    if confirm('No configuration file exists, would you like to create a default one in {0}?'.format(config_path),default=True):
        if not os.path.exists(os.path.dirname(config_path)):
            os.mkdir(os.path.dirname(config_path))
        shutil.copyfile(default_config_path,config_path)
        print >> sys.stderr, "Done.  Before proceeding, please edit {0}".format(default_config_path)
    else:
        sys.exit(1)
# Creating settings dictionary
co = ConfigObj(config_path)
settings = co.dict()
settings['cosmos_library_path'] = cosmos_library_path
settings['cosmos_path'] = cosmos_path
settings['config_path'] = config_path
settings['user_home_path'] = user_home_path

# Defaults