Example #1
0
 def populateFromJson(self, jsonString):
     try:
         parsed = protocol.fromJson(jsonString, protocol.BioSample)
     except:
         raise exceptions.InvalidJsonException(jsonString)
     self._created = parsed.created
     self._updated = parsed.updated
     self._description = parsed.description
     self._disease = protocol.toJsonDict(parsed.disease)
     self._individualId = parsed.individual_id
     self._info = {}
     for key in parsed.info:
         self._info[key] = {"values": protocol.toJsonDict(parsed.info[key])}
     return self
Example #2
0
 def populateFromJson(self, jsonString):
     # TODO validate
     try:
         parsed = protocol.fromJson(jsonString, protocol.Individual)
     except:
         raise exceptions.InvalidJsonException(jsonString)
     self._created = parsed.created
     self._updated = parsed.updated
     self._description = parsed.description
     self._species = protocol.toJsonDict(parsed.species)
     self._sex = protocol.toJsonDict(parsed.sex)
     self._info = {}
     for key in parsed.info:
         self._info[key] = {"values": protocol.toJsonDict(parsed.info[key])}
     return self
Example #3
0
 def sendListRequest(self, path, request):
     headers = {
         'Origin': self.exampleUrl,
     }
     data = protocol.toJsonDict(request)
     response = self.app.post(path, data=data, headers=headers)
     return response
Example #4
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)
Example #5
0
 def verifyParsedOutputsEqualReadGroup(self,
                                       clientIterator,
                                       cliCommand,
                                       cliArguments=""):
     cliOutput = self.captureJsonOutput(cliCommand, cliArguments)
     clientOutput = [protocol.toJsonDict(gObj) for gObj in clientIterator]
     self.assertEqual(clientOutput, cliOutput)
     return len(clientOutput)
Example #6
0
 def _formatExternalIdentifiers(self, element, element_type):
     """
     Formats several external identifiers for query
     """
     elementClause = None
     elements = []
     if not issubclass(element.__class__, dict):
         element = protocol.toJsonDict(element)
     if element['externalIdentifiers']:
         for _id in element['externalIdentifiers']:
             elements.append(
                 self._formatExternalIdentifier(_id, element_type))
         elementClause = "({})".format(" || ".join(elements))
     return elementClause
Example #7
0
 def _formatOntologyTermObject(self, terms, element_type):
     """
     Formats the ontology term object for query
     """
     elementClause = None
     if not isinstance(terms, collections.Iterable):
         terms = [terms]
     elements = []
     for term in terms:
         if not issubclass(term.__class__, dict):
             term = protocol.toJsonDict(term)
         if term['id']:
             elements.append('?{} = <{}> '.format(element_type, term['id']))
         else:
             elements.append('?{} = <{}> '.format(
                 element_type, self._toNamespaceURL(term['term'])))
     elementClause = "({})".format(" || ".join(elements))
     return elementClause
Example #8
0
 def verifyParsedOutputsEqual(self,
                              clientIterator,
                              cliCommand,
                              cliArguments="",
                              scrubFunc=None):
     """
     Verify that the parsed JSON of all the objects in the specified
     client iterator are equal to the parsed JSON from the specified
     CLI command.
     """
     cliOutput = self.captureJsonOutput(cliCommand, cliArguments)
     clientOutput = [protocol.toJsonDict(gObj) for gObj in clientIterator]
     if scrubFunc is not None:
         # this is a hack to deal with the issue of the timestamps on
         # objects being different
         scrubFunc(cliOutput, clientOutput)
     self.assertEqual(clientOutput, cliOutput)
     return len(clientOutput)
Example #9
0
 def testInstantiation(self):
     for class_ in self._getExceptionClasses():
         # some exceptions are becoming too complicated to instantiate
         # like the rest of the exceptions; just do them manually
         if class_ == exceptions.RequestValidationFailureException:
             objClass = protocol.SearchReadsRequest
             obj = objClass()
             obj.start = -1
             jsonDict = protocol.toJsonDict(obj)
             args = (jsonDict, objClass)
         else:
             numInitArgs = len(inspect.getargspec(class_.__init__).args) - 1
             args = ['arg' for _ in range(numInitArgs)]
         instance = class_(*args)
         self.assertIsInstance(instance, exceptions.BaseServerException)
         message = instance.getMessage()
         self.assertIsInstance(message, basestring)
         self.assertGreater(len(message), 0)
         self.assertEqual(instance.getErrorCode(), class_.getErrorCode())
Example #10
0
    def testToGA4GH(self):
        sample_associations = {
            u'environment_label': u'sunitinib',
            u'feature_label': u'RET M918T missense mutation',
            u'evidence_type': u'http://purl.obolibrary.org/obo/ECO_0000033',
            u'feature': {
                u'http://purl.obolibrary.org/obo/GENO_0000408':
                u'http://www.ncbi.nlm.nih.gov/gene/5979',
                u'http://purl.obolibrary.org/obo/GENO_reference_amino_acid':
                u'M',
                u'http://www.w3.org/1999/02/22-rdf-syntax-ns#type':
                u'http://purl.obolibrary.org/obo/SO_0001059',
                u'http://biohackathon.org/resource/faldo#location':
                u'http://www.monarchinitiative.org/_918918UniProtKB:'
                'P07949#P07949-1Region',
                u'http://purl.obolibrary.org/obo/GENO_reference_nucleotide':
                u'T',
                u'http://purl.obolibrary.org/obo/'
                'GENO_results_in_amino_acid_change':
                u'T',
                u'http://purl.obolibrary.org/obo/RO_0002200':
                u'http://ohsu.edu/cgd/3774b1d2',
                u'http://purl.obolibrary.org/obo/RO_0002205':
                u'http://www.ncbi.nlm.nih.gov/CCDS/CcdsBrowse.cgi?'
                'REQUEST=CCDS&DATA=7200.1',
                u'http://purl.obolibrary.org/obo/GENO_altered_nucleotide':
                u'C',
                u'http://www.w3.org/2000/01/rdf-schema#label':
                u'RET M918T missense mutation',
                u'id':
                u'http://cancer.sanger.ac.uk/cosmic/mutation/'
                'overview?id=965',
                u'http://www.w3.org/2002/07/owl#sameAs':
                u'http://www.ncbi.nlm.nih.gov/SNP/74799832',
            },
            u'evidence': u'http://ohsu.edu/cgd/sensitivity',
            u'environment': {
                u'http://purl.obolibrary.org/obo/RO_0002606':
                u'http://ohsu.edu/cgd/71fe9f0f',
                u'http://www.w3.org/2000/01/rdf-schema#subClassOf':
                u'http://purl.obolibrary.org/obo/CHEBI_23888',
                u'http://www.w3.org/1999/02/22-rdf-syntax-ns#type':
                u'http://www.w3.org/2002/07/owl#Class',
                u'http://www.w3.org/2000/01/rdf-schema#label': u'sunitinib',
                u'id': u'http://www.drugbank.ca/drugs/DB01268',
            },
            u'sources': u'http://www.ncbi.nlm.nih.gov/pubmed/21470995|'
            'http://www.ncbi.nlm.nih.gov/pubmed/21470995',
            u'phenotype': {
                u'http://purl.obolibrary.org/obo/BFO_0000159':
                u'http://ohsu.edu/cgd/sensitivity',
                u'http://www.w3.org/1999/02/22-rdf-syntax-ns#type':
                u'http://purl.obolibrary.org/obo/DOID_3969',
                u'http://www.w3.org/2000/01/rdf-schema#label':
                u'Papillary thyroid carcinoma with sensitivity to therapy',
                u'id': u'http://ohsu.edu/cgd/30ebfd1a',
            },
            u'phenotype_label':
            u'Papillary thyroid carcinoma with sensitivity to therapy',
            u'id': u'http://ohsu.edu/cgd/fe484b5c',
            u'association': u'http://ohsu.edu/cgd/fe484b5c',
        }
        result = self.phenotypeAssocationSet._toGA4GH(sample_associations)
        self.assertEqual(result.__class__.__name__,
                         'FeaturePhenotypeAssociation')
        fpa_dict = protocol.toJsonDict(result)
        description = 'Association: genotype:[RET M918T missense mutation]' \
                      ' phenotype:[Papillary thyroid carcinoma with ' \
                      'sensitivity to therapy] environment:[sunitinib]' \
                      ' evidence:[sensitivity] publications:' \
                      '[http://www.ncbi.nlm.nih.gov/pubmed/21470995|' \
                      'http://www.ncbi.nlm.nih.gov/pubmed/21470995]'

        self.assertEqual(fpa_dict['description'], description)
        self.assertIn('featureIds', fpa_dict.keys())
        self.assertIn('evidence', fpa_dict.keys())
        self.assertIn('environmentalContexts', fpa_dict.keys())
        self.assertEqual(len(fpa_dict['featureIds']), 1)
        self.assertEqual(len(fpa_dict['evidence']), 1)
        self.assertEqual(len(fpa_dict['environmentalContexts']), 1)