Skip to content

Commit

Permalink
Merge branch 'sprint13' of https://github.com/isb-cgc/ISB-CGC-Common
Browse files Browse the repository at this point in the history
…into isb-cgc-test
  • Loading branch information
phyllers committed Nov 16, 2016
2 parents 3cf1bb4 + 385a526 commit c29454a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cohorts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ def get_sample_participant_list(user, inc_filters=None, cohort_id=None):
else:
filters[key] = inc_filters[key]


# User data filters trump all other filters; if there are any which came along
# with the rest, only those count
if user_data_filters:
Expand Down Expand Up @@ -1744,6 +1745,8 @@ def set_operation(request):
samples = Samples.objects.filter(cohort_id__in=ids).distinct().values_list('sample_id', 'study_id')

elif op == 'intersect':

start = time.time()
cohort_ids = request.POST.getlist('selected-ids')
cohorts = Cohort.objects.filter(id__in=cohort_ids, active=True, cohort_perms__in=request.user.cohort_perms_set.all())
request.user.cohort_perms_set.all()
Expand Down Expand Up @@ -1821,6 +1824,10 @@ def set_operation(request):

samples = cohort_sample_list

stop = time.time()

logger.debug('[BENCHMARKING] Time to build intersecting sample set: ' + (stop - start).__str__())

elif op == 'complement':
base_id = request.POST.get('base-id')
subtract_ids = request.POST.getlist('subtract-ids')
Expand All @@ -1843,6 +1850,7 @@ def set_operation(request):
notes += ' from %s.' % base_cohort.name

if len(samples):
start = time.time()
new_cohort = Cohort.objects.create(name=name)
perm = Cohort_Perms(cohort=new_cohort, user=request.user, perm=Cohort_Perms.OWNER)
perm.save()
Expand All @@ -1857,7 +1865,10 @@ def set_operation(request):
Samples.objects.bulk_create(sample_list)

# get the full resulting sample and patient ID set
startSI = time.time()
samples_and_participants = get_sample_participant_list(request.user,None,new_cohort.id)
stopSI = time.time()
logger.debug('[BENCHMARKING] Time to get sample and participant list in set ops: '+(stopSI - startSI).__str__())

# Store cohort to BigQuery
project_id = settings.BQ_PROJECT_ID
Expand All @@ -1883,6 +1894,9 @@ def set_operation(request):
source = Source.objects.create(parent=cohort, cohort=new_cohort, type=Source.SET_OPS, notes=notes)
source.save()

stop = time.time()
logger.debug('[BENCHMARKING] Time to make cohort in set ops: '+(stop - start).__str__())

else:
message = 'Operation resulted in empty set of samples and patients. Cohort not created.'
messages.warning(request, message)
Expand Down

0 comments on commit c29454a

Please sign in to comment.