Exemple #1
0
 def __init__(self, use_dev_lims=True):
     self.log = logging.getLogger(__name__)
     self.lims_server = glsclient.SERVER
     if use_dev_lims:
         self.lims_server = glsclient.TEST_SERVER
     self.glsutil = glsclient.GlsUtil(server=self.lims_server)
     self.log.info('*** CONNECT TO GLS LIMS ********************************************************')
Exemple #2
0
def main():
    # get the options
    parser = argparse.ArgumentParser()
    parser.add_argument("--update", dest="update", action="store_true", default=False, help="use this option to preform the update and not only report action")
    parser.add_argument("--limsprod", dest="limsprod", action="store_true", default=False, help="Use the production LIMS url, by default it runs against the dev server.")
    parser.add_argument("--logfile", dest="logfile", action="store", default=False, help="File to print logging information")

    options = parser.parse_args()

    # logging configuration
    if options.logfile:
        log = logger.get_custom_logger(options.logfile)
    else:
        log = logger.get_custom_logger()

    log.setLevel('INFO')

    try:
        # connect to lims
        if options.limsprod:
            lims_server = glsclient.SERVER
        else:
            lims_server = glsclient.TEST_SERVER
        log.info('Connected to ' + lims_server)
        glsutil = glsclient.GlsUtil(server=lims_server)

        # count number of artifacts to modify
        count = 0

       # get all artifacts to modify in results
        glsutil.db.execute(QUERY)
        results = glsutil.db.fetchall()
        for row in results:
            count += 1
            artifact = glsutil.api.load('artifact', row['luid'])
            field_name = 'LPS Billable'
            field_value = None
            for field in artifact.field:
                if field.name == field_name:
                    field_value = field.value()
            field_new_value = row['outlpsbillable']
            log.info("[%s] Retrieved artifact %s, field '%s' value '%s' will be set to '%s'" % (count, artifact.uri, field_name, field_value, field_new_value))
            if options.update:
                new_field = glsapi.userdefined.field(row['outlpsbillable'])
                new_field.name = field_name
                artifact.field.append(new_field)
                log.debug(artifact.toxml('utf-8'))
                updated_artifact = glsutil.api.update(artifact)
                log.info("[%s] '%s' changed from '%s' to '%s' on artifact %s" % (count, field_name, field_value, field_new_value, updated_artifact.uri))

    except:
        log.exception("Unexpected error")
        raise
Exemple #3
0
def main():
    # get the options
    parser = argparse.ArgumentParser()
    parser.add_argument("--update", dest="update", action="store_true", default=False, help="use this option to preform the update and not only report action")
    parser.add_argument("--limsprod", dest="limsprod", action="store_true", default=False, help="Use the production LIMS url, by default it runs against the dev server.")
    parser.add_argument("--logfile", dest="logfile", action="store", default=False, help="File to print logging information")

    options = parser.parse_args()

    # logging configuration
    if options.logfile:
        log = logger.get_custom_logger(options.logfile)
    else:
        log = logger.get_custom_logger()

    log.setLevel('INFO')

    try:
        # connect to lims
        if options.limsprod:
            lims_server = glsclient.SERVER
        else:
            lims_server = glsclient.TEST_SERVER
        log.info('Connected to ' + lims_server)
        glsutil = glsclient.GlsUtil(server=lims_server)

        # count number of accounts to modify
        count = 0

        # get all accounts
        all_accounts = glsutil.api.list('lab')

        field_name = 'Email Address for Billing Notifications'

        for account in all_accounts.lab:
            lab = glsutil.api.load_by_uri('lab', account.uri)
            try:
                if lab.billing_address.institution == 'University of Cambridge MRC Cancer Unit':
                    count += 1
                    log.info(lab.billing_address.institution)
                    field_value = None
                    for field in lab.field:
                        if field.name == field_name:
                            field_value = field.value()
                            log.info(field_value)
                    if options.update:
                        field_new_value = '[email protected], [email protected]'
                        new_field = glsapi.userdefined.field(field_new_value)
                        new_field.name = field_name
                        lab.field.append(new_field)
                        log.debug(lab.toxml('utf-8'))
                        updated_lab = glsutil.api.update(lab)
                        log.info("[%s] '%s' changed from '%s' to '%s' on account %s" % (count, field_name, field_value, field_new_value, updated_lab.uri))

            except AttributeError:
                log.error(account.name)
                continue

    except:
        log.exception("Unexpected error")
        raise
Exemple #4
0
def main():
    # get the options
    parser = argparse.ArgumentParser()
    parser.add_argument("--update", dest="update", action="store_true", default=False, help="use this option to preform the update and not only report action")
    parser.add_argument("--updatesamples", dest="updatesamples", action="store_true", default=False, help="use this option to set the date received on sample and not only report action")
    parser.add_argument("--limsdev", dest="limsdev", action="store_true", default=False, help="Use the development LIMS url")
    parser.add_argument("--email", dest="email", action="store_true", default=False, help="Send email to genomics on MiSeq Express samples")
    parser.add_argument("--logfile", dest="logfile", action="store", default=False, help="File to print logging information")

    options = parser.parse_args()

    # logging configuration
    if options.logfile:
        log = logger.get_custom_logger(options.logfile)
    else:
        log = logger.get_custom_logger()

    try:
        # connect to lims
        lims_server = glsclient.SERVER
        if options.limsdev:
            lims_server = glsclient.TEST_SERVER
        glsutil = glsclient.GlsUtil(server=lims_server)
        glsutil.db.execute(glssql.UNASSIGNED_SAMPLES_QUERY)
        results = glsutil.db.fetchall()

        count = 0
        count_miseqexpress = 0
        count_nextseqdirect = 0
        count_unknownworkflow = 0
        report_assignedsamples = ''
        report_unassignedsamples = ''
        # MiSeq Express report to include: SLXID | username | workflow | entype | seqtype
        report_miseqexpresssamples = 'SLX-ID\t| project\t| researcher\t| read length\t| seq. type\n'
        # NextSeq Direct report to include: SLXID | username | workflow | entype | seqtype
        report_nextseqdirectsamples = 'SLX-ID\t| project\t| researcher\t| read length\t| seq. type\n'
        # Unassigned samples report to include: SLXID | username | workflow | entype | seqtype
        report_unknownworkflowsamples = 'SLX-ID\t| project\t| researcher\t| read length\t| seq. type\n'
        for row in results:
            # projectname,researchername,artifactid,samplename,slxid,workflow,readlength,seqtype,seqinfo,submissiondate,email
            try:
                # update sample date received if empty
                if row['submissiondate'] is None or row['submissiondate'] == '':
                    log.info('No date received on sample %s' % row['samplename'])
                    if options.updatesamples:
                        artifact = glsutil.api.load('artifact', row['artifactid'])
                        sample = glsutil.api.load('sample', artifact.sample[0].limsid)
                        sample.date_received = str(datetime.date.today())
                        log.debug(sample.toxml('utf-8'))
                        updated_sample = glsutil.api.update(sample)
                        log.info('Date set to %s on sample %s' % (updated_sample.date_received, updated_sample.name))
                        log.debug(updated_sample.toxml('utf-8'))


                # assign samples to workflow
                if row['workflow'] in WORKFLOW_MAPPING.keys():
                    details = "[%s,%s,%s,%s,%s] to be assigned to workflow '%s'" % (row['artifactid'], row['projectname'], row['samplename'], row['slxid'], row['workflow'], WORKFLOW_MAPPING[row['workflow']])
                    detailed_info_for_report = "%s\t| %s\t| %s\t| %s\t| %s" % (row['slxid'], row['projectname'], row['researcher'], row['readlength'], row['seqtype'])
                    report_assignedsamples += details + "\n"
                    log.info(details)
                    if options.update:
                        workflows = glsutil.api.list_filter_by_name('workflow', WORKFLOW_MAPPING[row['workflow']])
                        workflow = workflows.workflow[0]
                        log.debug(workflow)
                        artifact = glsutil.api.load('artifact', row['artifactid'])
                        glsutil.route_each_artifact_to_workflow([artifact.uri], WORKFLOW_MAPPING[row['workflow']])
                        count += 1
                        if row['workflow'] == 'MiSeq Express':
                            log.debug(detailed_info_for_report)
                            report_miseqexpresssamples += detailed_info_for_report + "\n"
                            count_miseqexpress += 1
                        if row['workflow'].startswith('NextSeq Direct') or row['workflow'].startswith('NextSeq Express'):
                            log.debug(detailed_info_for_report)
                            report_nextseqdirectsamples += detailed_info_for_report + "\n"
                            count_nextseqdirect += 1
                else:
                    details = "[%s,%s,%s,%s,%s] not assigned" % (row['artifactid'], row['projectname'], row['samplename'], row['slxid'], row['workflow'])
                    detailed_info_for_report = "%s\t| %s\t| %s\t| %s\t| %s\t| %s" % (row['slxid'], row['projectname'], row['researcher'], row['readlength'], row['seqtype'], row['workflow'])
                    report_unassignedsamples += details + "\n"
                    log.warn(details)
                    report_unknownworkflowsamples += detailed_info_for_report + "\n"
                    count_unknownworkflow += 1
            except:
                log.exception("Unexpected error")
                continue

        # email sent to genomics for MiSeq Express
        report_miseqexpresssamples = "%s samples assigned to MiSeq Express workflow:\n\n" % count_miseqexpress + report_miseqexpresssamples
        if options.email and count_miseqexpress > 0:
            send_email('MiSeq Express', report_miseqexpresssamples)
        log.info('MISEQ EXPRESS REPORT')
        log.info(report_miseqexpresssamples)

        # email sent to genomics for NextSeq Direct
        report_nextseqdirectsamples = "%s samples assigned to NextSeq Express workflow:\n\n" % count_nextseqdirect + report_nextseqdirectsamples
        if options.email and count_nextseqdirect > 0:
            send_email('NextSeq Express', report_nextseqdirectsamples)
        log.info('NEXTSEQ EXPRESS REPORT')
        log.info(report_nextseqdirectsamples)

        # email sent to genomics for unknown workflow
        report_unknownworkflowsamples = "%s samples unassigned to workflow:\n\n" % count_unknownworkflow + report_unknownworkflowsamples
        if options.email and count_unknownworkflow > 0:
            send_email('Unknown Workflow', report_unknownworkflowsamples)
        log.info('UNKNOWN WORKFLOW REPORT')
        log.info(report_unknownworkflowsamples)

        log.info("%s samples assigned to workflows over %s" % (count, len(results)))
        log.info("%s samples assigned to MiSeq Express workflow" % count_miseqexpress)
        log.info("%s samples assigned to NextSeq Direct workflow" % count_nextseqdirect)
        log.info("%s samples unassigned to any workflow" % count_unknownworkflow)

        if not options.update:
            log.info('use --update to perform the operation in the lims')

        print report_assignedsamples
        print report_unassignedsamples

    except:
        log.exception("Unexpected error")
        raise
Exemple #5
0
def main():
    # get the options
    parser = argparse.ArgumentParser()

    parser.add_argument("--stagingdir",
                        dest="stagingdir",
                        action="store",
                        help="staging base directories e.g. '/staging'",
                        required=True)

    parser.add_argument(
        "--dry-run",
        dest="dry_run",
        action="store_true",
        default=False,
        help=
        "use this option to not do any shell command execution, only report actions"
    )
    parser.add_argument("--dev-lims",
                        dest="use_limsdev",
                        action="store_true",
                        default=False,
                        help="Use the development LIMS url")
    parser.add_argument("--logfile",
                        dest="logfile",
                        action="store",
                        default=False,
                        help="File to print logging information")
    parser.add_argument("--nologemail",
                        dest="nologemail",
                        action="store_true",
                        default=False,
                        help="turn off sending log emails on error")

    options = parser.parse_args()

    # logging configuration
    log = logger.get_custom_logger(options.logfile, options.nologemail)

    # connect to lims
    lims_server = glsclient.SERVER
    if options.use_limsdev:
        lims_server = glsclient.TEST_SERVER
    glsutil = glsclient.GlsUtil(server=lims_server)

    glsutil.db.execute(glssql.PUBLISHED_RUNS_WITHOUT_FASTQ_ATTACHED)
    results = glsutil.db.fetchall()

    if results:
        for r in results:
            run_folder = r['run_id']
            if os.path.exists(os.path.join(options.stagingdir, run_folder)):
                log.error(
                    "Published run %s on staging area %s without sample FASTQ files"
                    % (run_folder, options.stagingdir))
            else:
                log.warning(
                    "Published run %s not on staging area %s without sample FASTQ files"
                    % (run_folder, options.stagingdir))

    glsutil.close_db_connection()
Exemple #6
0
def main():
    # get the options
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--mapping",
        dest="mapping",
        action="store",
        help=
        "mapping file, tab separated columns with old/new header '/path/to/mapping/file/mapping.txt'",
        required=True)
    parser.add_argument("--field",
                        dest="field",
                        action="store",
                        help="sample UDF name e.g. 'Billing Information'",
                        required=True)
    parser.add_argument(
        "--update",
        dest="update",
        action="store_true",
        default=False,
        help="use this option to preform the update and not only report action"
    )
    parser.add_argument(
        "--limsprod",
        dest="limsprod",
        action="store_true",
        default=False,
        help=
        "Use the production LIMS url, by default it runs against the dev server."
    )
    parser.add_argument("--logfile",
                        dest="logfile",
                        action="store",
                        default=False,
                        help="File to print logging information")

    options = parser.parse_args()

    # logging configuration
    if options.logfile:
        log = logger.get_custom_logger(options.logfile)
    else:
        log = logger.get_custom_logger()

    log.setLevel('INFO')

    try:
        # read mapping file
        mappings = []
        with open(options.mapping, "U") as f:
            reader = csv.DictReader(f, delimiter='\t')
            for line in reader:
                mappings.append(line)
        log.info(mappings)

        # connect to lims
        if options.limsprod:
            lims_server = glsclient.SERVER
        else:
            lims_server = glsclient.TEST_SERVER
        log.info('Connected to ' + lims_server)
        glsutil = glsclient.GlsUtil(server=lims_server)

        # count number of samples to modify
        count = 0

        # loop over all changes in mapping file
        for mapping in mappings:
            # get all samples to modify in results
            glsutil.db.execute(SAMPLES_QUERY % (options.field, mapping['old']))
            results = glsutil.db.fetchall()
            for row in results:
                count += 1
                sample = glsutil.api.load('sample', row['luid'])
                log.info(
                    "[%s] Retrieved sample %s, field '%s' has old value '%s', it will be changed to '%s'"
                    % (count, sample.uri, options.field, mapping['old'],
                       mapping['new']))
                if options.update:
                    new_field = glsapi.userdefined.field(mapping['new'])
                    new_field.name = options.field
                    sample.field.append(new_field)
                    log.debug(sample.toxml('utf-8'))
                    updated_sample = glsutil.api.update(sample)
                    log.info(
                        "[%s] '%s' changed from '%s' to '%s' on sample %s" %
                        (count, options.field, mapping['old'], mapping['new'],
                         updated_sample.uri))

    except:
        log.exception("Unexpected error")
        raise
Exemple #7
0
def main():
    # get the options
    parser = argparse.ArgumentParser()
    parser.add_argument("--send-email",
                        dest="send_email",
                        action="store_true",
                        default=False,
                        help="Send email")
    parser.add_argument("--logfile",
                        dest="logfile",
                        action="store",
                        default=False,
                        help="File to print logging information")

    options = parser.parse_args()

    # logging configuration
    if options.logfile:
        log = logger.get_custom_logger(options.logfile)
    else:
        log = logger.get_custom_logger()

    log.setLevel('INFO')

    try:
        # connect to lims
        lims_server = glsclient.SERVER
        log.info('Connected to ' + lims_server)
        glsutil = glsclient.GlsUtil(server=lims_server)

        current_group_name = ''
        account_list = ''
        account_members = ''
        report = ''
        fail_report = ''
        for account in get_group_accounts(glsutil):
            if current_group_name != account['group_name']:
                if current_group_name and account_list:
                    log.info('----------')
                    log.info(current_group_name)
                    log.info(account['leader_emails'])
                    log.info(account['approver_emails'])
                    log.info(account_list)
                    if account['leader_emails']:
                        report += 'OK\t%s\t%s\t%s\n' % (
                            current_group_name, account['leader_emails'],
                            account_members)
                        send_email(log, current_group_name,
                                   account['leader_emails'].split(','),
                                   account_list, options.send_email)
                    else:
                        log.error('Account without leader')
                        fail_report += 'FAIL\t%s\t%s\t%s\n' % (
                            current_group_name, account['leader_emails'],
                            account_members)
                current_group_name = account['group_name']
                account_list = ''
                account_members = ''

            account_list += '- %s <%s>\n' % (account['researcher'],
                                             account['email'])
            account_members += '%s <%s>,' % (account['researcher'],
                                             account['email'])
        log.info(report)
        log.info(fail_report)
    except:
        log.exception("Unexpected error")
        raise
Exemple #8
0
def main():
    # get the options
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--update",
        dest="update",
        action="store_true",
        default=False,
        help="use this option to preform the update and not only report action"
    )
    parser.add_argument("--limsdev",
                        dest="limsdev",
                        action="store_true",
                        default=False,
                        help="Use the development LIMS url")
    parser.add_argument("--logfile",
                        dest="logfile",
                        action="store",
                        default=False,
                        help="File to print logging information")

    options = parser.parse_args()

    # logging configuration
    if options.logfile:
        log = logger.get_custom_logger(options.logfile)
    else:
        log = logger.get_custom_logger()

    try:
        # connect to lims
        if options.limsdev:
            lims_server = 'limsdev'
        else:
            lims_server = 'lims'
        glsutil = glsclient.GlsUtil(server=lims_server)
        results = glsutil.db.execute(
            glssql.SAMPLES_WITH_NODATE_QUERY).fetchall()

        for row in results:
            # artifactid,samplename,submissiondate,acceptancedate
            try:
                # update sample date received if empty
                if row.submissiondate is None or row.submissiondate == '':
                    log.info(
                        'No date received on sample %s. It will be set to %s.'
                        % (row.samplename, row.acceptancedate))
                    if options.update:
                        artifact = glsutil.api.load('artifact', row.artifactid)
                        sample = glsutil.api.load('sample',
                                                  artifact.sample[0].limsid)
                        sample.date_received = row.acceptancedate
                        log.debug(sample.toxml('utf-8'))
                        updated_sample = glsutil.api.update(sample)
                        log.info('Date set to %s on sample %s' %
                                 (updated_sample.date_received,
                                  updated_sample.name))
                        log.debug(updated_sample.toxml('utf-8'))
            except:
                log.exception("Unexpected error")
                continue

    except:
        log.exception("Unexpected error")
        raise