Manages adding/removing samples from autocreated cohorts.
345940
def update_sample_for_autocreated_cohorts(instance, created, **kwargs):
    ""

    # World
    lookup = {'batch': None, 'project': None, 'autocreated': True,
              'name': 'World'}
    try:
        world_cohort = Cohort.objects.get(**lookup)
    except Cohort.DoesNotExist:
        if getattr(settings, 'VARIFY_AUTO_CREATE_COHORT', True):
            world_cohort = Cohort(**lookup)
            world_cohort.save()
        else:
            log.info("World cohort was not found and was not created because "
                     "VARIFY_AUTO_CREATE_COHORT setting is False.")
            return

    project = instance.project

    # Project
    lookup = {'batch': None, 'project': project, 'autocreated': True}
    try:
        project_cohort = Cohort.objects.get(**lookup)
    except Cohort.DoesNotExist:
        project_cohort = Cohort(name=unicode(project), **lookup)
        project_cohort.save()

    if instance.published:
        world_cohort.add(instance, added=False)
        project_cohort.add(instance, added=False)
    else:
        world_cohort.remove(instance, delete=True)
        project_cohort.remove(instance, delete=True)
1271924
def purge(datasets, reuses, organizations):
    '''
    
    '''
    purge_all = not any((datasets, reuses, organizations))

    if purge_all or datasets:
        log.info('Purging datasets')
        purge_datasets()

    if purge_all or reuses:
        log.info('Purging reuses')
        purge_reuses()

    if purge_all or organizations:
        log.info('Purging organizations')
        purge_organizations()

    success('Done')
222952
def do_auto_save(self):
        
        if not self.auto_save.GetValue():
            if self.current_fit:
                if not self.current_fit.saved:
                    self.delete_fit(self.current_fit, specimen=self.s)
1071603
public void addSample(int[] sample, SP lastProperty) {
        S target = getOrCreateState(sample);
        if (!target.tryMergeStateProperty(lastProperty)) {
            throw new IllegalStateException();
        }
    }
271799
void deleteNewAndOldFiles() {

        fa.removeElement(fileName + ".data" + ".old");
        fa.removeElement(fileName + ".data" + ".new");
        fa.removeElement(fileName + ".backup" + ".new");
        fa.removeElement(scriptFileName + ".new");
    }
1146732
def save(self, *args, **kwargs):
        ''''''
        if not self.id:
            self.slug = slugify(self.name)
        super(Cohort, self).save(*args, **kwargs)
791900
def handler(self):
        """"""
        printtime('Creating and populating objects', self.start)
        self.populate()
        printtime('Populating {} sequence profiles'.format(self.analysistype), self.start)
        self.profiler()
        # Annotate sequences with prokka
        self.annotatethreads()
        # Run the analyses
        self.cdsthreads()
        # Find core coding features
        self.cdssequencethreads()
        # Extract the sequence for each coding feature
        self.allelematchthreads()
        # Determine sequence types from the analyses
        printtime('Determining {} sequence types'.format(self.analysistype), self.start)
        self.sequencetyper()
        # Create reports
        printtime('Creating {} reports'.format(self.analysistype), self.start)
        self.reporter()
1327543
def _post_create(self, auto_refresh=False):

		'''
		
		'''

		# set PCDM triple as Object
		self.add_triple(self.rdf.prefixes.rdf.type, self.rdf.prefixes.pcdm.Object)
		self.update(auto_refresh=auto_refresh)

		# create /files child resource
		files_child = PCDMFilesContainer(
			self.repo,
			'%s/files' % self.uri_as_string(),
			membershipResource=self.uri,
			hasMemberRelation=self.rdf.prefixes.pcdm.hasFile)
		files_child.create(specify_uri=True)

		# create /members child resource
		members_child = PCDMMembersContainer(
			self.repo,
			'%s/members' % self.uri_as_string(),
			membershipResource=self.uri,
			hasMemberRelation=self.rdf.prefixes.pcdm.hasMember,
			insertedContentRelation=self.rdf.prefixes.ore.proxyFor)
		members_child.create(specify_uri=True)

		# create /related child resource
		related_child = PCDMRelatedContainer(
			self.repo,
			'%s/related' % self.uri_as_string(),
			membershipResource=self.uri,
			hasMemberRelation=self.rdf.prefixes.ore.aggregates,
			insertedContentRelation=self.rdf.prefixes.ore.proxyFor)
		related_child.create(specify_uri=True)

		# create /associated child resource
		associated_child = PCDMAssociatedContainer(
			self.repo,
			'%s/associated' % self.uri_as_string(),
			membershipResource=self.uri,
			hasMemberRelation=self.rdf.prefixes.pcdm.hasRelatedFile)
		associated_child.create(specify_uri=True)
837108
def _computeUniqueReadCounts(self):
        
        for pathogenName, samples in self.pathogenNames.items():
            for sampleName in samples:
                self.pathogenSampleFiles.add(pathogenName, sampleName)
451359
def forwards(self, orm):
        ""
        db_table = orm['samples.CohortVariant']._meta.db_table
        db.execute('TRUNCATE TABLE "{0}"'.format(db_table))
        db.execute('ALTER SEQUENCE "{0}_id_seq" RESTART 1'.format(db_table))
        cohorts = list(orm['samples.Cohort'].objects.all())

        for c in cohorts:
            # Calculate frequencies for all variants associated with all
            # samples in this cohort
            db.execute('''
                INSERT INTO cohort_variant (cohort_id, variant_id, af) (
                    SELECT c.id, r.variant_id, COUNT(r.id) / c."count"::float
                    FROM sample_result r
                        INNER JOIN sample s ON (r.sample_id = s.id)
                        INNER JOIN cohort_sample cs ON (cs.sample_id = s.id)
                        INNER JOIN cohort c ON (cs.cohort_id = c.id)
                    WHERE c.id = %s
                    GROUP BY c.id, r.variant_id, c."count"
                )
            ''', [c.pk])
488448
def _gen_mods(self, action, records, existing_rrsets):
        '''
        
        '''
        return [r.mod(action, existing_rrsets) for r in records]
700951
def change_specimen(self, old_spec_name, new_spec_name,
                        new_sample_name=None, new_er_data=None, new_pmag_data=None,
                        replace_data=False):
        
        specimen = self.find_by_name(old_spec_name, self.specimens)
        if not specimen:
            print('-W- {} is not a currently existing specimen, so cannot be updated'.format(old_spec_name))
            return False
        if new_sample_name:
            new_sample = self.find_by_name(new_sample_name, self.samples)
            if not new_sample:
                print("""-W- {} is not a currently existing sample.
Creating a new sample named: {} """.format(new_sample_name, new_sample_name))
                new_sample = self.add_sample(new_sample_name)
        else:
            new_sample = None
        specimen.change_specimen(new_spec_name, new_sample, new_er_data, new_pmag_data, replace_data)
        return specimen
88754
void addSample(StopwatchSample sample) {
		total += sample.getTotal();
		counter += sample.getCounter();

		if (min > sample.getMin()) {
			min = sample.getMin();
			minTimestamp = sample.getMinTimestamp();
		}

		if (max < sample.getMax()) {
			max = sample.getMax();
			maxTimestamp = sample.getMaxTimestamp();
		}

		active += sample.getActive();

		if (maxActive < sample.getMaxActive()) {
			maxActive = sample.getMaxActive();
			maxActiveTimestamp = sample.getMaxActiveTimestamp();
		}
	}
62095
def purge_obsolete_samples(self, config, now):
        
        expire_age = config.samples * config.time_window_ms
        for sample in self._samples:
            if now - sample.last_window_ms >= expire_age:
                sample.reset(now)
1092292
public void addSample(double[] sampleData) {
		if (sampleIndex >= numSamples)
			throw new IllegalArgumentException("Too many samples");
		if (sampleData.length != sampleSize)
			throw new IllegalArgumentException("Unexpected sample size");

		for (int i = 0; i < sampleData.length; i++) {
			A.set(sampleIndex, i, sampleData[i]);
		}
		sampleIndex++;
	}
934622
public void addSample(Sample stat) {
        samples.add(stat);
        if (samples.size() == 1) {
            start = stat.start;
            end = stat.end;
        }
        this.ioBytes += stat.ioBytes;
        this.jobMsgCnt += stat.jobMsgCnt;
        this.msgCnt += stat.msgCnt;
        this.msgBytes += stat.msgBytes;
        this.start = Math.min(this.start, stat.start);
        this.end = Math.max(this.end, stat.end);
    }
702854
@Override
    public void clearData() {
        synchronized (lock) {
            model.clearData();
            tableRows.clear();
            tableRows.put(TOTAL_ROW_LABEL, new SamplingStatCalculator(
                    TOTAL_ROW_LABEL));
            model.addRow(tableRows.get(TOTAL_ROW_LABEL));
        }
    }