def toProtocolElement(self, tier=0): """ Returns the GA4GH protocol representation of this ReadGroup. """ # TODO this is very incomplete, but we don't have the # implementation to fill out the rest of the fields currently readGroup = protocol.ReadGroup() readGroup.id = self.getId() readGroup.created = self._creationTime readGroup.updated = self._updateTime dataset = self.getParentContainer().getParentContainer() readGroup.dataset_id = dataset.getId() readGroup.name = self.getLocalId() readGroup.predicted_insert_size = pb.int(self.getPredictedInsertSize()) referenceSet = self._parentContainer.getReferenceSet() readGroup.sample_name = pb.string(self.getSampleName()) readGroup.biosample_id = pb.string(self.getBiosampleId()) if referenceSet is not None: readGroup.reference_set_id = referenceSet.getId() readGroup.stats.CopyFrom(self.getStats()) readGroup.programs.extend(self.getPrograms()) readGroup.description = pb.string(self.getDescription()) readGroup.experiment.CopyFrom(self.getExperiment()) self.serializeAttributes(readGroup) return readGroup
def _gaFeatureForFeatureDbRecord(self, feature): """ :param feature: The DB Row representing a feature :return: the corresponding GA4GH protocol.Feature object """ gaFeature = protocol.Feature() gaFeature.id = self.getCompoundIdForFeatureId(feature['id']) if feature.get('parent_id'): gaFeature.parent_id = self.getCompoundIdForFeatureId( feature['parent_id']) else: gaFeature.parent_id = "" gaFeature.feature_set_id = self.getId() gaFeature.reference_name = pb.string(feature.get('reference_name')) gaFeature.start = pb.int(feature.get('start')) gaFeature.end = pb.int(feature.get('end')) gaFeature.name = pb.string(feature.get('name')) if feature.get('strand', '') == '-': gaFeature.strand = protocol.NEG_STRAND else: # default to positive strand gaFeature.strand = protocol.POS_STRAND gaFeature.child_ids.extend(list(map( self.getCompoundIdForFeatureId, json.loads(feature['child_ids'])))) gaFeature.feature_type.CopyFrom( self._ontology.getGaTermByName(feature['type'])) attributes = json.loads(feature['attributes']) # TODO: Identify which values are ExternalIdentifiers and OntologyTerms for key in attributes: for v in attributes[key]: gaFeature.attributes.attr[key].values.add().string_value = v if 'gene_name' in attributes and len(attributes['gene_name']) > 0: gaFeature.gene_symbol = pb.string(attributes['gene_name'][0]) return gaFeature
def toProtocolElement(self, tier=0): dataset = protocol.Dataset() dataset.id = self.getId() dataset.name = pb.string(self.getLocalId()) dataset.description = pb.string(self.getDescription()) # Populate DUO info by extending the list dataset.terms_of_use.extend([ protocol.fromJson(json.dumps(p), protocol.OntologyTerm) for p in self.getInfo() ]) self.serializeAttributes(dataset) return dataset
def toProtocolElement(self, tier=0): """ Returns the GA4GH protocol representation of this ReferenceSet. """ ret = protocol.ReferenceSet() ret.assembly_id = pb.string(self.getAssemblyId()) ret.description = pb.string(self.getDescription()) ret.id = self.getId() ret.is_derived = self.getIsDerived() ret.md5checksum = self.getMd5Checksum() if self.getSpecies(): term = protocol.fromJson( json.dumps(self.getSpecies()), protocol.OntologyTerm) ret.species.term_id = term.term_id ret.species.term = term.term ret.source_accessions.extend(self.getSourceAccessions()) ret.source_uri = pb.string(self.getSourceUri()) ret.name = self.getLocalId() self.serializeAttributes(ret) return ret
def toProtocolElement(self, tier=0): """ Returns the representation of this FeatureSet as the corresponding ProtocolElement. """ gaFeatureSet = protocol.FeatureSet() gaFeatureSet.id = self.getId() gaFeatureSet.dataset_id = self.getParentContainer().getId() gaFeatureSet.reference_set_id = pb.string(self._referenceSet.getId()) gaFeatureSet.name = self._name gaFeatureSet.source_uri = self._sourceUri attributes = self.getAttributes() for key in attributes: gaFeatureSet.attributes.attr[key] \ .values.extend(protocol.encodeValue(attributes[key])) return gaFeatureSet
def getExperiment(self): """ Returns the GA4GH protocol representation of this read group's Experiment. """ experiment = protocol.Experiment() experiment.id = self.getExperimentId() experiment.instrument_model = pb.string(self.getInstrumentModel()) experiment.sequencing_center = pb.string(self.getSequencingCenter()) experiment.description = pb.string(self.getExperimentDescription()) experiment.library = pb.string(self.getLibrary()) experiment.platform_unit = pb.string(self.getPlatformUnit()) experiment.message_create_time = self._iso8601 experiment.message_update_time = self._iso8601 experiment.run_time = pb.string(self.getRunTime()) return experiment
def testString(self): self.assertEqual(pb.DEFAULT_STRING, pb.string(None)) self.assertEqual('A', pb.string('A'))