Count the number of samples is the samplesheet
326212
def numberofsamples(self):
        """"""
        # Initialise variables to store line data
        idline = 0
        linenumber = 0
        # Parse the sample sheet to find the number of samples
        with open(self.samplesheet, "rb") as ssheet:
            # Use enumerate to iterate through the lines in the sample sheet to retrieve the line number and the data
            for linenumber, entry in enumerate(ssheet):
                # Once Sample_ID is encountered
                if "Sample_ID" in entry:
                    # Set the id line as the current line number
                    idline = linenumber
        # :samplecount is the last line number in the file minus the line number of Sample_ID
        self.samplecount = linenumber - idline
        printtime('There are {} samples in this run. '
                  'Running off-hours module with the following parameters:\n'
                  'MiSeqPath: {},\n'
                  'MiSeqFolder: {},\n'
                  'SampleSheet: {}'.format(self.samplecount, self.miseqpath, self.miseqfolder, self.samplesheet),
                  self.start)
        # Run the fastqmover module now that the number of sequences is known
        self.fastqlinker()
341406
public final void sample()
  {
    long sum = _sum.getAndSet(0);
    int count = _count.getAndSet(0);

    if (count != 0)
      _value =sum / (double) count;
    else
      _value = 0;
  }
1266688
def count(self, q='*:*', fq=None):
        """"""
        params = {'q': q, 'rows': '0'}
        if fq is not None:
            params['fq'] = fq
        res = self.search(params)
        hits = res['response']['numFound']
        return hits
680321
@Override
  public final void sample()
  {
    synchronized (_lock) {
      long count = _count.get();
      long lastCount = _lastAvgCount;
      _lastAvgCount = count;

      long sum = _sum.get();
      double lastSum = _lastAvgSum;
      _lastAvgSum = sum;

      if (count == lastCount)
        _value = 0;
      else
        _value = _scale * (sum - lastSum) / (double) (count - lastCount);
    }
  }
1135219
def sample_data(count: 5, mode: 'tabular')
      mode = mode.to_s.downcase
      unless SAMPLE_DATA_OUTPUT.include?(mode)
        raise Errors::InvalidConfigurationError, "Mode must be one of '#{SAMPLE_DATA_OUTPUT.join(', ')}'. Given: #{mode}"
      end
      samples = all { |x| x.limit(count) }.to_a
      return samples if mode == 'raw'
      return {} if samples.count == 0

      # tabular output
      schm = schema_inferrer.infer_schema(dataset: samples, extended: true)
      keys = schm.keys
      res = samples.map do |sample|
        keys.map do |key|
          value = record_value(record: sample, key: key)
          next if value.nil?
          [key, value]
        end.compact.to_h
      end

      res
    end
996282
def count(self, count):
        
        if count is None:
            raise ValueError("Invalid value for `count`, must not be `None`")
        if count is not None and count < 0:
            raise ValueError("Invalid value for `count`, must be a value greater than or equal to `0`")

        self._count = count
654494
def count(self, item):
        """"""
        if not isinstance(item, str):
            return 0
        count = 0
        for entry in self:
            if item.lower() == entry.lower():
                count += 1
        return count
431642
def count(self, value=True):
        """"""
        if value not in (True, False):
            raise ValueError('can only count True or False, not %r' % (value,))
        return bin(self)[2:].count('01'[value])
820352
def sampleCellsAcrossColumns(numCellPairs, cellsPerColumn, numColumns, seed=42):
  
  np.random.seed(seed)
  cellPairs = []
  for i in range(numCellPairs):
    randCols = np.random.choice(np.arange(numColumns), (2, ), replace=False)
    randCells = np.random.choice(np.arange(cellsPerColumn), (2, ), replace=False)

    cellsPair = np.zeros((2, ))
    for j in range(2):
      cellsPair[j] = randCols[j] * cellsPerColumn + randCells[j]
    cellPairs.append(cellsPair.astype('int32'))
  return cellPairs
1169811
def _control_sample(self, sample):
        '''  '''
        if sample > float(self.SAMPLE_LAST_PIXEL):
            return int(self.SAMPLE_LAST_PIXEL)
        elif sample < float(self.SAMPLE_FIRST_PIXEL):
            return int(self.SAMPLE_FIRST_PIXEL)
        else:
            return sample
333222
def num_examples(self):
        """"""
        if self.is_list:
            return len(self.list_or_slice)
        else:
            start, stop, step = self.slice_to_numerical_args(
                self.list_or_slice, self.original_num_examples)
            return stop - start
573574
def [](ind)
      case ind
      when Integer then worksheets[ind]
      when String  then worksheets.find { |ws| ws.sheet_name == ind }
      end
    end
1262259
function countVertices(cells) {
  var vc = -1
    , max = Math.max
  for(var i=0, il=cells.length; i<il; ++i) {
    var c = cells[i]
    for(var j=0, jl=c.length; j<jl; ++j) {
      vc = max(vc, c[j])
    }
  }
  return vc+1
}
1161989
def parsesamplesheet(self):
        """"""
        # Open the sample sheet
        with open(self.samplesheet, "r") as samplesheet:
            # Iterate through the sample sheet
            samples, prev, header = False, 0, []
            for count, line in enumerate(samplesheet):
                # Remove new lines, and split on commas
                # line = line.decode('utf-8')  # Turn from bytes to string, since python3 is finicky.
                data = line.rstrip().split(",")
                if any(data):
                    if "[Settings]" in line:
                        samples = False
                    if not line.startswith("[") and not samples and not data == ['']:
                        # Grab an data not in the [Data] Section
                        setattr(self.header, data[0].replace(" ", ""), "".join(data[1:]))
                    elif "[Data]" in line or "[Reads]" in line:
                        samples = True
                    elif samples and "Sample_ID" in line:
                        header.extend([x.replace("_", "").replace(' ', "") for x in data])
                        prev = count
                    elif header:
                        # Try and replicate the Illumina rules to create file names from "Sample_Name"
                        samplename = samplenamer(data)
                        # Create an object for storing nested static variables
                        strainmetadata = MetadataObject()
                        # Set the sample name in the object
                        strainmetadata.name = samplename
                        # Add the header object to strainmetadata
                        # strainmetadata.__setattr__("run", GenObject(dict(self.header)))
                        strainmetadata.run = GenObject(copy.copy(self.header.datastore))
                        # Create the run object, so it will be easier to populate the object (eg run.SampleName = ...
                        # instead of strainmetadata.run.SampleName = ...
                        run = strainmetadata.run
                        # Capture Sample_ID, Sample_Name, I7_Index_ID, index1, I5_Index_ID,	index2, Sample_Project
                        for idx, item in enumerate(data):
                            setattr(run, header[idx], item) if item else setattr(run, header[idx], "NA")
                        # Add the sample number
                        run.SampleNumber = count - prev
                        # Create the 'General' category for strainmetadata
                        strainmetadata.general = GenObject({'outputdirectory': os.path.join(self.path, samplename),
                                                            'pipelinecommit': self.commit})
                        strainmetadata.general.logout = os.path.join(self.path, samplename,
                                                                     '{}_log_out.txt'.format(samplename))
                        strainmetadata.general.logerr = os.path.join(self.path, samplename,
                                                                     '{}_log_err.txt'.format(samplename))
                        # Add the output directory to the general category
                        # Append the strainmetadata object to a list
                        self.samples.append(strainmetadata)
                    elif samples:
                        setattr(self.header, 'forwardlength', data[0]) \
                            if 'forwardlength' not in self.header.datastore else \
                            setattr(self.header, 'reverselength', data[0])
                        self.totalreads += int(data[0])
        self.date = self.header.Date if "Date" in self.header.datastore else self.date
        for sample in self.samples:
            if 'InvestigatorName' not in sample.run.datastore:
                sample.run.InvestigatorName = 'NA'
1163697
def num_samples(self, **kwargs):
        
        if self.num_samples_fn is None:
            return None
        elif callable(self.num_samples_fn):
            return self.num_samples_fn(**kwargs)
        else:
            return self.num_samples_fn
1304432
def count(self, query, _or=False):
        
        if isinstance(query, str):
            return self.fm.count(query, MapIntInt({}))
        else:
            search_results = []
            for q in query:
                dids = MapIntInt({})
                self.fm.search(q, dids)
                search_results.append(dids.asdict())
            merged_dids = self._merge_search_result(search_results, _or)
            counts = 0
            for did in merged_dids:
                if _or:
                    counts += reduce(add, [int(x.pop(did, 0)) for x in search_results])
                else:
                    counts += min([int(x.pop(did, 0)) for x in search_results])
            return counts
121007
def sample(self, x0, nsteps, nskip=1):
        """
        x = np.zeros(shape=(nsteps + 1,))
        x[0] = x0
        for t in range(nsteps):
            q = x[t]
            for s in range(nskip):
                q = self.step(q)
            x[t + 1] = q
        return x