Exemplo n.º 1
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
 def setUp(self):
     import glsclient.log as logger
     self.log = logger.get_custom_logger(glsclient.LOGFILE)
     self.log.setLevel('DEBUG')
     self.gls = glsclient.GlsClientApi(server=glsclient.TEST_SERVER, username=glsclient.USERNAME, password=glsclient.PASSWORD)
     self.unknown_id = 'unknown'
     self.containertype_id = '1'
     self.containertype_name = '96 well plate'
     self.instrument_id = '5'
     self.instrument_name = 'Luke-Leia [HWI-ST230]'
     self.lab_id = '11'
     self.lab_name = 'CRUKCI Core - Genomics'
     # load project
     self.project_name = 'Py Test Project'
     self.projects = self.gls.list_filter_by_name('project', self.project_name)
     self.project = self.projects.project[0]
     # load container type
     self.container_type_name = 'Tube'
     self.container_types = self.gls.list_filter_by_name('container_type', self.container_type_name)
     self.container_type = self.container_types.container_type[0]
     # container name
     self.container_name = 'Container created via Python Unit Test'
     # sample name
     self.sample_name = 'Sample created via Python Unit Test'
     # workflow name
     self.workflow_name = 'BIO: Analyses'
     self.workflows = self.gls.list_filter_by_name('workflow', self.workflow_name)
     self.workflow = self.workflows.workflow[0]
     # process type
     self.process_type_name = 'Automated Pipeline Reports'
     self.process_types = self.gls.list_filter_by_name('process_type', self.process_type_name)
     self.process_type = self.process_types.process_type[0]
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 5
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
Exemplo n.º 6
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
Exemplo n.º 7
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
 def setUp(self):
     import glsclient.log as logger
     self.log = logger.get_custom_logger(glsclient.LOGFILE)
     self.log.setLevel('DEBUG')
     self.glsutil = glsclient.GlsUtil(server=glsclient.TEST_SERVER)