Skip to content
This repository has been archived by the owner on Jan 24, 2018. It is now read-only.

Commit

Permalink
Make referencesets optional for variant sets
Browse files Browse the repository at this point in the history
Allow nullity for referencesetid field in models
Safely access the referenceset name in a few places
  • Loading branch information
david4096 committed Mar 2, 2017
1 parent 0276ab0 commit 578a2d7
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 21 deletions.
26 changes: 16 additions & 10 deletions ga4gh/server/cli/repomanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,16 +275,22 @@ def addVariantSet(self):
variantSet.populateFromFile(dataUrls, indexFiles)
# Get the reference set that is associated with the variant set.
referenceSetName = self._args.referenceSetName
if referenceSetName is None:
# Try to find a reference set name from the VCF header.
referenceSetName = variantSet.getVcfHeaderReferenceSetName()
if referenceSetName is None:
raise exceptions.RepoManagerException(
"Cannot infer the ReferenceSet from the VCF header. Please "
"specify the ReferenceSet to associate with this "
"VariantSet using the --referenceSetName option")
referenceSet = self._repo.getReferenceSetByName(referenceSetName)
variantSet.setReferenceSet(referenceSet)
referenceSet = None
if referenceSetName is not None:
referenceSet = self._repo.getReferenceSetByName(referenceSetName)
elif variantSet.getVcfHeaderReferenceSetName() is not None:
try:
referenceSet = self._repo.getReferenceSetByName(
variantSet.getVcfHeaderReferenceSetName())
except exceptions.ReferenceSetNameNotFoundException as e:
# It's a lucky shot to get a reference set by name using the
# VCF header.
pass
print('made it')
if referenceSet is not None:
print('hur')

variantSet.setReferenceSet(referenceSet)
variantSet.setAttributes(json.loads(self._args.attributes))
# Now check for annotations
annotationSets = []
Expand Down
31 changes: 24 additions & 7 deletions ga4gh/server/datarepo.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,13 @@ def printSummary(self):
sep="\t")
print("\tVariantSets:")
for variantSet in dataset.getVariantSets():
referenceSetName = ""
if variantSet.getReferenceSet() is not None:
referenceSetName = \
variantSet.getReferenceSet().getLocalId()
print(
"\t", variantSet.getLocalId(),
variantSet.getReferenceSet().getLocalId(),
referenceSetName,
variantSet.getId(),
sep="\t")
if variantSet.getNumVariantAnnotationSets() > 0:
Expand All @@ -235,17 +239,25 @@ def printSummary(self):
vas.getOntology().getName(), sep="\t")
print("\tFeatureSets:")
for featureSet in dataset.getFeatureSets():
referenceSetName = ""
if featureSet.getReferenceSet() is not None:
referenceSetName = \
featureSet.getReferenceSet().getLocalId()
print(
"\t", featureSet.getLocalId(),
featureSet.getReferenceSet().getLocalId(),
referenceSetName,
featureSet.getOntology().getName(),
featureSet.getId(),
sep="\t")
print("\tContinuousSets:")
for continuousSet in dataset.getContinuousSets():
referenceSetName = ""
if continuousSet.getReferenceSet() is not None:
referenceSetName = \
continuousSet.getReferenceSet().getLocalId()
print(
"\t", continuousSet.getLocalId(),
continuousSet.getReferenceSet().getLocalId(),
referenceSetName,
continuousSet.getId(),
sep="\t")
print("\tPhenotypeAssociationSets:")
Expand Down Expand Up @@ -1016,11 +1028,14 @@ def insertVariantSet(self, variantSet):
[protocol.toJsonDict(metadata) for metadata in
variantSet.getMetadata()])
urlMapJson = json.dumps(variantSet.getReferenceToDataUrlIndexMap())
referenceSetId = None
if variantSet.getReferenceSet() is not None:
referenceSetId = variantSet.getReferenceSet().getId()
try:
m.Variantset.create(
id=variantSet.getId(),
datasetid=variantSet.getParentContainer().getId(),
referencesetid=variantSet.getReferenceSet().getId(),
referencesetid=referenceSetId,
name=variantSet.getLocalId(),
created=datetime.datetime.now(),
updated=datetime.datetime.now(),
Expand All @@ -1035,11 +1050,13 @@ def insertVariantSet(self, variantSet):
def _readVariantSetTable(self):
for variantSetRecord in m.Variantset.select():
dataset = self.getDataset(variantSetRecord.datasetid.id)
referenceSet = self.getReferenceSet(
variantSetRecord.referencesetid.id)
variantSet = variants.HtslibVariantSet(
dataset, variantSetRecord.name)
variantSet.setReferenceSet(referenceSet)
if variantSetRecord.referencesetid is not None:
referenceSet = self.getReferenceSet(
variantSetRecord.referencesetid.id)
variantSet.setReferenceSet(referenceSet)

variantSet.populateFromRow(variantSetRecord)
assert variantSet.getId() == variantSetRecord.id
# Insert the variantSet into the memory-based object model.
Expand Down
8 changes: 4 additions & 4 deletions ga4gh/server/repo/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class Variantset(BaseModel):
metadata = pw.TextField(null=True)
name = pw.TextField()
referencesetid = pw.ForeignKeyField(
db_column='referenceSetId', rel_model=Referenceset, to_field='id')
db_column='referenceSetId', rel_model=Referenceset, to_field='id', null=True)
updated = pw.TextField(null=True)

class Meta:
Expand Down Expand Up @@ -138,7 +138,7 @@ class Featureset(BaseModel):
ontologyid = pw.ForeignKeyField(
db_column='ontologyId', rel_model=Ontology, to_field='id')
referencesetid = pw.ForeignKeyField(
db_column='referenceSetId', rel_model=Referenceset, to_field='id')
db_column='referenceSetId', rel_model=Referenceset, to_field='id', null=True)
sourceuri = pw.TextField(
db_column='sourceUri', null=True)

Expand All @@ -157,7 +157,7 @@ class ContinuousSet(BaseModel):
info = pw.TextField(null=True)
name = pw.TextField()
referencesetid = pw.ForeignKeyField(
db_column='referenceSetId', rel_model=Referenceset, to_field='id')
db_column='referenceSetId', rel_model=Referenceset, to_field='id', null=True)
sourceuri = pw.TextField(
db_column='sourceUri', null=True)

Expand Down Expand Up @@ -270,7 +270,7 @@ class Rnaquantificationset(BaseModel):
info = pw.TextField(null=True)
name = pw.TextField()
referencesetid = pw.ForeignKeyField(
db_column='referenceSetId', rel_model=Referenceset, to_field='id')
db_column='referenceSetId', rel_model=Referenceset, to_field='id', null=True)

class Meta:
db_table = 'RnaQuantificationSet'
Expand Down

0 comments on commit 578a2d7

Please sign in to comment.