Exemplo n.º 1
0
def run_miso_on_samples(settings_filename, output_dir,
                        use_cluster=True,
                        delay=120):
    """
    Run MISO on a set of samples.
    """
    misowrap_obj = MISOWrap(settings_filename, output_dir,
                            logger_label="run")
    bam_files = misowrap_obj.bam_files
    read_len = misowrap_obj.read_len
    overhang_len = misowrap_obj.overhang_len
    events_dir = misowrap_obj.miso_events_dir
    single_end = True
    if misowrap_obj.insert_lens_dir is not None:
        insert_lens_dir = misowrap_obj.insert_lens_dir
        misowrap_obj.logger.info("Running in paired-end mode...")
        misowrap_obj.logger.info(" - Insert length directory: %s" \
                                 %(insert_lens_dir))
        single_end = False
    else:
        misowrap_obj.logger.info("Running in single-end mode...")        
    run_events_analysis = misowrap_obj.run_events_cmd
    event_types_dirs = \
        miso_utils.get_event_types_dirs(misowrap_obj.settings_info)
    miso_settings_filename = misowrap_obj.miso_settings_filename
    for bam_input in bam_files:
        bam_filename, sample_label = bam_input
        bam_filename = utils.pathify(bam_filename)
        misowrap_obj.logger.info("Processing: %s" %(bam_filename))
        for event_type_dir in event_types_dirs:
            event_type = os.path.basename(event_type_dir)
            print "  - Using event dir: %s" %(event_type_dir)
            miso_cmd = "%s" %(run_events_analysis)
            bam_basename = os.path.basename(bam_filename)
            # Output directory for sample
            sample_output_dir = os.path.join(output_dir, 
                                             sample_label,
                                             event_type)
            # Pass sample to MISO along with event
            miso_cmd += " --compute-genes-psi %s %s" %(event_type_dir,
                                                       bam_filename)
            if not single_end:
                insert_len_filename = \
                    os.path.join(insert_lens_dir,
                                 "%s.insert_len" %(bam_basename))
                misowrap_obj.logger.info("Reading paired-end parameters " \
                                         "from file...")
                misowrap_obj.logger.info("  - PE file: %s" \
                                         %(insert_len_filename))
                pe_params = miso_utils.read_pe_params(insert_len_filename)
                # Paired-end parameters
                miso_cmd += " --paired-end %.2f %.2f" %(pe_params["mean"],
                                                        pe_params["sdev"])
            # Read length
            miso_cmd += " --read-len %d" %(read_len)
            # Overhang length
            miso_cmd += " --overhang-len %d" %(overhang_len)
            # Prefilter?
            if misowrap_obj.prefilter_miso:
                miso_cmd += " --prefilter"
            # Output directory
            miso_cmd += " --output-dir %s" %(sample_output_dir)
            # Use cluster
            if misowrap_obj.use_cluster:
                miso_cmd += " --use-cluster"
                miso_cmd += " --chunk-jobs %d" %(misowrap_obj.chunk_jobs)
            # Settings
            miso_cmd += " --settings %s" %(miso_settings_filename)
            misowrap_obj.logger.info("Executing: %s" %(miso_cmd))
            job_name = "%s_%s" %(sample_label, event_type)
            if use_cluster:
                misowrap_obj.my_cluster.launch_job(miso_cmd,
                                                   job_name)
                time.sleep(delay)
            else:
                os.system(miso_cmd)
Exemplo n.º 2
0
def run(
    settings,
    logs_outdir,
    use_cluster=True,
    base_delay=10,
    # Batch delay (20 mins by default)
    batch_delay=60 * 20,
    delay_every_n_jobs=30,
    dry_run=False,
    event_types=None,
):
    """
    Run MISO on a set of samples.
    """
    settings_filename = utils.pathify(settings)
    if event_types is not None:
        print "Only running MISO on event types: ", event_types
    misowrap_obj = mw.MISOWrap(settings_filename, logs_outdir, logger_label="run")
    output_dir = misowrap_obj.miso_outdir
    bam_files = misowrap_obj.bam_files
    read_len = misowrap_obj.read_len
    overhang_len = misowrap_obj.overhang_len
    events_dir = misowrap_obj.miso_events_dir
    single_end = True
    if misowrap_obj.insert_lens_dir is not None:
        insert_lens_dir = misowrap_obj.insert_lens_dir
        misowrap_obj.logger.info("Running in paired-end mode...")
        misowrap_obj.logger.info(" - Insert length directory: %s" % (insert_lens_dir))
        single_end = False
    else:
        misowrap_obj.logger.info("Running in single-end mode...")
    run_events_analysis = misowrap_obj.run_events_cmd
    event_types_dirs = miso_utils.get_event_types_dirs(misowrap_obj.settings_info)
    miso_settings_filename = misowrap_obj.miso_settings_filename
    n = 0
    for bam_input in bam_files:
        bam_filename, sample_label = bam_input
        bam_filename = utils.pathify(bam_filename)
        misowrap_obj.logger.info("Processing: %s" % (bam_filename))
        for event_type_dir in event_types_dirs:
            event_type = os.path.basename(event_type_dir)
            if event_types is not None:
                if event_type not in event_types:
                    print "Skipping event type: %s" % (event_type)
                    continue
            print "  - Using event dir: %s" % (event_type_dir)
            miso_cmd = "%s" % (run_events_analysis)
            bam_basename = os.path.basename(bam_filename)
            # Output directory for sample
            sample_output_dir = os.path.join(output_dir, sample_label, event_type)
            # Pass sample to MISO along with event
            miso_cmd += " --run %s %s" % (event_type_dir, bam_filename)
            if not single_end:
                insert_len_filename = os.path.join(insert_lens_dir, "%s.insert_len" % (bam_basename))
                misowrap_obj.logger.info("Reading paired-end parameters " "from file...")
                misowrap_obj.logger.info("  - PE file: %s" % (insert_len_filename))
                pe_params = miso_utils.read_pe_params(insert_len_filename)
                # Paired-end parameters
                miso_cmd += " --paired-end %.2f %.2f" % (pe_params["mean"], pe_params["sdev"])
            # Read length
            miso_cmd += " --read-len %d" % (read_len)
            # Overhang length
            miso_cmd += " --overhang-len %d" % (overhang_len)
            # Prefilter?
            if misowrap_obj.prefilter_miso:
                miso_cmd += " --prefilter"
            # Output directory
            miso_cmd += " --output-dir %s" % (sample_output_dir)
            # Use cluster
            if misowrap_obj.use_cluster:
                miso_cmd += " --use-cluster"
                miso_cmd += " --chunk-jobs %d" % (misowrap_obj.chunk_jobs)
            # Settings
            miso_cmd += " --settings %s" % (miso_settings_filename)
            misowrap_obj.logger.info("Executing: %s" % (miso_cmd))
            job_name = "%s_%s" % (sample_label, event_type)
            if use_cluster:
                if not dry_run:
                    misowrap_obj.my_cluster.launch_job(miso_cmd, job_name, ppn=1)
                if n == delay_every_n_jobs:
                    # Larger delay everytime we've submitted n jobs
                    misowrap_obj.logger.info("Submitted %d jobs, now waiting %.2f mins." % (n, batch_delay / 60.0))
                    time.sleep(batch_delay)
                    n = 0
                time.sleep(base_delay)
            else:
                if not dry_run:
                    os.system(miso_cmd)
            n += 1
Exemplo n.º 3
0
def run(settings, logs_outdir,
        use_cluster=True,
        base_delay=10,
        # Batch delay (20 mins by default)
        batch_delay=60*20,
        delay_every_n_jobs=30,
        dry_run=False,
        event_types=None):
    """
    Run MISO on a set of samples.
    """
    settings_filename = utils.pathify(settings)
    if event_types is not None:
        print "Only running MISO on event types: ", event_types
    misowrap_obj = mw.MISOWrap(settings_filename,
                               logs_outdir,
                               logger_label="run")
    output_dir = misowrap_obj.miso_outdir
    bam_files = misowrap_obj.bam_files
    read_len = misowrap_obj.read_len
    overhang_len = misowrap_obj.overhang_len
    events_dir = misowrap_obj.miso_events_dir
    single_end = True
    if misowrap_obj.insert_lens_dir is not None:
        insert_lens_dir = misowrap_obj.insert_lens_dir
        misowrap_obj.logger.info("Running in paired-end mode...")
        misowrap_obj.logger.info(" - Insert length directory: %s" \
                                 %(insert_lens_dir))
        single_end = False
    else:
        misowrap_obj.logger.info("Running in single-end mode...")        
    run_events_analysis = misowrap_obj.run_events_cmd
    event_types_dirs = \
        miso_utils.get_event_types_dirs(misowrap_obj.settings_info)
    miso_settings_filename = misowrap_obj.miso_settings_filename
    n = 0
    for bam_input in bam_files:
        bam_filename, sample_label = bam_input
        bam_filename = utils.pathify(bam_filename)
        misowrap_obj.logger.info("Processing: %s" %(bam_filename))
        for event_type_dir in event_types_dirs:
            event_type = os.path.basename(event_type_dir)
            if event_types is not None:
                if event_type not in event_types:
                    print "Skipping event type: %s" %(event_type)
                    continue
            print "  - Using event dir: %s" %(event_type_dir)
            miso_cmd = "%s" %(run_events_analysis)
            bam_basename = os.path.basename(bam_filename)
            # Output directory for sample
            sample_output_dir = os.path.join(output_dir, 
                                             sample_label,
                                             event_type)
            # Pass sample to MISO along with event
            miso_cmd += " --run %s %s" %(event_type_dir,
                                         bam_filename)
            if not single_end:
                insert_len_filename = \
                    os.path.join(insert_lens_dir,
                                 "%s.insert_len" %(bam_basename))
                misowrap_obj.logger.info("Reading paired-end parameters " \
                                         "from file...")
                misowrap_obj.logger.info("  - PE file: %s" \
                                         %(insert_len_filename))
                pe_params = miso_utils.read_pe_params(insert_len_filename)
                # Paired-end parameters
                miso_cmd += " --paired-end %.2f %.2f" %(pe_params["mean"],
                                                        pe_params["sdev"])
            # Read length
            miso_cmd += " --read-len %d" %(read_len)
            # Overhang length
            miso_cmd += " --overhang-len %d" %(overhang_len)
            # Prefilter?
            if misowrap_obj.prefilter_miso:
                miso_cmd += " --prefilter"
            # Output directory
            miso_cmd += " --output-dir %s" %(sample_output_dir)
            # Use cluster
            if misowrap_obj.use_cluster:
                miso_cmd += " --use-cluster"
                miso_cmd += " --chunk-jobs %d" %(misowrap_obj.chunk_jobs)
            # Settings
            miso_cmd += " --settings %s" %(miso_settings_filename)
            misowrap_obj.logger.info("Executing: %s" %(miso_cmd))
            job_name = "%s_%s" %(sample_label, event_type)
            if use_cluster:
                if not dry_run:
                    misowrap_obj.my_cluster.launch_job(miso_cmd,
                                                       job_name,
                                                       ppn=1)
                if n == delay_every_n_jobs:
                    # Larger delay everytime we've submitted n jobs
                    misowrap_obj.logger.info("Submitted %d jobs, now waiting %.2f mins." \
                                             %(n, batch_delay / 60.))
                    time.sleep(batch_delay)
                    n = 0
                time.sleep(base_delay)
            else:
                if not dry_run:
                    os.system(miso_cmd)
            n += 1