Separates out the quality score from the accepted content_type
338873
def accept_quality(accept, default=1):
    """"""
    quality = default
    if accept and ";" in accept:
        accept, rest = accept.split(";", 1)
        accept_quality = RE_ACCEPT_QUALITY.search(rest)
        if accept_quality:
            quality = float(accept_quality.groupdict().get('quality', quality).strip())

    return (quality, accept.strip())
875956
def read_quality_trim(self):
        
        logging.info('Quality trim')
        for sample in self.metadata:
            sample.sampled_reads = GenObject()
            sample.sampled_reads.outputdir = os.path.join(sample.outputdir, 'sampled')
            sample.sampled_reads.trimmed_dir = os.path.join(sample.sampled_reads.outputdir, 'qualitytrimmed_reads')
            make_path(sample.sampled_reads.trimmed_dir)
            for depth in self.read_depths:
                # Create the depth GenObject
                setattr(sample.sampled_reads, depth, GenObject())
                # Set the depth and output directory attributes for the depth GenObject
                sample.sampled_reads[depth].depth = depth
                sample.sampled_reads[depth].depth_dir = os.path.join(sample.sampled_reads.outputdir, depth)
                # Create the output directory
                make_path(sample.sampled_reads[depth].depth_dir)
                for read_pair in self.read_lengths:
                    # Create the read_pair GenObject within the depth GenObject
                    setattr(sample.sampled_reads[depth], read_pair, GenObject())
                    # Set and create the output directory
                    sample.sampled_reads[depth][read_pair].outputdir = \
                        os.path.join(sample.sampled_reads[depth].depth_dir, read_pair)
                    make_path(sample.sampled_reads[depth][read_pair].outputdir)
                    # Create both forward_reads and reverse_reads sub-GenObjects
                    sample.sampled_reads[depth][read_pair].forward_reads = GenObject()
                    sample.sampled_reads[depth][read_pair].reverse_reads = GenObject()
                    sample.sampled_reads[depth][read_pair].trimmed_dir = \
                        os.path.join(sample.sampled_reads.trimmed_dir,
                                     read_pair)
                    make_path(sample.sampled_reads[depth][read_pair].trimmed_dir)
                    # Extract the forward and reverse reads lengths from the read_pair variable
                    sample.sampled_reads[depth][read_pair].forward_reads.length, \
                        sample.sampled_reads[depth][read_pair].reverse_reads.length = read_pair.split('_')
                    logging.info('Performing quality trimming on reads from sample {name} at depth {depth} '
                                 'for minimum read length {forward}'
                                 .format(name=sample.name,
                                         depth=depth,
                                         forward=sample.sampled_reads[depth][read_pair].forward_reads.length))
                    # Set the attributes for the trimmed forward and reverse reads to use for subsampling
                    sample.sampled_reads[depth][read_pair].trimmed_forwardfastq = \
                        os.path.join(sample.sampled_reads[depth][read_pair].trimmed_dir,
                                     '{name}_{length}_R1.fastq.gz'
                                     .format(name=sample.name,
                                             length=sample.sampled_reads[depth][read_pair].forward_reads.length))
                    sample.sampled_reads[depth][read_pair].trimmed_reversefastq = \
                        os.path.join(sample.sampled_reads[depth][read_pair].trimmed_dir,
                                     '{name}_{length}_R2.fastq.gz'
                                     .format(name=sample.name,
                                             length=sample.sampled_reads[depth][read_pair].forward_reads.length))
                    # Create the trimmed output directory attribute
                    sample.sampled_reads[depth][read_pair].sampled_trimmed_outputdir \
                        = os.path.join(sample.sampled_reads[depth][read_pair].outputdir,
                                       'sampled_trimmed')
                    # Set the name of the forward trimmed reads - include the depth and read length information
                    # This is set now, as the untrimmed files will be removed, and a check is necessary
                    sample.sampled_reads[depth][read_pair].forward_reads.trimmed_sampled_fastq = \
                        os.path.join(sample.sampled_reads[depth][read_pair].sampled_trimmed_outputdir,
                                     '{name}_sampled_{depth}_{read_pair}_R1.fastq.gz'
                                     .format(name=sample.name,
                                             depth=depth,
                                             read_pair=read_pair))
                    # Reverse reads
                    sample.sampled_reads[depth][read_pair].reverse_reads.trimmed_sampled_fastq = \
                        os.path.join(sample.sampled_reads[depth][read_pair].sampled_trimmed_outputdir,
                                     '{name}_sampled_{depth}_{read_pair}_R2.fastq.gz'
                                     .format(name=sample.name,
                                             depth=depth,
                                             read_pair=read_pair))
                    # Sample if the forward output file does not already exist
                    if not os.path.isfile(sample.sampled_reads[depth][read_pair].trimmed_forwardfastq) and \
                            not os.path.isfile(
                                sample.sampled_reads[depth][read_pair].forward_reads.trimmed_sampled_fastq):
                        out, \
                            err, \
                            sample.sampled_reads[depth][read_pair].sample_cmd = \
                            bbtools.bbduk_trim(forward_in=sample.forward_fastq,
                                               forward_out=sample.sampled_reads[depth][read_pair]
                                               .trimmed_forwardfastq,
                                               reverse_in=sample.reverse_fastq,
                                               reverse_out=sample.sampled_reads[depth][read_pair]
                                               .trimmed_reversefastq,
                                               minlength=sample.sampled_reads[depth][read_pair]
                                               .forward_reads.length,
                                               forcetrimleft=0,
                                               returncmd=True,
                                               **{'ziplevel': '9',
                                                  'Xmx': self.mem})
            # Update the JSON file
            self.write_json(sample)
10541
private static int getContentScore(Element node) {
        try {
            return Integer.parseInt(node.attr(CONTENT_SCORE));
        } catch (NumberFormatException e) {
            return 0;
        }
    }
357729
def get_quality(self, type='etx'):
        
        if type == 'etx':
            if 0 < self.etx < 1.5:
               quality = 1
            elif self.etx < 3:
               quality = 2
            else:
                quality = 3
        elif type == 'dbm':
            if -83 < self.dbm < 0:
                quality = 1
            elif self.dbm > -88:
                quality = 2
            else:
                quality = 3
        return quality
600209
private void processQualityUTScore(
    ScoreComponentSettings qualityUTSettings,
    Iterable<CodeQuality> codeQualityIterable,
    List<ScoreWeight> categoryScores) {
    ScoreWeight qualityUTScore = getCategoryScoreByIdName(categoryScores, WIDGET_QUALITY_UT_ID_NAME);
    Double qualityUTRatio = fetchQualityValue(codeQualityIterable, QUALITY_PARAM_UT);

    if (null == qualityUTRatio) {
      qualityUTScore.setScore(
        qualityUTSettings.getCriteria().getNoDataFound()
      );
      qualityUTScore.setMessage(Constants.SCORE_ERROR_NO_DATA_FOUND);
      qualityUTScore.setState(ScoreWeight.ProcessingState.criteria_failed);
    } else {
      try {
        //Check thresholds at widget level
        checkPercentThresholds(qualityUTSettings, qualityUTRatio);
        qualityUTScore.setScore(
          new ScoreTypeValue(qualityUTRatio)
        );
        qualityUTScore.setState(ScoreWeight.ProcessingState.complete);
      } catch (ThresholdException ex) {
        setThresholdFailureWeight(ex, qualityUTScore);
      }
    }
  }
1005405
def quality(self):
        
        from udata.models import Discussion  # noqa: Prevent circular imports
        result = {}
        if not self.id:
            # Quality is only relevant on saved Datasets
            return result
        if self.next_update:
            result['frequency'] = self.frequency
            result['update_in'] = -(self.next_update - datetime.now()).days
        if self.tags:
            result['tags_count'] = len(self.tags)
        if self.description:
            result['description_length'] = len(self.description)
        if self.resources:
            result['has_resources'] = True
            result['has_only_closed_or_no_formats'] = all(
                resource.closed_or_no_format for resource in self.resources)
            result['has_unavailable_resources'] = not all(
                self.check_availability())
        discussions = Discussion.objects(subject=self)
        if discussions:
            result['discussions'] = len(discussions)
            result['has_untreated_discussions'] = not all(
                discussion.person_involved(self.owner)
                for discussion in discussions)
        result['score'] = self.compute_quality_score(result)
        return result
103146
def format_dapi_score(cls, meta, offset):
        ''''''
        if 'average_rank' and 'rank_count' in meta:
            label = (cls._nice_strings['average_rank'] + ':').ljust(offset + 2)
            score = cls._format_field(meta['average_rank'])
            votes = ' ({num} votes)'.format(num=meta['rank_count'])
            return label + score + votes
        else:
            return ''
53871
void prune(AndCriterion criterion) {
		Set<String> usedLayers = new HashSet<String>();
		Set<String> badLayers = new HashSet<String>();
		criterion.serverLayerIdVisitor(usedLayers);
		findUnmatchedLayers(criterion, usedLayers, badLayers);
		if (usedLayers.isEmpty()) {
			criterion.getCriteria().clear();
		} else if (!badLayers.isEmpty()) {
			removeUnmatchedLayers(criterion, badLayers);
		}
	}
209091
def from_content_type(cls, content_type):
		
		name = content_type
		options = {}
		if ';' in content_type:
			name, options_str = content_type.split(';', 1)
			for part in options_str.split(';'):
				part = part.strip()
				if '=' in part:
					key, value = part.split('=')
				else:
					key, value = (part, None)
				options[key] = value
		# old style compatibility
		if name.endswith('+zlib'):
			options['compression'] = 'zlib'
			name = name[:-5]
		return cls(name, charset=options.get('charset', 'UTF-8'), compression=options.get('compression'))
755972
def content_type(self, request=None, response=None):
        """"""
        if callable(self.outputs.content_type):
            return self.outputs.content_type(request=request, response=response)
        else:
            return self.outputs.content_type
1155575
def parse_accept_header(accept):
    

    def parse_media_range(accept_item):
        """ Parse media range and subtype """

        return accept_item.split('/', 1)

    def comparator(a, b):
        """ Compare accept items a and b """

        # first compare q values
        result = -cmp(a[2], b[2])
        if result is not 0:
            # q values differ, no need to compare media types
            return result

        # parse media types and compare them (asterisks are lower in precedence)
        mtype_a, subtype_a = parse_media_range(a[0])
        mtype_b, subtype_b = parse_media_range(b[0])
        if mtype_a == '*' and subtype_a == '*':
            return 1
        if mtype_b == '*' and subtype_b == '*':
            return -1
        if subtype_a == '*':
            return 1
        if subtype_b == '*':
            return -1
        return 0

    if not accept:
        return []

    result = []
    for media_range in accept.split(","):
        parts = media_range.split(";")
        media_type = parts.pop(0).strip()
        media_params = []
        q = 1.0
        for part in parts:
            (key, value) = part.lstrip().split("=", 1)
            if key == "q":
                q = float(value)
            else:
                media_params.append((key, value))
        result.append((media_type, tuple(media_params), q))
    result.sort(comparator)
    return result
41148
def normalize_result(result, default, threshold=0.2):
    """"""
    if result is None:
        return default
    if result.get('confidence') is None:
        return default
    if result.get('confidence') < threshold:
        return default
    return normalize_encoding(result.get('encoding'),
                              default=default)
842296
def filter(args):
    
    p = OptionParser(filter.__doc__)
    p.add_option("-q", dest="qv", default=20, type="int",
                 help="Minimum quality score to keep [default: %default]")
    p.add_option("-p", dest="pct", default=95, type="int",
                 help="Minimum percent of bases that have [-q] quality "\
                 "[default: %default]")

    opts, args = p.parse_args(args)

    if len(args) not in (1, 2):
        sys.exit(not p.print_help())

    if len(args) == 1:
        r1 = r2 = args[0]
    else:
        r1, r2 = args

    qv = opts.qv
    pct = opts.pct

    offset = guessoffset([r1])
    qvchar = chr(offset + qv)
    logging.debug("Call base qv >= {0} as good.".format(qvchar))
    outfile = r1.rsplit(".", 1)[0] + ".q{0}.paired.fastq".format(qv)
    fw = open(outfile, "w")

    p1fp, p2fp = FastqPairedIterator(r1, r2)
    while True:
        a = list(islice(p1fp, 4))
        if not a:
            break

        b = list(islice(p2fp, 4))
        q1 = a[-1].rstrip()
        q2 = b[-1].rstrip()

        if isHighQv(q1, qvchar, pct=pct) and isHighQv(q2, qvchar, pct=pct):
            fw.writelines(a)
            fw.writelines(b)
431027
private void obtainQualityScoresFromQualityString() {
        int total = 0;
        this.maximumQuality = Integer.MIN_VALUE;
        this.minimumQuality = Integer.MAX_VALUE;
        // quality int array initialization
        qualityScoresArray = new int[this.quality.length()];

        // Transform each character in the quality String into a integer, depending on
        // the quality scale, and obtain the average, minimum and maximum values
        for (int i = 0; i < this.quality.length(); i++) {
            char c = this.quality.charAt(i);
            qualityScoresArray[i] = c - FastQ.SCALE_OFFSET[this.encoding];
            total += this.qualityScoresArray[i];

            this.maximumQuality = Math.max(this.qualityScoresArray[i], this.maximumQuality);
            this.minimumQuality = Math.min(this.qualityScoresArray[i], this.minimumQuality);
        }
        this.averageQuality = (double) total / this.quality.length();
    }
170277
private void obtainQualityStringFromQualityScoresArray(int encoding) {
        char[] qualityChars = new char[this.qualityScoresArray.length];
        // add the scale offset to each individual score and transform the result to a char
        for (int i = 0; i < this.qualityScoresArray.length; i++) {
            qualityChars[i] = (char) (this.qualityScoresArray[i] + FastQ.SCALE_OFFSET[encoding]);
        }
        this.quality = new String(qualityChars);
    }
701552
def content_val(self, ymldata=None, messages=None):
        """"""

        # Turn off the YAML Processor
        log.debug("BEGIN: Content-based validation of Telemetry dictionary")
        if ymldata is not None:
            tlmdict = ymldata
        else:
            tlmdict = tlm.TlmDict(self._ymlfile)

        try:
            # instantiate the document number. this will increment in order to
            # track the line numbers and section where validation fails
            docnum = 0

            # boolean to hold argument validity
            fldsvalid = True

            # list of rules to validate against
            rules = []

            ### set the packet rules
            #
            # set uniqueness rule for packet names
            rules.append(UniquenessRule('name', "Duplicate packet name: %s", messages))

            ###
            # Loop through the keys and check each PacketDefinition
            for key in tlmdict.keys():
                pktdefn = tlmdict[key]
                # check the telemetry packet rules
                for rule in rules:
                    rule.check(pktdefn)

                # list of field rules to validate against
                fldrules = []

                ### set rules for telemetry fields
                #
                # set uniqueness rule for field name
                fldrules.append(UniquenessRule('name', "Duplicate field name: " + pktdefn.name + ".%s", messages))

                # set type rule for field.type
                fldrules.append(TypeRule('type', "Invalid field type for field: " + pktdefn.name + ".%s", messages))

                # set field size rule for field.type.nbytes
                fldrules.append(TypeSizeRule('nbytes', "Invalid field size for field: " + pktdefn.name + ".%s", messages))

                # set field enumerations rule to check no enumerations contain un-quoted YAML special variables
                fldrules.append(EnumRule('enum', "Invalid enum value for field: " + pktdefn.name + ".%s", messages))
                #
                ###

                flddefns = pktdefn.fields
                for fld in flddefns:
                    # check field rules
                    for rule in fldrules:
                        rule.check(fld)

                # check if field rule failed, if so set the validity to False
                if not all(r.valid is True for r in fldrules):
                    fldsvalid = False

            log.debug("END: Content-based validation complete for '%s'", self._ymlfile)

            # check validity of all packet rules and field validity
            return all(rule.valid is True for rule in rules) and fldsvalid

        except util.YAMLValidationError, e:
            # Display the error message
            if messages is not None:
                if len(e.message) < 128:
                    msg = "Validation Failed for YAML file '" + self._ymlfile + "': '" + str(e.message) + "'"
                else:
                    msg = "Validation Failed for YAML file '" + self._ymlfile + "'"

                log.error(msg)
                self.ehandler.process(self.ehandler.doclines, e, messages)
                return False
1268218
protected Set<String> getContentTypes(String contentType) {
        if (StringUtils.isNullOrEmpty(contentType)) {
            return Collections.emptySet();
        }

        Set<String> set = new LinkedHashSet<>();
        String[] types = contentType.split(",");
        for (String type : types) {
            if (type.contains(";")) {
                // drop ;q=0.8 quality scores
                type = type.substring(0, type.indexOf(';'));
            }

            set.add(type.trim().toLowerCase());
        }

        return set;
    }