<commit_before>#!/usr/bin/env python

import argparse
from glob import glob
import logging
import os
import subprocess

import miseq_logging
import settings
import sys

def parseOptions():
    parser = argparse.ArgumentParser(
        description='Process all the samples in a single run folder.')
    
    parser.add_argument('run_folder',
                        help='Path to sample fastq files and SampleSheet.csv')
    parser.add_argument('mode',
                        help='Amplicon or Nextera, default from sample sheet',
                        nargs=argparse.OPTIONAL)
    
    return parser.parse_args()



def check_mpi_version():
    p = subprocess.Popen(['mpirun', '-V'],
                         stdout=subprocess.PIPE,
                         stderr=subprocess.STDOUT)
    version, _ = p.communicate()
    return version

def main():
    args = parseOptions()
    log_file = "{}/run.log".format(args.run_folder)
    logger = miseq_logging.init_logging(log_file,
                                        file_log_level=logging.DEBUG,
                                        console_log_level=logging.INFO)
    
    logger.info('Start processing run %s', args.run_folder)
    logger.info('Removing old CSF files')
    old_csf_files = glob(args.run_folder+'/*.aligned.csv')
    for f in old_csf_files:
        os.remove(f)
        
    # Check for Open MPI
    expected_version = 'Open MPI'
    version = check_mpi_version()
    if not expected_version in version:
        subprocess.check_call(['module', 'load', 'openmpi/gnu'])
        version = check_mpi_version()
        if not expected_version in version:
            sys.exit("Couldn't find Open MPI:\n{}".format(version))
    
    mapping_args = ['mpirun', 
                    '-np', 
                    str(settings.mapping_processes), 
                    '--hostfile', 
                    'hostfile', 
                    './sample_pipeline.py',<commit_msg>Make check_mpi_version() handle any exception.<commit_after>#!/usr/bin/env python

import argparse
from glob import glob
import logging
import os
import subprocess
import sys
import traceback

import miseq_logging
import settings

def parseOptions():
    parser = argparse.ArgumentParser(
        description='Process all the samples in a single run folder.')
    
    parser.add_argument('run_folder',
                        help='Path to sample fastq files and SampleSheet.csv')
    parser.add_argument('mode',
                        help='Amplicon or Nextera, default from sample sheet',
                        nargs=argparse.OPTIONAL)
    
    return parser.parse_args()



def check_mpi_version():
    try:
        return subprocess.check_output(['mpirun', '-V'],
                                       stderr=subprocess.STDOUT)
    except:
        etype, value, _tb = sys.exc_info()
        return traceback.format_exception_only(etype, value)

def main():
    args = parseOptions()
    log_file = "{}/run.log".format(args.run_folder)
    logger = miseq_logging.init_logging(log_file,
                                        file_log_level=logging.DEBUG,
                                        console_log_level=logging.INFO)
    
    logger.info('Start processing run %s', args.run_folder)
    logger.info('Removing old CSF files')
    old_csf_files = glob(args.run_folder+'/*.aligned.csv')
    for f in old_csf_files:
        os.remove(f)
        
    # Check for Open MPI
    expected_version = 'Open MPI'
    version = check_mpi_version()
    if not expected_version in version:
        subprocess.check_call(['module', 'load', 'openmpi/gnu'])
        version = check_mpi_version()
        if not expected_version in version:
            sys.exit("Couldn't find Open MPI:\n{}".format(version))
    
    mapping_args = ['mpirun', 
                    '-np', 
                    str(settings.mapping_processes), 
                    '--hostfile', 
                    'hostfile', 
                    './sample_pipeline.py',
{'fraction_non_alphanumeric': 0.09818731117824774, 'fraction_numerical': 0.0, 'mean_word_length': 2.0167046317388, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6564844', 'n_tokens_mistral': 1122, 'n_tokens_neox': 1072, 'n_words': 257}