コード例 #1
0
 def testToProtocolElement(self):
     dataset = datasets.Dataset('dataset1')
     term = protocol.OntologyTerm()
     term.term = "male genotypic sex"
     term.term_id = "PATO:0020001"
     # 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.attributes.attr['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
ファイル: test_cli.py プロジェクト: saupchurch/server
 def setUp(self):
     self.parser = cli_repomanager.RepoManager.getParser()
     self.registryPath = 'a/repo/path'
     self.datasetName = "datasetName"
     self.filePath = 'a/file/path'
     self.dirPath = 'a/dir/path/'
     self.individualName = "test"
     self.biosampleName = "test"
     self.individual = protocol.toJson(
         protocol.Individual(name="test",
                             created="2016-05-19T21:00:19Z",
                             updated="2016-05-19T21:00:19Z"))
     self.biosample = protocol.toJson(
         protocol.Biosample(name="test",
                            created="2016-05-19T21:00:19Z",
                            updated="2016-05-19T21:00:19Z"))
コード例 #3
0
 def toProtocolElement(self):
     species = None
     sex = None
     if self.getSpecies():
         species = protocol.fromJson(json.dumps(self.getSpecies()),
                                     protocol.OntologyTerm)
     if self.getSex():
         sex = protocol.fromJson(json.dumps(self.getSex()),
                                 protocol.OntologyTerm)
     gaIndividual = protocol.Individual(dataset_id=self._datasetId,
                                        created=self.getCreated(),
                                        updated=self.getUpdated(),
                                        description=self.getDescription(),
                                        id=self.getId(),
                                        name=self.getName(),
                                        species=species,
                                        sex=sex)
     self.serializeAttributes(gaIndividual)
     return gaIndividual
コード例 #4
0
class RepoManagerEndToEndTest(unittest.TestCase):

    datasetName = 'datasetOne'
    metadata = {'description': 'aDescription'}
    individualName = "test"
    biosampleName = "test"
    individual = protocol.toJson(protocol.Individual(
        name="test",
        created="2016-05-19T21:00:19Z",
        updated="2016-05-19T21:00:19Z"))
    biosample = protocol.toJson(protocol.Biosample(
        name="test",
        created="2016-05-19T21:00:19Z",
        updated="2016-05-19T21:00:19Z"))
    attributes = {"key1": "value1", "key2": "value2"}

    def setUp(self):
        _, self.repoFile = tempfile.mkstemp(
            prefix='ga4gh_repo_manager_end2end_test')
        os.unlink(self.repoFile)

    def tearDown(self):
        if os.path.exists(self.repoFile):
            os.unlink(self.repoFile)

    def _runCmd(self, cmd, *args):
        command = [cmd, self.repoFile] + list(args)
        cli_repomanager.repo_main(command)

    def testEndToEnd(self):
        self._runCmd("init")
        self._runCmd("add-ontology", paths.ontologyPath)
        self._runCmd(
            "add-referenceset", paths.faPath,
            '-n', paths.referenceSetName,
            '-A', json.dumps(self.attributes))
        self._runCmd("add-dataset", self.datasetName,
                     '-A', json.dumps(self.attributes))
        self._runCmd("add-biosample",
                     self.datasetName,
                     self.biosampleName,
                     self.biosample)
        self._runCmd("add-individual",
                     self.datasetName,
                     self.individualName,
                     self.individual)
        self._runCmd(
            "add-readgroupset", self.datasetName, "patient1", "sample1", paths.bamPath,
            '-R', paths.referenceSetName, '-n', paths.readGroupSetName,
            '-A', json.dumps(self.attributes))
        self._runCmd(
            "add-featureset", self.datasetName, paths.featuresPath,
            '-R', paths.referenceSetName, '-O', paths.ontologyName,
            '-A', json.dumps(self.attributes))
        # ensure we can handle trailing slashes
        vcfPath = paths.vcfDirPath + '/'
        self._runCmd(
            "add-variantset", self.datasetName,
            'patient1', 'sample1',
            vcfPath, '-R', paths.referenceSetName,
            '-A', json.dumps(self.attributes))
        variantAnnotationSetName = "vas"
        self._runCmd(
            "add-variantset", self.datasetName,
            'patient1', 'sample1',
            paths.annotatedVcfPath, '-R', paths.referenceSetName,
            "-aO", paths.ontologyName, "-n", variantAnnotationSetName,
            '-A', json.dumps(self.attributes))
        phenotypeAssociationSetName = "paSet"
        self._runCmd(
            "add-phenotypeassociationset",
            self.datasetName,
            paths.phenotypeAssociationSetPath,
            "-n",
            phenotypeAssociationSetName,
            '-A', json.dumps(self.attributes))

        self._runCmd("verify")
        self._runCmd("list")
        self._runCmd(
            "remove-phenotypeassociationset",
            self.datasetName, phenotypeAssociationSetName, "-f")
        self._runCmd(
            "remove-variantset", self.datasetName, paths.variantSetName, "-f")
        self._runCmd(
            "remove-variantset", self.datasetName, variantAnnotationSetName,
            "-f")
        self._runCmd(
            "remove-readgroupset", self.datasetName,
            paths.readGroupSetName, "-f")
        self._runCmd(
            "remove-featureset", self.datasetName, paths.featureSetName,
            "-f")
        self._runCmd(
            "remove-dataset", self.datasetName, "-f")
        self._runCmd(
            "remove-referenceset", paths.referenceSetName, "-f")
        self._runCmd(
            "remove-ontology", paths.ontologyName, "-f")

    def testForce(self):
        datasetName = 'dataset1'
        self._runCmd("init")
        self._runCmd("add-dataset", datasetName)
        with mock.patch(
                'ga4gh.server.cli.repomanager.getRawInput',
                lambda x: 'N'):
            self._runCmd("remove-dataset", datasetName)
        with mock.patch(
                'ga4gh.server.cli.repomanager.getRawInput',
                lambda x: 'y'):
            self._runCmd("remove-dataset", datasetName)
            with self.assertRaises(SystemExit):
                self._runCmd("remove-dataset", datasetName)