예제 #1
0
 def testToProtocolElement(self):
     dataset = datasets.Dataset('dataset1')
     term = protocol.OntologyTerm()
     term.term = "male genotypic sex"
     term.id = "PATO:0020001"
     term.source_name = "PATO"
     term.source_version = pb.string("2015-11-18")
     # Write out a valid input
     print(protocol.toJsonDict(term))
     validIndividual = protocol.Individual(
         name="test",
         created="2016-05-19T21:00:19Z",
         updated="2016-05-19T21:00:19Z",
         sex=term)
     validIndividual.info['test'].values.add().string_value = 'test-info'
     # pass through protocol creation
     individual = bioMetadata.Individual(
         dataset, "test")
     individual.populateFromJson(protocol.toJson(validIndividual))
     gaIndividual = individual.toProtocolElement()
     # Verify elements exist
     self.assertEqual(gaIndividual.created, validIndividual.created)
     self.assertEqual(gaIndividual.updated, validIndividual.updated)
     # Invalid input
     invalidIndividual = '{"bad:", "json"}'
     individual = bioMetadata.Individual(dataset, "test")
     # Should fail
     self.assertRaises(
         exceptions.InvalidJsonException,
         individual.populateFromJson,
         invalidIndividual)
예제 #2
0
 def testCreation(self):
     dataset = datasets.Dataset('dataset1')
     referenceSet = references.SimulatedReferenceSet("srs1")
     localId = "variantAnnotationSetId"
     simulatedVariantSet = variants.SimulatedVariantSet(
         dataset,
         referenceSet,
         'variantSet1',
         randomSeed=self.randomSeed,
         numCalls=self.numCalls,
         variantDensity=self.variantDensity)
     simulatedVariantAnnotationSet = variants.SimulatedVariantAnnotationSet(
         simulatedVariantSet, localId, self.randomSeed)
     annotations = simulatedVariantAnnotationSet.getVariantAnnotations(
         self.referenceName, self.startPosition, self.endPosition)
     self.assertEquals(
         simulatedVariantSet.toProtocolElement().id,
         simulatedVariantAnnotationSet.toProtocolElement().variant_set_id,
         "Variant Set ID should match the annotation's variant set ID")
     for variant, ann in annotations:
         self.assertEquals(
             datetime.datetime.strptime(
                 ann.created,
                 "%Y-%m-%dT%H:%M:%S.%fZ").strftime("%Y-%m-%dT%H:%M:%S.%fZ"),
             ann.created, "Expect time format to be in ISO8601")
         self.assertEqual(variant.id, ann.variant_id)
예제 #3
0
 def _getSimulatedVariantSet(self):
     dataset = datasets.Dataset('dataset1')
     referenceSet = references.SimulatedReferenceSet("srs1")
     simulatedVariantSet = variants.SimulatedVariantSet(
         dataset, referenceSet, 'variantSet1', randomSeed=self.randomSeed,
         numCalls=self.numCalls, variantDensity=self.variantDensity)
     return simulatedVariantSet
 def testTopLevelIdsUnique(self):
     datasetId = "a"
     idStr = "b"
     dataset = datasets.Dataset(datasetId)
     readGroupSet = reads.AbstractReadGroupSet(dataset, idStr)
     variantSet = variants.AbstractVariantSet(dataset, idStr)
     self.assertNotEqual(readGroupSet.getId(), variantSet.getId())
예제 #5
0
파일: datarepo.py 프로젝트: ejacox/server
 def _readDatasetTable(self):
     for datasetRecord in m.Dataset.select():
         dataset = datasets.Dataset(datasetRecord.name)
         dataset.populateFromRow(datasetRecord)
         assert dataset.getId() == datasetRecord.id
         # Insert the dataset into the memory-based object model.
         self.addDataset(dataset)
예제 #6
0
 def testGetDatasetByIndexBadIndex(self):
     self.assertRaises(IndexError, self._dataRepo.getDatasetByIndex, 0)
     self.assertRaises(TypeError, self._dataRepo.getDatasetByIndex, None)
     self.assertRaises(TypeError, self._dataRepo.getDatasetByIndex, "")
     datasetName = "ds"
     dataset = datasets.Dataset(datasetName)
     self._dataRepo.addDataset(dataset)
     self.assertRaises(IndexError, self._dataRepo.getDatasetByIndex, 1)
예제 #7
0
 def __init__(self, variantSetId, baseDir):
     self._dataset = datasets.Dataset("ds")
     super(VariantSetTest, self).__init__(variantSetId, baseDir)
     self._variantRecords = []
     self._reference_names = set()
     # Read in all the VCF files in datadir and store each variant.
     for vcfFile in glob.glob(os.path.join(self._dataPath, "*.vcf.gz")):
         self._readVcf(vcfFile)
예제 #8
0
 def __init__(self, rnaQuantificationLocalId, baseDir):
     self._dataset = datasets.Dataset(_datasetName)
     self._repo = datarepo.SqlDataRepository(paths.testDataRepo)
     self._repo.open(datarepo.MODE_READ)
     self._referenceSet = references.AbstractReferenceSet("test_rs")
     rnaQuantificationId = rnaQuantificationLocalId[:-3]  # remove '.db'
     super(RnaQuantificationTest, self).__init__(rnaQuantificationId,
                                                 baseDir)
예제 #9
0
 def testCreation(self):
     dataset = datasets.Dataset('dataset1')
     localId = "readGroupSetId"
     referenceSet = references.SimulatedReferenceSet("srs1")
     simulatedReadGroupSet = reads.SimulatedReadGroupSet(
         dataset, localId, referenceSet)
     for readGroup in simulatedReadGroupSet.getReadGroups():
         alignments = list(readGroup.getReadAlignments())
         self.assertGreater(len(alignments), 0)
예제 #10
0
 def addDataset(self):
     """
     Adds a new dataset into this repo.
     """
     self._openRepo()
     dataset = datasets.Dataset(self._args.datasetName)
     dataset.setDescription(self._args.description)
     dataset.setAttributes(json.loads(self._args.attributes))
     self._updateRepo(self._repo.insertDataset, dataset)
    def testToProtocolElement(self):
        dataset = datasets.Dataset('dataset1')
        validFusionDetection = protocol.FusionDetection(
            name="test",
            created="2016-05-19T21:00:19Z",
            updated="2016-05-19T21:00:19Z",
            fusionDetectionId="n/a",
            fusionDetectionIdTier=0,
            sampleId="n/a",
            sampleIdTier=0,
            inHousePipeline="n/a",
            inHousePipelineTier=0,
            svDetection="n/a",
            svDetectionTier=0,
            fusionDetection="n/a",
            fusionDetectionTier=0,
            realignment="n/a",
            realignmentTier=0,
            annotation="n/a",
            annotationTier=0,
            genomeReference="n/a",
            genomeReferenceTier=0,
            geneModels="n/a",
            geneModelsTier=0,
            alignmentId="n/a",
            alignmentIdTier=0,
            site="n/a",
            siteTier=0)

        validFusionDetection.attributes.attr['test']. \
            values.add().string_value = 'test-info'

        # pass through protocol creation
        fusionDetection = pipeMetadata.FusionDetection(dataset, "test")
        fusionDetection.populateFromJson(protocol.toJson(validFusionDetection))
        gaFusionDetection = fusionDetection.toProtocolElement()
        # Verify select elements exist
        self.assertEqual(gaFusionDetection.created,
                         validFusionDetection.created)
        self.assertEqual(gaFusionDetection.updated,
                         validFusionDetection.updated)
        self.assertEqual(gaFusionDetection.fusionDetectionId,
                         validFusionDetection.fusionDetectionId)
        self.assertEqual(gaFusionDetection.sampleId,
                         validFusionDetection.sampleId)
        self.assertEqual(gaFusionDetection.site, validFusionDetection.site)
        self.assertEqual(gaFusionDetection.fusionDetectionTier,
                         validFusionDetection.fusionDetectionTier)

        # Invalid input
        invalidFusionDetection = '{"bad:", "json"}'
        fusionDetection = pipeMetadata.FusionDetection(dataset, "test")
        # Should fail
        self.assertRaises(exceptions.InvalidJsonException,
                          fusionDetection.populateFromJson,
                          invalidFusionDetection)
예제 #12
0
 def _createContinuousSet(self):
     """
     Creates a ContinuousSet from the specified directory.
     """
     self._continuousSetName = "testContinuous"
     self._repo = datarepo.SqlDataRepository(paths.testDataRepo)
     self._repo.open(datarepo.MODE_READ)
     self._dataset = datasets.Dataset("testDs")
     self._continuousSet = continuous.readSet(
         self._dataset, self._continuousSetName)
예제 #13
0
 def __init__(self, localId, dataPath):
     self._backend = backend.Backend(datarepo.AbstractDataRepository())
     self._referenceSet = None
     self._dataset = datasets.Dataset("ds")
     self._readGroupInfos = {}
     self._readGroupSetInfo = None
     self._samFile = pysam.AlignmentFile(dataPath)
     self._readReferences()
     super(ReadGroupSetTest, self).__init__(localId, dataPath)
     self._readAlignmentInfo()
    def testToProtocolElement(self):
        dataset = datasets.Dataset('dataset1')
        validExpressionAnalysis = protocol.ExpressionAnalysis(
            name="test",
            created="2016-05-19T21:00:19Z",
            updated="2016-05-19T21:00:19Z",
            expressionAnalysisId="n/a",
            expressionAnalysisIdTier=0,
            sampleId="n/a",
            sampleIdTier=0,
            readLength="n/a",
            readLengthTier=0,
            reference="n/a",
            referenceTier=0,
            alignmentTool="n/a",
            alignmentToolTier=0,
            bamHandling="n/a",
            bamHandlingTier=0,
            expressionEstimation="n/a",
            expressionEstimationTier=0,
            sequencingId="n/a",
            sequencingIdTier=0,
            site="n/a",
            siteTier=0)

        validExpressionAnalysis.attributes.attr['test']. \
            values.add().string_value = 'test-info'

        # pass through protocol creation
        expressionAnalysis = pipeMetadata.ExpressionAnalysis(dataset, "test")
        expressionAnalysis.populateFromJson(
            protocol.toJson(validExpressionAnalysis))
        gaExpressionAnalysis = expressionAnalysis.toProtocolElement()
        # Verify select elements exist
        self.assertEqual(gaExpressionAnalysis.created,
                         validExpressionAnalysis.created)
        self.assertEqual(gaExpressionAnalysis.updated,
                         validExpressionAnalysis.updated)
        self.assertEqual(gaExpressionAnalysis.expressionAnalysisId,
                         validExpressionAnalysis.expressionAnalysisId)
        self.assertEqual(gaExpressionAnalysis.sampleId,
                         validExpressionAnalysis.sampleId)
        self.assertEqual(gaExpressionAnalysis.site,
                         validExpressionAnalysis.site)
        self.assertEqual(gaExpressionAnalysis.bamHandlingTier,
                         validExpressionAnalysis.bamHandlingTier)

        # Invalid input
        invalidExpressionAnalysis = '{"bad:", "json"}'
        expressionAnalysis = pipeMetadata.ExpressionAnalysis(dataset, "test")
        # Should fail
        self.assertRaises(exceptions.InvalidJsonException,
                          expressionAnalysis.populateFromJson,
                          invalidExpressionAnalysis)
예제 #15
0
 def testAddOneDataset(self):
     datasetName = "ds"
     dataset = datasets.Dataset(datasetName)
     self.assertEqual(self._dataRepo.getNumDatasets(), 0)
     self.assertEqual(self._dataRepo.getDatasets(), [])
     self._dataRepo.addDataset(dataset)
     self.assertEqual(self._dataRepo.getNumDatasets(), 1)
     self.assertEqual(self._dataRepo.getDatasets(), [dataset])
     self.assertEqual(self._dataRepo.getDatasetByIndex(0), dataset)
     self.assertEqual(self._dataRepo.getDatasetByName(datasetName), dataset)
     self.assertEqual(self._dataRepo.getDataset(dataset.getId()), dataset)
예제 #16
0
 def testAddMultipleDatasets(self):
     firstDatasetName = "ds1"
     firstDataset = datasets.Dataset(firstDatasetName)
     secondDatasetName = "ds2"
     secondDataset = datasets.Dataset(secondDatasetName)
     self.assertEqual(self._dataRepo.getNumDatasets(), 0)
     self.assertEqual(self._dataRepo.getDatasets(), [])
     self._dataRepo.addDataset(firstDataset)
     self._dataRepo.addDataset(secondDataset)
     self.assertEqual(self._dataRepo.getNumDatasets(), 2)
     self.assertEqual(self._dataRepo.getDatasets(),
                      [firstDataset, secondDataset])
     self.assertEqual(self._dataRepo.getDatasetByIndex(0), firstDataset)
     self.assertEqual(self._dataRepo.getDatasetByIndex(1), secondDataset)
     self.assertEqual(self._dataRepo.getDatasetByName(firstDatasetName),
                      firstDataset)
     self.assertEqual(self._dataRepo.getDatasetByName(secondDatasetName),
                      secondDataset)
     self.assertEqual(self._dataRepo.getDataset(firstDataset.getId()),
                      firstDataset)
     self.assertEqual(self._dataRepo.getDataset(secondDataset.getId()),
                      secondDataset)
    def testToProtocolElement(self):
        dataset = datasets.Dataset('dataset1')
        validSurgery = protocol.Surgery(name="test",
                                        created="2016-05-19T21:00:19Z",
                                        updated="2016-05-19T21:00:19Z",
                                        patientId="PATIENT_TEST",
                                        patientIdTier=0,
                                        startDate="n/a",
                                        startDateTier=0,
                                        stopDate="n/a",
                                        stopDateTier=0,
                                        sampleId="n/a",
                                        sampleIdTier=0,
                                        collectionTimePoint="n/a",
                                        collectionTimePointTier=0,
                                        diagnosisDate="n/a",
                                        diagnosisDateTier=0,
                                        site="n/a",
                                        siteTier=0,
                                        type="n/a",
                                        typeTier=0,
                                        recordingDate="n/a",
                                        recordingDateTier=0,
                                        treatmentPlanId="n/a",
                                        treatmentPlanIdTier=0,
                                        courseNumber="1",
                                        courseNumberTier=0)

        validSurgery.attributes.attr['test']. \
            values.add().string_value = 'test-info'

        # pass through protocol creation
        surgery = clinMetadata.Surgery(dataset, "test")
        surgery.populateFromJson(protocol.toJson(validSurgery))
        gaSurgery = surgery.toProtocolElement()
        # Verify select elements exist
        self.assertEqual(gaSurgery.created, validSurgery.created)
        self.assertEqual(gaSurgery.updated, validSurgery.updated)
        self.assertEqual(gaSurgery.patientId, validSurgery.patientId)
        self.assertEqual(gaSurgery.collectionTimePoint,
                         validSurgery.collectionTimePoint)
        self.assertEqual(gaSurgery.recordingDate, validSurgery.recordingDate)
        self.assertEqual(gaSurgery.treatmentPlanIdTier,
                         validSurgery.treatmentPlanIdTier)

        # Invalid input
        invalidSurgery = '{"bad:", "json"}'
        surgery = clinMetadata.Surgery(dataset, "test")
        # Should fail
        self.assertRaises(exceptions.InvalidJsonException,
                          surgery.populateFromJson, invalidSurgery)
    def testToProtocolElement(self):
        dataset = datasets.Dataset('dataset1')
        validTreatment = protocol.Treatment(
            name="test",
            created="2016-05-19T21:00:19Z",
            updated="2016-05-19T21:00:19Z",
            patientId="PATIENT_TEST",
            patientIdTier=0,
            courseNumber="n/a",
            courseNumberTier=0,
            therapeuticModality="n/a",
            therapeuticModalityTier=0,
            treatmentPlanType="n/a",
            treatmentPlanTypeTier=0,
            treatmentIntent="n/a",
            treatmentIntentTier=0,
            startDate="n/a",
            startDateTier=0,
            stopDate="n/a",
            stopDateTier=0,
            reasonForEndingTheTreatment="n/a",
            reasonForEndingTheTreatmentTier=0,
            responseToTreatment="n/a",
            responseToTreatmentTier=0,
            responseCriteriaUsed="n/a",
            responseCriteriaUsedTier=0,
            dateOfRecurrenceOrProgressionAfterThisTreatment="n/a",
            dateOfRecurrenceOrProgressionAfterThisTreatmentTier=0,
            unexpectedOrUnusualToxicityDuringTreatment="n/a",
            unexpectedOrUnusualToxicityDuringTreatmentTier=0)

        validTreatment.attributes.attr['test']. \
            values.add().string_value = 'test-info'

        # pass through protocol creation
        treatment = clinMetadata.Treatment(dataset, "test")
        treatment.populateFromJson(protocol.toJson(validTreatment))
        gaTreatment = treatment.toProtocolElement()
        # Verify select elements exist
        self.assertEqual(gaTreatment.created, validTreatment.created)
        self.assertEqual(gaTreatment.updated, validTreatment.updated)
        self.assertEqual(gaTreatment.patientId, validTreatment.patientId)
        self.assertEqual(gaTreatment.courseNumber, validTreatment.courseNumber)
        self.assertEqual(gaTreatment.startDate, validTreatment.startDate)

        # Invalid input
        invalidTreatment = '{"bad:", "json"}'
        treatment = clinMetadata.Treatment(dataset, "test")
        # Should fail
        self.assertRaises(exceptions.InvalidJsonException,
                          treatment.populateFromJson, invalidTreatment)
    def testToProtocolElement(self):
        dataset = datasets.Dataset('dataset1')
        validSequencing = protocol.Sequencing(name="test",
                                              created="2016-05-19T21:00:19Z",
                                              updated="2016-05-19T21:00:19Z",
                                              sequencingId="Sequencing_TEST",
                                              sequencingIdTier=0,
                                              sampleId="Sample_test",
                                              sampleIdTier=0,
                                              dnaLibraryKit="n/a",
                                              dnaLibraryKitTier=0,
                                              dnaSeqPlatform="n/a",
                                              dnaSeqPlatformTier=0,
                                              dnaReadLength="n/a",
                                              dnaReadLengthTier=0,
                                              rnaLibraryKit="n/a",
                                              rnaLibraryKitTier=0,
                                              rnaSeqPlatform="n/a",
                                              rnaSeqPlatformTier=0,
                                              rnaReadLength="n/a",
                                              rnaReadLengthTier=0,
                                              pcrCycles="n/a",
                                              pcrCyclesTier=0,
                                              extractionId="n/a",
                                              extractionIdTier=0,
                                              site="Toronto",
                                              siteTier=0)

        validSequencing.attributes.attr['test']. \
            values.add().string_value = 'test-info'

        # pass through protocol creation
        sequencing = pipeMetadata.Sequencing(dataset, "test")
        sequencing.populateFromJson(protocol.toJson(validSequencing))
        gaSequencing = sequencing.toProtocolElement()
        # Verify select elements exist
        self.assertEqual(gaSequencing.created, validSequencing.created)
        self.assertEqual(gaSequencing.updated, validSequencing.updated)
        self.assertEqual(gaSequencing.sequencingId,
                         validSequencing.sequencingId)
        self.assertEqual(gaSequencing.sampleId, validSequencing.sampleId)
        self.assertEqual(gaSequencing.site, validSequencing.site)
        self.assertEqual(gaSequencing.sampleIdTier,
                         validSequencing.sampleIdTier)

        # Invalid input
        invalidSequencing = '{"bad:", "json"}'
        sequencing = pipeMetadata.Sequencing(dataset, "test")
        # Should fail
        self.assertRaises(exceptions.InvalidJsonException,
                          sequencing.populateFromJson, invalidSequencing)
예제 #20
0
 def getDataModelInstance(self, localId, dataPath):
     dataset = datasets.Dataset("ds")
     variantSet = variants.HtslibVariantSet(dataset, localId)
     variantSet.populateFromDirectory(dataPath)
     referenceSet = references.AbstractReferenceSet("rs")
     variantSet.setReferenceSet(referenceSet)
     if variantSet.isAnnotated():
         sequenceOntology = ontologies.Ontology(paths.ontologyName)
         sequenceOntology.populateFromFile(paths.ontologyPath)
         annotationSet = variantSet.getVariantAnnotationSets()[0]
         annotationSet.setOntology(sequenceOntology)
         return annotationSet
     else:
         return variantSet
예제 #21
0
 def __init__(self, featureSetLocalName, dataPath):
     """
     :param localId: Name of the GFF3 resource corresponding to a pair
     of files, .db and .gff3
     :param dataPath: string representing full path to the .db file
     :return:
     """
     self._dataset = datasets.Dataset(_datasetName)
     self._repo = datarepo.SqlDataRepository(paths.testDataRepo)
     self._repo.open(datarepo.MODE_READ)
     self._ontology = self._repo.getOntologyByName(paths.ontologyName)
     self._referenceSet = references.AbstractReferenceSet("test_rs")
     featureSetLocalName = featureSetLocalName[:-3]  # remove '.db'
     self._testData = _testDataForFeatureSetName[featureSetLocalName]
     super(FeatureSetTests, self).__init__(featureSetLocalName, dataPath)
 def _createVariantAnnotationSet(self, vcfDir):
     """
     Creates a VariantAnnotationSet from the specified directory of
     VCF files.
     """
     self._variantSetName = "testVariantSet"
     self._repo = datarepo.SqlDataRepository(paths.testDataRepo)
     self._repo.open(datarepo.MODE_READ)
     self._dataset = datasets.Dataset("testDs")
     self._variantSet = variants.HtslibVariantSet(
         self._dataset, self._variantSetName)
     self._variantSet.populateFromDirectory(vcfDir)
     self._variantAnnotationSet = variants.HtslibVariantAnnotationSet(
         self._variantSet, "testVAs")
     self._variantAnnotationSet.setOntology(
         self._repo.getOntologyByName(paths.ontologyName))
    def testToProtocolElement(self):
        dataset = datasets.Dataset('dataset1')
        validImmunotherapy = protocol.Immunotherapy(
            name="test",
            created="2016-05-19T21:00:19Z",
            updated="2016-05-19T21:00:19Z",
            patientId="PATIENT_TEST",
            patientIdTier=0,
            startDate="n/a",
            startDateTier=0,
            immunotherapyType="n/a",
            immunotherapyTypeTier=0,
            immunotherapyTarget="n/a",
            immunotherapyTargetTier=0,
            immunotherapyDetail="n/a",
            immunotherapyDetailTier=0,
            treatmentPlanId="n/a",
            treatmentPlanIdTier=0,
            courseNumber="1",
            courseNumberTier=0)

        validImmunotherapy.attributes.attr['test']. \
            values.add().string_value = 'test-info'

        # pass through protocol creation
        immunotherapy = clinMetadata.Immunotherapy(dataset, "test")
        immunotherapy.populateFromJson(protocol.toJson(validImmunotherapy))
        gaImmunotherapy = immunotherapy.toProtocolElement()
        # Verify select elements exist
        self.assertEqual(gaImmunotherapy.created, validImmunotherapy.created)
        self.assertEqual(gaImmunotherapy.updated, validImmunotherapy.updated)
        self.assertEqual(gaImmunotherapy.patientId,
                         validImmunotherapy.patientId)
        self.assertEqual(gaImmunotherapy.immunotherapyType,
                         validImmunotherapy.immunotherapyType)
        self.assertEqual(gaImmunotherapy.immunotherapyDetailTier,
                         validImmunotherapy.immunotherapyDetailTier)
        self.assertEqual(gaImmunotherapy.treatmentPlanId,
                         validImmunotherapy.treatmentPlanId)

        # Invalid input
        invalidImmunotherapy = '{"bad:", "json"}'
        immunotherapy = clinMetadata.Immunotherapy(dataset, "test")
        # Should fail
        self.assertRaises(exceptions.InvalidJsonException,
                          immunotherapy.populateFromJson, invalidImmunotherapy)
    def testToProtocolElement(self):
        dataset = datasets.Dataset('dataset1')
        validLabtest = protocol.Labtest(
            name="test",
            created="2016-05-19T21:00:19Z",
            updated="2016-05-19T21:00:19Z",
            patientId="PATIENT_TEST",
            patientIdTier=0,
            startDate="n/a",
            startDateTier=0,
            collectionDate="n/a",
            collectionDateTier=0,
            endDate="n/a",
            endDateTier=0,
            eventType="n/a",
            eventTypeTier=0,
            testResults="n/a",
            testResultsTier=0,
            timePoint="n/a",
            timePointTier=0,
            recordingDate="n/a",
            recordingDateTier=0,
        )

        validLabtest.attributes.attr['test']. \
            values.add().string_value = 'test-info'

        # pass through protocol creation
        labtest = clinMetadata.Labtest(dataset, "test")
        labtest.populateFromJson(protocol.toJson(validLabtest))
        gaLabtest = labtest.toProtocolElement()
        # Verify select elements exist
        self.assertEqual(gaLabtest.created, validLabtest.created)
        self.assertEqual(gaLabtest.updated, validLabtest.updated)
        self.assertEqual(gaLabtest.patientId, validLabtest.patientId)
        self.assertEqual(gaLabtest.eventType, validLabtest.eventType)
        self.assertEqual(gaLabtest.collectionDate, validLabtest.collectionDate)
        self.assertEqual(gaLabtest.recordingDateTier,
                         validLabtest.recordingDateTier)

        # Invalid input
        invalidLabtest = '{"bad:", "json"}'
        labtest = clinMetadata.Labtest(dataset, "test")
        # Should fail
        self.assertRaises(exceptions.InvalidJsonException,
                          labtest.populateFromJson, invalidLabtest)
    def createRepo(self):
        """
        Creates the repository for all the data we've just downloaded.
        """
        repo = datarepo.SqlDataRepository(self.repoPath)
        repo.open("w")
        repo.initialise()

        referenceSet = references.HtslibReferenceSet("GRCh37-subset")
        referenceSet.populateFromFile(self.fastaFilePath)
        referenceSet.setDescription("Subset of GRCh37 used for demonstration")
        referenceSet.setSpeciesFromJson(
            '{"id": "9606",' +
            '"term": "H**o sapiens", "source_name": "NCBI"}')
        for reference in referenceSet.getReferences():
            reference.setSpeciesFromJson(
                '{"id": "9606",' +
                '"term": "H**o sapiens", "source_name": "NCBI"}')
            reference.setSourceAccessions(
                self.accessions[reference.getName()] + ".subset")
        repo.insertReferenceSet(referenceSet)

        dataset = datasets.Dataset("1kg-p3-subset")
        dataset.setDescription("Sample data from 1000 Genomes phase 3")
        repo.insertDataset(dataset)

        variantSet = variants.HtslibVariantSet(dataset, "mvncall")
        variantSet.setReferenceSet(referenceSet)
        dataUrls = [vcfFile for vcfFile, _ in self.vcfFilePaths]
        indexFiles = [indexFile for _, indexFile in self.vcfFilePaths]
        variantSet.populateFromFile(dataUrls, indexFiles)
        variantSet.checkConsistency()
        repo.insertVariantSet(variantSet)

        for sample, (bamFile, indexFile) in zip(self.samples,
                                                self.bamFilePaths):
            readGroupSet = reads.HtslibReadGroupSet(dataset, sample)
            readGroupSet.populateFromFile(bamFile, indexFile)
            readGroupSet.setReferenceSet(referenceSet)
            repo.insertReadGroupSet(readGroupSet)

        repo.commit()
        repo.close()
        self.log("Finished creating the repository; summary:\n")
        repo.open("r")
        repo.printSummary()
    def testToProtocolElement(self):
        dataset = datasets.Dataset('dataset1')
        validCelltransplant = protocol.Celltransplant(
            name="test",
            created="2016-05-19T21:00:19Z",
            updated="2016-05-19T21:00:19Z",
            patientId="PATIENT_TEST",
            patientIdTier=0,
            startDate="n/a",
            startDateTier=0,
            cellSource="n/a",
            cellSourceTier=0,
            donorType="n/a",
            donorTypeTier=0,
            treatmentPlanId="PATIENT_TEST_1",
            treatmentPlanIdTier=0,
            courseNumber="1",
            courseNumberTier=0)

        validCelltransplant.attributes.attr['test']. \
            values.add().string_value = 'test-info'

        # pass through protocol creation
        celltransplant = clinMetadata.Celltransplant(dataset, "test")
        celltransplant.populateFromJson(protocol.toJson(validCelltransplant))
        gaCelltransplant = celltransplant.toProtocolElement()
        # Verify select elements exist
        self.assertEqual(gaCelltransplant.created, validCelltransplant.created)
        self.assertEqual(gaCelltransplant.updated, validCelltransplant.updated)
        self.assertEqual(gaCelltransplant.patientId,
                         validCelltransplant.patientId)
        self.assertEqual(gaCelltransplant.cellSource,
                         validCelltransplant.cellSource)
        self.assertEqual(gaCelltransplant.courseNumber,
                         validCelltransplant.courseNumber)
        self.assertEqual(gaCelltransplant.treatmentPlanId,
                         validCelltransplant.treatmentPlanId)

        # Invalid input
        invalidCelltransplant = '{"bad:", "json"}'
        celltransplant = clinMetadata.Celltransplant(dataset, "test")
        # Should fail
        self.assertRaises(exceptions.InvalidJsonException,
                          celltransplant.populateFromJson,
                          invalidCelltransplant)
    def testToProtocolElement(self):
        dataset = datasets.Dataset('dataset1')
        validExtraction = protocol.Extraction(name="test",
                                              created="2016-05-19T21:00:19Z",
                                              updated="2016-05-19T21:00:19Z",
                                              extractionId="EXTRACTION_TEST",
                                              extractionIdTier=0,
                                              sampleId="n/a",
                                              sampleIdTier=0,
                                              rnaBlood="n/a",
                                              rnaBloodTier=0,
                                              dnaBlood="n/a",
                                              dnaBloodTier=0,
                                              rnaTissue="n/a",
                                              rnaTissueTier=0,
                                              dnaTissue="n/a",
                                              dnaTissueTier=0,
                                              site="Vancouver",
                                              siteTier=0)

        validExtraction.attributes.attr['test']. \
            values.add().string_value = 'test-info'

        # pass through protocol creation
        extraction = pipeMetadata.Extraction(dataset, "test")
        extraction.populateFromJson(protocol.toJson(validExtraction))
        gaExtraction = extraction.toProtocolElement()
        # Verify select elements exist
        self.assertEqual(gaExtraction.created, validExtraction.created)
        self.assertEqual(gaExtraction.updated, validExtraction.updated)
        self.assertEqual(gaExtraction.extractionId,
                         validExtraction.extractionId)
        self.assertEqual(gaExtraction.sampleId, validExtraction.sampleId)
        self.assertEqual(gaExtraction.site, validExtraction.site)
        self.assertEqual(gaExtraction.sampleIdTier,
                         validExtraction.sampleIdTier)

        # Invalid input
        invalidExtraction = '{"bad:", "json"}'
        extraction = pipeMetadata.Extraction(dataset, "test")
        # Should fail
        self.assertRaises(exceptions.InvalidJsonException,
                          extraction.populateFromJson, invalidExtraction)
    def testToProtocolElement(self):
        dataset = datasets.Dataset('dataset1')
        validComplication = protocol.Complication(
            name="test",
            created="2016-05-19T21:00:19Z",
            updated="2016-05-19T21:00:19Z",
            patientId="PATIENT_TEST",
            patientIdTier=0,
            date="n/a",
            dateTier=0,
            lateComplicationOfTherapyDeveloped="n/a",
            lateComplicationOfTherapyDevelopedTier=0,
            lateToxicityDetail="n/a",
            lateToxicityDetailTier=0,
            suspectedTreatmentInducedNeoplasmDeveloped="n/a",
            suspectedTreatmentInducedNeoplasmDevelopedTier=0,
            treatmentInducedNeoplasmDetails="n/a",
            treatmentInducedNeoplasmDetailsTier=0)

        validComplication.attributes.attr['test']. \
            values.add().string_value = 'test-info'

        # pass through protocol creation
        complication = clinMetadata.Complication(dataset, "test")
        complication.populateFromJson(protocol.toJson(validComplication))
        gaComplication = complication.toProtocolElement()
        # Verify select elements exist
        self.assertEqual(gaComplication.created, validComplication.created)
        self.assertEqual(gaComplication.updated, validComplication.updated)
        self.assertEqual(gaComplication.patientId, validComplication.patientId)
        self.assertEqual(gaComplication.date, validComplication.date)
        self.assertEqual(gaComplication.lateToxicityDetail,
                         validComplication.lateToxicityDetail)
        self.assertEqual(gaComplication.treatmentInducedNeoplasmDetailsTier,
                         validComplication.treatmentInducedNeoplasmDetailsTier)

        # Invalid input
        invalidComplication = '{"bad:", "json"}'
        complication = clinMetadata.Complication(dataset, "test")
        # Should fail
        self.assertRaises(exceptions.InvalidJsonException,
                          complication.populateFromJson, invalidComplication)
 def testToProtocolElement(self):
     dataset = datasets.Dataset('dataset1')
     # Write out a valid input
     validBiosample = protocol.Biosample(name="test",
                                         created="2016-05-19T21:00:19Z",
                                         updated="2016-05-19T21:00:19Z")
     validBiosample.attributes.attr['test']. \
         values.add().string_value = 'test-info'
     # pass through protocol creation
     biosample = bioMetadata.Biosample(dataset, "test")
     biosample.populateFromJson(protocol.toJson(validBiosample))
     gaBiosample = biosample.toProtocolElement()
     # Verify elements exist
     self.assertEqual(gaBiosample.created, validBiosample.created)
     self.assertEqual(gaBiosample.updated, validBiosample.updated)
     # Invalid input
     invalidBiosample = '{"bad:", "json"}'
     biosample = bioMetadata.Individual(dataset, "test")
     # Should fail
     self.assertRaises(exceptions.InvalidJsonException,
                       biosample.populateFromJson, invalidBiosample)
    def testToProtocolElement(self):
        dataset = datasets.Dataset('dataset1')
        validStudy = protocol.Study(name="test",
                                    created="2016-05-19T21:00:19Z",
                                    updated="2016-05-19T21:00:19Z",
                                    patientId="PATIENT_TEST",
                                    patientIdTier=0,
                                    startDate="n/a",
                                    startDateTier=0,
                                    endDate="n/a",
                                    endDateTier=0,
                                    status="n/a",
                                    statusTier=0,
                                    recordingDate="n/a",
                                    recordingDateTier=0)

        validStudy.attributes.attr['test']. \
            values.add().string_value = 'test-info'

        # pass through protocol creation
        study = clinMetadata.Study(dataset, "test")
        study.populateFromJson(protocol.toJson(validStudy))
        gaStudy = study.toProtocolElement()
        # Verify select elements exist
        self.assertEqual(gaStudy.created, validStudy.created)
        self.assertEqual(gaStudy.updated, validStudy.updated)
        self.assertEqual(gaStudy.patientId, validStudy.patientId)
        self.assertEqual(gaStudy.startDate, validStudy.startDate)
        self.assertEqual(gaStudy.status, validStudy.status)
        self.assertEqual(gaStudy.recordingDateTier,
                         validStudy.recordingDateTier)

        # Invalid input
        invalidStudy = '{"bad:", "json"}'
        study = clinMetadata.Study(dataset, "test")
        # Should fail
        self.assertRaises(exceptions.InvalidJsonException,
                          study.populateFromJson, invalidStudy)