Example #1
0
def createMSRuns():
    data = request.json
    msRuns = data.get('samples')
    responseDTO = BulkCreateResponseDTO()

    for i in msRuns:
        msReadySample = msReadySamplesDAO.getMSReadySampleByName(
            i['msReadySampleName'])

        sop = "NA"
        if(msReadySample != None):
            if i['runMode'] == "DIA":
                entry = artefactDAO.getArtefactById(i['SOPDIA'])
                if(entry != None):
                    sop = entry['name']
            elif i['runMode'] == "DDA":
                entry = artefactDAO.getArtefactById(i['SOPDDA'])
                if(entry != None):
                    sop = entry['name']

            description = ""
            if i['description'] != None:
                description = i['description']

            existingMSRun = MSRunDAO.getMsRunByName(i['name'])

            if(existingMSRun != None):
                MSRunDAO.updateMSRun(
                    existingMSRun['id'], msReadySample['id'], msReadySample['clinicalSamples'], i['instrumentId'], sop,
                    description, i['instrumentMethod'], i['processingPerson'])
                responseDTO.appendOverwritten(i['name'])

            else:
                new_msrun = {
                    "clinicalSamples": msReadySample['clinicalSamples'],
                    "msReadySampleId": msReadySample['id'],
                    "name": i['name'],
                    "projectId": i['projectId'],
                    "protocolId": i['runMode'],
                    "instrumentId": i['instrumentId'],
                    "sopFileName": sop,
                    "instrumentMethod": i['instrumentMethod'],
                    "updatedDate": datetime.datetime.now(),
                    "createdDate": datetime.datetime.now(),
                    "workflowTag": "Library Generation",
                    "description": description,
                    "processingPerson": i['processingPerson'],
                }
                new_run = MSRunDAO.createMsRun(new_msrun)
                responseDTO.appendCreateSuccess(i['name'])
        else:
            responseDTO.appendCreateFail(i['name'])

    return responseDTO.toJson(), status.HTTP_200_OK
Example #2
0
def insertSWATHAnalysis(swa, projectId):
    spl = spectralLibraryDAO.getAllLibrariesForProject(projectId)
    ms_runs = MSRunDAO.getAllMSRunsByProjectId(projectId)
    ms_run_ids = []
    involved_clinical_samples = []
    for ms_run in ms_runs:
        if (re.search("^sgoetze_A1902_-*", ms_run['name'])):
            ms_run_ids.append(ms_run['id'])
            for j in ms_run['clinicalSamples']:
                if j not in involved_clinical_samples:
                    involved_clinical_samples.append(j)

    new_swa = {
        "swathId": 1,
        "clinicalSamples": involved_clinical_samples,
        "msRunIds": ms_run_ids,
        "name": "PHRT_001_005_CPAC_SWATH",
        "spectralLibraryId": spl[0]['id'],
        "projectId": projectId,
        "protocolId": "1",
        "protocolName": swa['protocolId'],
        "sopFileName": "PHRT_Data_Analysis_SOP",
        "proteinMatrixFileName": "PHRT_005_Protein_Matrix.tsv",
        "updatedDate": datetime.datetime.now(),
        "createdDate": datetime.datetime.now(),
        "workflowTag": "SWATHAnalysis",
        "description": "Generated from Excel archive"
    }

    print(swathAnalysisDAO.createSWATHAnalysis(new_swa))
Example #3
0
def insertSpectralLibrary(spl, projectId):
    ms_runs = MSRunDAO.getAllMSRunsByProjectId(projectId)
    ms_run_ids = []
    involved_clinical_samples = []
    for ms_run in ms_runs:
        if (re.search("^sgoetze_C1902-*", ms_run['name'])):
            ms_run_ids.append(ms_run['id'])
            for j in ms_run['clinicalSamples']:
                if j not in involved_clinical_samples:
                    involved_clinical_samples.append(j)

    new_spl = {
        "libId": 1,
        "clinicalSamples": involved_clinical_samples,
        "msRunIds": ms_run_ids,
        "name": "PHRT_001_005_CPAC_Lib",
        "projectId": projectId,
        "protocolId": "1",
        "protocolName": spl['protocolId'],
        "updatedDate": datetime.datetime.now(),
        "createdDate": datetime.datetime.now(),
        "specLibFilename": "PHRT_005_Spec_Lib.tsv",
        "sopFileName": "PHRT_Data_Analysis_SOP",
        "workflowTag": "Library Generation",
        "description": "Generated from Excel archive",
        "proteinDatabaseOrganism": spl['protein_database']['organism'],
        "proteinDatabaseVersion": spl['protein_database']['version']
    }

    print(spectralLibraryDAO.createSpectralLibrary(new_spl))
Example #4
0
def insertLibGenMSRuns(projectId):
    frac_samples = intermediateSampleDAO.getIntermediateSamplesByProjectAndProtocolId(
        "fractionation_preparation", projectId)
    name_counter = 25
    run_counter = 7
    for f in frac_samples:
        if (re.search("^IS_MMA_library_batch-1_mix-*", f['name'])):
            msr_sample = msReadySamplesDAO.getMsReadySampleByIntermediateSampleId(
                f['id'])
            if (len(msr_sample) > 0):
                msr = msr_sample[0]
                new_msrun = {
                    "runId": run_counter,
                    "clinicalSamples": msr['clinicalSamples'],
                    "msReadySampleId": msr['id'],
                    "name": "PHRT_5_sgoetze_C1902_0" + str(name_counter),
                    "projectId": projectId,
                    "protocolId": "DDA_protocol",
                    "instrumentId": "MS:1002877",
                    "instrumentMethod": "Xcalibur methods TP",
                    "sopFileName": "PHRT_Mass_Spectrometry_SOP",
                    "updatedDate": datetime.datetime.now(),
                    "createdDate": datetime.datetime.now(),
                    "workflowTag": "Library Generation",
                    "description": "Generated from Excel archive",
                    "processingPerson": "System",
                }
                name_counter = name_counter + 1
                run_counter = run_counter + 1
                print(MSRunDAO.createMsRun(new_msrun))
Example #5
0
def insertMSRuns(msruns, projectId):
    for i in msruns:
        x = re.search("^sgoetze_A1*", i['name'])
        if x:
            samples = []
            sample_c = clinicalSampleDAO.getClinicalSampleByClinicalSampleCode(
                str(int(i['sample_ref']['sampleIdRef'])))
            if sample_c != None:
                msrs = msReadySamplesDAO.getMsReadySamplesByClinicalSample(
                    sample_c['id'])

            for msr in msrs:
                if len(msr['clinicalSamples']) == 1:
                    new_msrun = {
                        "runId": i['id'],
                        "clinicalSamples": msr['clinicalSamples'],
                        "msReadySampleId": msr['id'],
                        "name": i['name'],
                        "projectId": projectId,
                        "protocolId": i['protocolId'],
                        "instrumentId": i['instrumentId'],
                        "sopFileName": "PHRT_Mass_Spectrometry_SOP",
                        "instrumentMethod": "Xcalibur methods TP",
                        "updatedDate": datetime.datetime.now(),
                        "createdDate": datetime.datetime.now(),
                        "workflowTag": "Sample Preparation",
                        "description": "Generated from Excel archive",
                        "processingPerson": "System",
                    }
                    print(MSRunDAO.createMsRun(new_msrun))
Example #6
0
def deleteRun():
    id = request.args.get('id')
    sts = MSRunDAO.deleteMSrun(id)
    if(sts == 0):
        return 'MS Run with id does not exist.', status.HTTP_404_NOT_FOUND
    else:
        return '', status.HTTP_200_OK
def getAllSpectralLibraries():
    projectId = request.args.get('projectId')

    if (projectDAO.getProjectById(projectId)):
        spec_libs = spectralLibraryDAO.getAllLibrariesForProject(projectId)
        for s in spec_libs:
            augmentedClinicalSamples = clinicalSampleDAO.augmentClinicalSampleNames(
                s['clinicalSamples'])
            augmentedMSRuns = MSRunDAO.augmentMSRunNames(s['msRunIds'])
            s['clinicalSamples'] = augmentedClinicalSamples
            s['msRunIds'] = augmentedMSRuns
        return jsonify(spec_libs), status.HTTP_200_OK
    else:
        return 'Project with id does not exist.', status.HTTP_404_NOT_FOUND
Example #8
0
def getMSRunById():
    id = ObjectId(request.args.get('id'))
    msrun = MSRunDAO.getMsRun(id)
    if(msrun):
        msrun = msrun.dump()
        augmentedClinicalSamples = clinicalSampleDAO.augmentClinicalSampleNames(
            msrun['clinicalSamples'])
        msReadySampleName = msReadySamplesDAO.getMSReadySampleName(
            msrun['msReadySampleId'])
        msrun['clinicalSamples'] = augmentedClinicalSamples
        msrun['msReadySampleName'] = msReadySampleName
        return jsonify(msrun), status.HTTP_200_OK
    else:
        return 'MS Run with id does not exist.', status.HTTP_404_NOT_FOUND
Example #9
0
def getMSRunsByProjectId():
    projectId = request.args.get('projectId')
    if (projectDAO.getProjectById(projectId)):
        msruns = MSRunDAO.getAllMSRunsByProjectId(projectId)
        for msrun in msruns:
            augmentedClinicalSamples = clinicalSampleDAO.augmentClinicalSampleNames(
                msrun['clinicalSamples'])
            msReadySampleName = msReadySamplesDAO.getMSReadySampleName(
                msrun['msReadySampleId'])
            msrun['clinicalSamples'] = augmentedClinicalSamples
            msrun['msReadySampleName'] = msReadySampleName
        return jsonify(msruns), status.HTTP_200_OK
    else:
        return 'Project with id does not exist.', status.HTTP_404_NOT_FOUND
def getAllSwathAnalysis():
    projectId = request.args.get('projectId')

    if (projectDAO.getProjectById(projectId)):
        swath_analysis = swathAnalysisDAO.getSWATHByProject(projectId)
        for s in swath_analysis:
            augmentedClinicalSamples = clinicalSampleDAO.augmentClinicalSampleNames(
                s['clinicalSamples'])
            augmentedMSRuns = MSRunDAO.augmentMSRunNames(
                s['msRunIds'])
            s['clinicalSamples'] = augmentedClinicalSamples
            s['msRunIds'] = augmentedMSRuns
        return jsonify(swath_analysis), status.HTTP_200_OK
    else:
        return 'Project with id does not exist.', status.HTTP_404_NOT_FOUND
Example #11
0
def getMsRunsByClinicalSampleId():
    clinicalSampleId = ObjectId(request.args.get('id'))
    if clinicalSampleDAO.getClinicalSampleById(clinicalSampleId):
        msruns = MSRunDAO.getMsRunsByClinicalSampleId(
            clinicalSampleId)
        for ms_run in msruns:
            augmentedClinicalSamples = clinicalSampleDAO.augmentClinicalSampleNames(
                ms_run['clinicalSamples'])
            msReadySampleName = msReadySamplesDAO.getMSReadySampleName(
                ms_run['msReadySampleId'])
            ms_run['clinicalSamples'] = augmentedClinicalSamples
            ms_run['msReadySampleName'] = msReadySampleName
        return jsonify(msruns), status.HTTP_200_OK
    else:
        return 'Clinical Sample with id does not exist.', status.HTTP_404_NOT_FOUND
Example #12
0
def setMsPrepEntries(sampleJourney, ins):
    msrs = msReadySamplesDAO.getMsReadySampleByIntermediateSampleId(ins['id'])
    if len(msrs) > 0:
        msr = msrs[0]
        msr_name = msr['name']
        sampleJourney.appendMsReadySampleName(msr_name)
        sampleJourney.appendLink(ins['name'], msr_name, "")
        msruns = MSRunDAO.getMsRunsByMSReadySampleId(msr['id'])
        for r in msruns:
            msrun_name = r['name']
            msrun_sop = r['sopFileName']
            sampleJourney.appendMsRunName(msrun_name)
            sampleJourney.appendLink(msr_name, msrun_name, msrun_sop)

            setComputationalEntries(sampleJourney, r)
    return sampleJourney
def generateMassSpecCluster(g, msr):

    msrun = MSRunDAO.getMsRunsByMSREadySampleId(msr['id'])[0]
    if len(msrun) > 0:
        msrun_name = msrun['name']
        msrun_sop = msrun['sopFileName']
        print(msrun_name)

        with g.subgraph(name='cluster_2') as e:
            e.attr(style='filled',
                   color='darkseagreen',
                   minlen='8,5',
                   fixedsize='True')
            e.node_attr.update(style='filled', color='white', shape='box')
            e.node(msrun_name)
            e.attr(label='MASS SPEC')
            g.edge(msr['name'],
                   msrun_name,
                   label=msrun_sop,
                   color='darkgrey',
                   fontsize='10')
        generateComputationalCluster(g, msrun['id'], msrun_name)
Example #14
0
def insertMelanomaJourney(projectId):

    new_sample = {
        "clinicalSampleCode": "FDSG23",
        "name": "PHRT_006_FDSG23_CPAC",
        "sampleCounter": 1,
        "projectId": projectId,
        "processingPerson": "System",
        "description": "Mock sample",
        "workflowTag": "Sample Preparation",
        "updatedDate": datetime.datetime.now(),
        "createdDate": datetime.datetime.now()
    }
    second_sample = {
        "clinicalSampleCode": "RTYD12",
        "name": "PHRT_006_RTYD12_CPAC",
        "sampleCounter": 2,
        "projectId": projectId,
        "processingPerson": "System",
        "description": "Mock sample",
        "workflowTag": "Sample Preparation",
        "updatedDate": datetime.datetime.now(),
        "createdDate": datetime.datetime.now()
    }
    cs1 = clinicalSampleDAO.createClinicalSample(new_sample)
    cs2 = clinicalSampleDAO.createClinicalSample(second_sample)

    is_sample1 = {
        "name": "IS_" + str(cs1['name']) + "_1",
        "projectId": projectId,
        "clinicalSamples": [cs1['id']],
        "workflowTag": "Sample Preparation",
        "protocolName": "fractionation_preparation",
        "sopFileName": "PHRT_Sample_Preparation_SOP",
        "description": "Mock sample",
        "processingPerson": "System",
        "updatedDate": datetime.datetime.now(),
        "createdDate": datetime.datetime.now()
    }
    is_sample2 = {
        "name": "IS_" + str(cs1['name']) + "_2",
        "projectId": projectId,
        "clinicalSamples": [cs1['id']],
        "workflowTag": "Sample Preparation",
        "protocolName": "fractionation_preparation",
        "sopFileName": "PHRT_Sample_Preparation_SOP",
        "description": "Mock sample",
        "processingPerson": "System",
        "updatedDate": datetime.datetime.now(),
        "createdDate": datetime.datetime.now()
    }

    is1 = intermediateSampleDAO.createIntermediateSample(is_sample1)
    is2 = intermediateSampleDAO.createIntermediateSample(is_sample2)

    new_msr1 = {
        "name": "MSR_" + is1['name'],
        "projectId": projectId,
        "clinicalSamples": is1['clinicalSamples'],
        "intermediateSampleId": is1['id'],
        "workflowTag": "Sample Preparation",
        "description": "Mock samples",
        "processingPerson": "System",
        "updatedDate": datetime.datetime.now(),
        "createdDate": datetime.datetime.now()
    }

    new_msr2 = {
        "name": "MSR_" + is2['name'],
        "projectId": projectId,
        "clinicalSamples": is2['clinicalSamples'],
        "intermediateSampleId": is2['id'],
        "workflowTag": "Sample Preparation",
        "description": "Mock samples",
        "processingPerson": "System",
        "updatedDate": datetime.datetime.now(),
        "createdDate": datetime.datetime.now()
    }
    msr1 = msReadySamplesDAO.createMSReadySample(new_msr1)
    msr2 = msReadySamplesDAO.createMSReadySample(new_msr2)

    new_msrun1 = {
        "runId": 1,
        "clinicalSamples": msr1['clinicalSamples'],
        "msReadySampleId": msr1['id'],
        "name": "PHRT_6_salbert_A1902_012",
        "projectId": projectId,
        "protocolId": "DIA",
        "instrumentId": "MS:1002523",
        "instrumentMethod": "Xcalibur methods TP",
        "sopFileName": "PHRT_Mass_Spectrometry_SOP",
        "updatedDate": datetime.datetime.now(),
        "createdDate": datetime.datetime.now(),
        "workflowTag": "Sample Preparation",
        "description": "Mock run",
        "processingPerson": "System"
    }

    new_msrun2 = {
        "runId": 2,
        "clinicalSamples": msr2['clinicalSamples'],
        "msReadySampleId": msr2['id'],
        "name": "PHRT_6_salbert_A1902_045",
        "projectId": projectId,
        "protocolId": "DIA",
        "instrumentId": "MS:1002523",
        "sopFileName": "PHRT_Mass_Spectrometry_SOP",
        "updatedDate": datetime.datetime.now(),
        "instrumentMethod": "Xcalibur methods TP",
        "createdDate": datetime.datetime.now(),
        "workflowTag": "Sample Preparation",
        "description": "Mock run",
        "processingPerson": "System"
    }
    run1 = MSRunDAO.createMsRun(new_msrun1)
    run2 = MSRunDAO.createMsRun(new_msrun2)

    new_spl = {
        "libId": 1,
        "clinicalSamples": is1['clinicalSamples'],
        "msRunIds": [run1['id'], run2['id']],
        "name": "PHRT_001_006_CPAC_Lib",
        "projectId": projectId,
        "protocolId": "1",
        "protocolName": "PHRT_Data_Analysis_SOP",
        "updatedDate": datetime.datetime.now(),
        "createdDate": datetime.datetime.now(),
        "specLibFilename": "PHRT_005_Spec_Lib.tsv",
        "sopFileName": "PHRT_Data_Analysis_SOP",
        "workflowTag": "Library Generation",
        "description": "Mock lib",
        "proteinDatabaseOrganism": "UP000005640",
        "proteinDatabaseVersion": "200812"
    }

    spl = spectralLibraryDAO.createSpectralLibrary(new_spl)

    new_swa = {
        "swathId": 1,
        "clinicalSamples": is1['clinicalSamples'],
        "msRunIds": [run1['id']],
        "name": "PHRT_001_006_CPAC_SWATH",
        "spectralLibraryId": spl['id'],
        "projectId": projectId,
        "protocolId": "1",
        "protocolName": "PHRT_Data_Analysis_SOP",
        "sopFileName": "PHRT_Data_Analysis_SOP",
        "proteinMatrixFileName": "PHRT_006_Protein_Matrix.tsv",
        "updatedDate": datetime.datetime.now(),
        "createdDate": datetime.datetime.now(),
        "workflowTag": "SWATHAnalysis",
        "description": "Mock swath"
    }

    print(swathAnalysisDAO.createSWATHAnalysis(new_swa))