def validate(evaluation, canCancel, dry_run=False):

    if type(evaluation) != Evaluation:
        evaluation = syn.getEvaluation(evaluation)

    print "\n\nValidating", evaluation.id, evaluation.name
    print "-" * 60
    sys.stdout.flush()

    for submission, status in syn.getSubmissionBundles(evaluation, status='RECEIVED'):

        ## refetch the submission so that we get the file path
        ## to be later replaced by a "downloadFiles" flag on getSubmissionBundles
        submission = syn.getSubmission(submission)
        ex1 = None #Must define ex1 in case there is no error
        print "validating", submission.id, submission.name
        try:
            is_valid, validation_message = conf.validate_submission(evaluation, submission)
        except Exception as ex1:
            is_valid = False
            print "Exception during validation:", type(ex1), ex1, ex1.message
            traceback.print_exc()
            validation_message = str(ex1)

        status.status = "VALIDATED" if is_valid else "INVALID"
        if canCancel:
            status.canCancel = True
        if not is_valid:
            failure_reason = {"FAILURE_REASON":validation_message}
        else:
            failure_reason = {"FAILURE_REASON":''}
        add_annotations = synapseclient.annotations.to_submission_status_annotations(failure_reason,is_private=True)
        status = update_single_submission_status(status, add_annotations)

        if not dry_run:
            status = syn.store(status)
        ## send message AFTER storing status to ensure we don't get repeat messages
        profile = syn.getUserProfile(submission.userId)
        if is_valid:
            messages.validation_passed(
                userIds=[submission.userId],
                username=get_user_name(profile),
                queue_name=evaluation.name,
                submission_id=submission.id,
                submission_name=submission.name)
        else:
            if isinstance(ex1, AssertionError):
                sendTo = [submission.userId]
                username = get_user_name(profile)
            else:
                sendTo = conf.ADMIN_USER_IDS
                username = "******"

            messages.validation_failed(
                userIds= sendTo,
                username=username,
                queue_name=evaluation.name,
                submission_id=submission.id,
                submission_name=submission.name,
                message=validation_message)
def validate(evaluation, token, dry_run=False):

    if type(evaluation) != Evaluation:
        evaluation = syn.getEvaluation(evaluation)

    print "\n\nValidating", evaluation.id, evaluation.name
    print "-" * 60
    sys.stdout.flush()


    for submission, status in syn.getSubmissionBundles(evaluation, status='RECEIVED'):

        ## refetch the submission so that we get the file path
        ## to be later replaced by a "downloadFiles" flag on getSubmissionBundles
        sub = json.loads(submission['entityBundleJSON'])
        if len(sub['fileHandles']) == 0:
            submission = syn.getSubmission(submission)
        else:
            if sub['fileHandles'][0].get('externalURL') is None:
                submission = syn.getSubmission(submission)
            else:
                submission = syn.getSubmission(submission,downloadFile=False)

        print "validating", submission.id, submission.name
        try:
            is_valid, validation_message = conf.validate_submission(evaluation, submission, token)
        except Exception as ex1:
            is_valid = False
            print "Exception during validation:", type(ex1), ex1, ex1.message
            traceback.print_exc()
            validation_message = str(ex1)

        status.status = "VALIDATED" if is_valid else "INVALID"

        if not dry_run:
            status = syn.store(status)

        ## send message AFTER storing status to ensure we don't get repeat messages
        profile = syn.getUserProfile(submission.userId)
        if is_valid:
            messages.validation_passed(
                userIds=[submission.userId],
                username=get_user_name(profile),
                queue_name=evaluation.name,
                submission_id=submission.id,
                submission_name=submission.name)
        else:
            messages.validation_failed(
                userIds=[submission.userId],
                username=get_user_name(profile),
                queue_name=evaluation.name,
                submission_id=submission.id,
                submission_name=submission.name,
                message=validation_message)
示例#3
0
def validate(evaluation, token, dry_run=False):

    if type(evaluation) != Evaluation:
        evaluation = syn.getEvaluation(evaluation)

    print "\n\nValidating", evaluation.id, evaluation.name
    print "-" * 60
    sys.stdout.flush()

    for submission, status in syn.getSubmissionBundles(evaluation,
                                                       status='RECEIVED'):

        ## refetch the submission so that we get the file path
        ## to be later replaced by a "downloadFiles" flag on getSubmissionBundles
        sub = json.loads(submission['entityBundleJSON'])
        if len(sub['fileHandles']) == 0:
            submission = syn.getSubmission(submission)
        else:
            if sub['fileHandles'][0].get('externalURL') is None:
                submission = syn.getSubmission(submission)
            else:
                submission = syn.getSubmission(submission, downloadFile=False)

        print "validating", submission.id, submission.name
        try:
            is_valid, validation_message = conf.validate_submission(
                evaluation, submission, token)
        except Exception as ex1:
            is_valid = False
            print "Exception during validation:", type(ex1), ex1, ex1.message
            traceback.print_exc()
            validation_message = str(ex1)

        status.status = "VALIDATED" if is_valid else "INVALID"

        if not dry_run:
            status = syn.store(status)

        ## send message AFTER storing status to ensure we don't get repeat messages
        profile = syn.getUserProfile(submission.userId)
        if is_valid:
            messages.validation_passed(userIds=[submission.userId],
                                       username=get_user_name(profile),
                                       queue_name=evaluation.name,
                                       submission_id=submission.id,
                                       submission_name=submission.name)
        else:
            messages.validation_failed(userIds=[submission.userId],
                                       username=get_user_name(profile),
                                       queue_name=evaluation.name,
                                       submission_id=submission.id,
                                       submission_name=submission.name,
                                       message=validation_message)
def validate(evaluation, dry_run=False):

    if type(evaluation) != Evaluation:
        evaluation = syn.getEvaluation(evaluation)

    print "\n\nValidating", evaluation.id, evaluation.name
    print "-" * 60
    sys.stdout.flush()


    for submission, status in syn.getSubmissionBundles(evaluation, status='RECEIVED'):

        ## refetch the submission so that we get the file path
        ## to be later replaced by a "downloadFiles" flag on getSubmissionBundles
        submission = syn.getSubmission(submission)

        print "validating", submission.id, submission.name
        try:
            is_valid, validation_message = conf.validate_submission(evaluation, submission)
        except Exception as ex1:
            is_valid = False
            validation_message = str(ex1)

        status.status = "VALIDATED" if is_valid else "INVALID"

        if not dry_run:
            status = syn.store(status)

        ## send message AFTER storing status to ensure we don't get repeat messages
        profile = syn.getUserProfile(submission.userId)
        if is_valid:
            messages.validation_passed(
                userIds=[submission.userId],
                username=get_user_name(profile),
                queue_name=evaluation.name,
                submission_id=submission.id,
                submission_name=submission.name)
        else:
            messages.validation_failed(
                userIds=[submission.userId],
                username=get_user_name(profile),
                queue_name=evaluation.name,
                submission_id=submission.id,
                submission_name=submission.name,
                message=validation_message)
示例#5
0
def validate(evaluation, dry_run=False):

    if type(evaluation) != Evaluation:
        evaluation = syn.getEvaluation(evaluation)

    print "\n\nValidating", evaluation.id, evaluation.name
    print "-" * 60
    sys.stdout.flush()

    for submission, status in syn.getSubmissionBundles(evaluation,
                                                       status='RECEIVED'):

        ## refetch the submission so that we get the file path
        ## to be later replaced by a "downloadFiles" flag on getSubmissionBundles
        submission = syn.getSubmission(submission)

        print "validating", submission.id, submission.name
        try:
            is_valid, validation_message = conf.validate_submission(
                evaluation, submission)
        except Exception as ex1:
            is_valid = False
            validation_message = str(ex1)

        status.status = "VALIDATED" if is_valid else "INVALID"

        if not dry_run:
            status = syn.store(status)

        ## send message AFTER storing status to ensure we don't get repeat messages
        profile = syn.getUserProfile(submission.userId)
        if is_valid:
            messages.validation_passed(userIds=[submission.userId],
                                       username=get_user_name(profile),
                                       queue_name=evaluation.name,
                                       submission_id=submission.id,
                                       submission_name=submission.name)
        else:
            messages.validation_failed(userIds=[submission.userId],
                                       username=get_user_name(profile),
                                       queue_name=evaluation.name,
                                       submission_id=submission.id,
                                       submission_name=submission.name,
                                       message=validation_message)
示例#6
0
def validate(evaluation, canCancel, dry_run=False):

    if type(evaluation) != Evaluation:
        evaluation = syn.getEvaluation(evaluation)

    print "\n\nValidating", evaluation.id, evaluation.name
    print "-" * 60
    sys.stdout.flush()
    team_mapping_table = syn.tableQuery('select * from syn8220615')
    team_mapping = team_mapping_table.asDataFrame()
    #metadataPath = syn.get("syn8371011").path
    #metadata = pd.read_csv(metadataPath)
    #patientIds = set(metadata.patientId)
    #HLA = metadata[['patientId','classIHLAalleles']][~metadata['classIHLAalleles'].isnull()]
    metadataTable = syn.tableQuery('SELECT * FROM syn8292741')
    metadata = metadataTable.asDataFrame()
    HLA = metadata[['patientId','classIHLAalleles']][~metadata['classIHLAalleles'].isnull()]
    HLA.drop_duplicates("classIHLAalleles",inplace=True)
    patientIds = set(metadata['patientId'][~metadata['patientId'].isnull()].apply(int))
    for submission, status in syn.getSubmissionBundles(evaluation, status='RECEIVED'):

        ## refetch the submission so that we get the file path
        ## to be later replaced by a "downloadFiles" flag on getSubmissionBundles
        submission = syn.getSubmission(submission,downloadFile=False)
        ex1 = None #Must define ex1 in case there is no error
        print "validating", submission.id, submission.name
        addAnnots = {}
        try:
            is_valid, validation_message, addAnnots = conf.validate_teamname(syn, evaluation, submission, team_mapping)
            add_annotations = synapseclient.annotations.to_submission_status_annotations(addAnnots,is_private=True)
            status = update_single_submission_status(status, add_annotations)
            is_valid, validation_message, patientAnnot = conf.validate_submission(syn, evaluation, submission, patientIds, HLA)
            addAnnots.update(patientAnnot)
        except Exception as ex1:
            is_valid = False
            print "Exception during validation:", type(ex1), ex1, ex1.message
            traceback.print_exc()
            validation_message = str(ex1)

        status.status = "VALIDATED" if is_valid else "INVALID"
        if canCancel:
            status.canCancel = True
        if not is_valid:
            #UPDATE ROUND NUMBER
            addAnnots.update({"FAILURE_REASON":validation_message[0:1000], "round":'2'})
        else:
            #UPDATE ROUND NUMBER
            addAnnots.update({"FAILURE_REASON":'',
                              "submissionName":submission.entity.name, "round":'2'})
        uniqueId = randomString()
        addAnnots.update({"uniqueId":uniqueId})
        add_annotations = synapseclient.annotations.to_submission_status_annotations(addAnnots,is_private=False)
        status = update_single_submission_status(status, add_annotations)

        if not dry_run:
            status = syn.store(status)
        ## send message AFTER storing status to ensure we don't get repeat messages
        profile = syn.getUserProfile(submission.userId)
        if is_valid:
            messages.validation_passed(
                userIds=[submission.userId],
                username=get_user_name(profile),
                queue_name=evaluation.name,
                submission_id=uniqueId,
                submission_name=submission.name)
        else:
            if isinstance(ex1, AssertionError):
                sendTo = [submission.userId]
                username = get_user_name(profile)
            else:
                sendTo = conf.ADMIN_USER_IDS
                username = "******"

            messages.validation_failed(
                userIds= sendTo,
                username=username,
                queue_name=evaluation.name,
                submission_id=uniqueId,
                submission_name=submission.name,
                message=validation_message)
示例#7
0
def validate(evaluation, public=False, admin=None, dry_run=False):

    if type(evaluation) != Evaluation:
        evaluation = syn.getEvaluation(evaluation)

    print("\n\nValidating", evaluation.id, evaluation.name)
    print("-" * 60)
    sys.stdout.flush()
    if admin is not None:
        try:
            admin = syn.getUserProfile(admin)['userName']
        except Exception as ex1:
            admin = syn.getTeam(admin)['name']
    for submission, status in syn.getSubmissionBundles(evaluation, status='RECEIVED'):
        ex1 = None #Must define ex1 in case there is no error
        print("validating", submission.id, submission.name)
        try:
            is_valid, validation_message = conf.validate_submission(syn, evaluation, submission, public=public, admin=admin)
        except Exception as ex1:
            is_valid = False
            print("Exception during validation:", type(ex1), ex1, str(ex1))
            traceback.print_exc()
            validation_error = ex1
            validation_message = str(ex1)

        addannotations = {}
        #Add team name
        if 'teamId' in submission:
            team = syn.restGET('/team/{id}'.format(id=submission.teamId))
            if 'name' in team:
                addannotations['team'] = team['name']
            else:
                addannotations['team'] = submission.teamId
        elif 'userId' in submission:
            profile = syn.getUserProfile(submission.userId)
            addannotations['team'] = get_user_name(profile)
        else:
            addannotations['team'] = '?'
        status.status = "VALIDATED" if is_valid else "INVALID"
        if not is_valid:
            addannotations["FAILURE_REASON"] = validation_message
        else:
            addannotations["FAILURE_REASON"] = ''
        add_annotations = synapseclient.annotations.to_submission_status_annotations(addannotations,is_private=True)
        status = update_single_submission_status(status, add_annotations)

        if not dry_run:
            status = syn.store(status)
        ## send message AFTER storing status to ensure we don't get repeat messages
        profile = syn.getUserProfile(submission.userId)
        if is_valid:
            messages.validation_passed(
                userIds=[submission.userId],
                username=get_user_name(profile),
                queue_name=evaluation.name,
                submission_id=submission.id,
                submission_name=submission.name)
        else:
            if isinstance(validation_error, AssertionError):
                sendTo = [submission.userId]
                username = get_user_name(profile)
            else:
                sendTo = conf.ADMIN_USER_IDS
                username = "******"

            messages.validation_failed(
                userIds= sendTo,
                username=username,
                queue_name=evaluation.name,
                submission_id=submission.id,
                submission_name=submission.name,
                message=validation_message)