当前位置: 首页>>代码示例>>Java>>正文


Java StringUtil类代码示例

本文整理汇总了Java中htsjdk.samtools.util.StringUtil的典型用法代码示例。如果您正苦于以下问题:Java StringUtil类的具体用法?Java StringUtil怎么用?Java StringUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


StringUtil类属于htsjdk.samtools.util包,在下文中一共展示了StringUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: customCommandLineValidation

import htsjdk.samtools.util.StringUtil; //导入依赖的package包/类
@Override
protected String[] customCommandLineValidation() {
    IOUtil.assertDirectoryIsReadable(BASECALLS_DIR);
    final List<String> errors = new ArrayList<>();

    for (final Integer lane : LANES) {
        if (lane < 1) {
            errors.add(
                    "LANES must be greater than or equal to 1.  LANES passed in " + StringUtil.join(", ", LANES));
            break;
        }
    }

    if (errors.isEmpty()) {
        return null;
    } else {
        return errors.toArray(new String[errors.size()]);
    }
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:20,代码来源:CheckIlluminaDirectory.java

示例2: makeDataProvider

import htsjdk.samtools.util.StringUtil; //导入依赖的package包/类
/**
 * Call this method to create a ClusterData iterator over the specified tiles.
 *
 * @return An iterator for reading the Illumina basecall output for the lane specified in the constructor.
 */
public BaseIlluminaDataProvider makeDataProvider(List<Integer> requestedTiles) {
    if (requestedTiles == null) {
        requestedTiles = availableTiles;
    } else {
        if (requestedTiles.isEmpty()) {
            throw new PicardException("Zero length tile list supplied to makeDataProvider, you must specify at least 1 tile OR pass NULL to use all available tiles");
        }
    }

    final Map<IlluminaParser, Set<IlluminaDataType>> parsersToDataType = new HashMap<>();
    for (final Map.Entry<SupportedIlluminaFormat, Set<IlluminaDataType>> fmToDt : formatToDataTypes.entrySet()) {
        parsersToDataType.put(makeParser(fmToDt.getKey(), requestedTiles), fmToDt.getValue());
    }

    log.debug("The following parsers will be used by IlluminaDataProvider: " + StringUtil.join("," + parsersToDataType.keySet()));

    return new IlluminaDataProvider(outputMapping, parsersToDataType, basecallDirectory, lane);
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:24,代码来源:IlluminaDataProviderFactory.java

示例3: findAndFilterExpectedColumns

import htsjdk.samtools.util.StringUtil; //导入依赖的package包/类
/**
 * Assert that expectedCols are present and return actualCols - expectedCols
 *
 * @param actualCols   The columns present in the LIBRARY_PARAMS file
 * @param expectedCols The columns that are REQUIRED
 * @return actualCols - expectedCols
 */
private Set<String> findAndFilterExpectedColumns(final Set<String> actualCols, final Set<String> expectedCols) {
    final Set<String> missingColumns = new HashSet<>(expectedCols);
    missingColumns.removeAll(actualCols);

    if (!missingColumns.isEmpty()) {
        throw new PicardException(String.format(
                "LIBRARY_PARAMS file %s is missing the following columns: %s.",
                LIBRARY_PARAMS.getAbsolutePath(), StringUtil.join(", ", missingColumns
                )));
    }

    final Set<String> remainingColumns = new HashSet<>(actualCols);
    remainingColumns.removeAll(expectedCols);
    return remainingColumns;
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:23,代码来源:IlluminaBasecallsToSam.java

示例4: checkRgTagColumns

import htsjdk.samtools.util.StringUtil; //导入依赖的package包/类
/**
 * Given a set of columns assert that all columns conform to the format of an RG header attribute (i.e. 2 letters)
 * the attribute is NOT a member of the rgHeaderTags that are built by default in buildSamHeaderParameters
 *
 * @param rgTagColumns A set of columns that should conform to the rg header attribute format
 */
private void checkRgTagColumns(final Set<String> rgTagColumns) {
    final Set<String> forbiddenHeaders = buildSamHeaderParameters(null).keySet();
    forbiddenHeaders.retainAll(rgTagColumns);

    if (!forbiddenHeaders.isEmpty()) {
        throw new PicardException("Illegal ReadGroup tags in library params(barcode params) file(" + LIBRARY_PARAMS.getAbsolutePath() + ") Offending headers = " + StringUtil.join(", ", forbiddenHeaders));
    }

    for (final String column : rgTagColumns) {
        if (column.length() > 2) {
            throw new PicardException("Column label (" + column + ") unrecognized.  Library params(barcode params) can only contain the columns " +
                    "(OUTPUT, LIBRARY_NAME, SAMPLE_ALIAS, BARCODE, BARCODE_<X> where X is a positive integer) OR two letter RG tags!");
        }
    }
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:22,代码来源:IlluminaBasecallsToSam.java

示例5: makeSequenceRecord

import htsjdk.samtools.util.StringUtil; //导入依赖的package包/类
/**
 * Create one SAMSequenceRecord from a single fasta sequence
 */
private SAMSequenceRecord makeSequenceRecord(final ReferenceSequence refSeq) {
    final SAMSequenceRecord ret = new SAMSequenceRecord(refSeq.getName(), refSeq.length());

    // Compute MD5 of upcased bases
    final byte[] bases = refSeq.getBases();
    for (int i = 0; i < bases.length; ++i) {
            bases[i] = StringUtil.toUpperCase(bases[i]);
        }

    ret.setAttribute(SAMSequenceRecord.MD5_TAG, md5Hash(bases));
    if (GENOME_ASSEMBLY != null) {
        ret.setAttribute(SAMSequenceRecord.ASSEMBLY_TAG, GENOME_ASSEMBLY);
    }
    ret.setAttribute(SAMSequenceRecord.URI_TAG, URI);
    if (SPECIES != null) {
            ret.setAttribute(SAMSequenceRecord.SPECIES_TAG, SPECIES);
        }
    return ret;
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:23,代码来源:CreateSequenceDictionary.java

示例6: createSamRecord

import htsjdk.samtools.util.StringUtil; //导入依赖的package包/类
private SAMRecord createSamRecord(final SAMFileHeader header, final String baseName, final FastqRecord frec, final boolean paired) {
    final SAMRecord srec = new SAMRecord(header);
    srec.setReadName(baseName);
    srec.setReadString(frec.getReadString());
    srec.setReadUnmappedFlag(true);
    srec.setAttribute(ReservedTagConstants.READ_GROUP_ID, READ_GROUP_NAME);
    final byte[] quals = StringUtil.stringToBytes(frec.getBaseQualityString());
    convertQuality(quals, QUALITY_FORMAT);
    for (final byte qual : quals) {
        final int uQual = qual & 0xff;
        if (uQual < MIN_Q || uQual > MAX_Q) {
            throw new PicardException("Base quality " + uQual + " is not in the range " + MIN_Q + ".." +
            MAX_Q + " for read " + frec.getReadHeader());
        }
    }
    srec.setBaseQualities(quals);

    if (paired) {
        srec.setReadPairedFlag(true);
        srec.setMateUnmappedFlag(true);
    }
    return srec ;
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:24,代码来源:FastqToSam.java

示例7: getBaseName

import htsjdk.samtools.util.StringUtil; //导入依赖的package包/类
/** Returns read baseName and asserts correct pair read name format:
 * <ul>
 * <li> Paired reads must either have the exact same read names or they must contain at least one "/"
 * <li> and the First pair read name must end with "/1" and second pair read name ends with "/2"
 * <li> The baseName (read name part before the /) must be the same for both read names
 * <li> If the read names are exactly the same but end in "/2" or "/1" then an exception will be thrown 
 * </ul>
 */
String getBaseName(final String readName1, final String readName2, final FastqReader freader1, final FastqReader freader2) {
    String [] toks = getReadNameTokens(readName1, 1, freader1);
    final String baseName1 = toks[0] ;
    final String num1 = toks[1] ;

    toks = getReadNameTokens(readName2, 2, freader2);
    final String baseName2 = toks[0] ;
    final String num2 = toks[1];

    if (!baseName1.equals(baseName2)) {
        throw new PicardException(String.format("In paired mode, read name 1 (%s) does not match read name 2 (%s)", baseName1,baseName2));
    }

    final boolean num1Blank = StringUtil.isBlank(num1);
    final boolean num2Blank = StringUtil.isBlank(num2);
    if (num1Blank || num2Blank) {
        if(!num1Blank) throw new PicardException(error(freader1,"Pair 1 number is missing (" +readName1+ "). Both pair numbers must be present or neither."));       //num1 != blank and num2   == blank
        else if(!num2Blank) throw new PicardException(error(freader2, "Pair 2 number is missing (" +readName2+ "). Both pair numbers must be present or neither.")); //num1 == blank and num =2 != blank 
    } else {
        if (!num1.equals("1")) throw new PicardException(error(freader1,"Pair 1 number must be 1 ("+readName1+")"));
        if (!num2.equals("2")) throw new PicardException(error(freader2,"Pair 2 number must be 2 ("+readName2+")"));
    }

    return baseName1 ;
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:34,代码来源:FastqToSam.java

示例8: calculateRefWindowsByGc

import htsjdk.samtools.util.StringUtil; //导入依赖的package包/类
public static int[] calculateRefWindowsByGc(final int windows, final File referenceSequence, final int windowSize) {
    final ReferenceSequenceFile refFile = ReferenceSequenceFileFactory.getReferenceSequenceFile(referenceSequence);
    ReferenceSequence ref;

    final int [] windowsByGc = new int [windows];

    while ((ref = refFile.nextSequence()) != null) {
        final byte[] refBases = ref.getBases();
        StringUtil.toUpperCase(refBases);
        final int refLength = refBases.length;
        final int lastWindowStart = refLength - windowSize;

        final CalculateGcState state = new GcBiasUtils().new CalculateGcState();

        for (int i = 1; i < lastWindowStart; ++i) {
            final int windowEnd = i + windowSize;
            final int gcBin = calculateGc(refBases, i, windowEnd, state);
            if (gcBin != -1) windowsByGc[gcBin]++;
        }
    }

    return windowsByGc;
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:24,代码来源:GcBiasUtils.java

示例9: fillHalfRecords

import htsjdk.samtools.util.StringUtil; //导入依赖的package包/类
/**
 * Fills a halfContextAccumulator by summing over the appropriate counts from a fullContextAccumulator.
 */
public void fillHalfRecords(final ContextAccumulator fullContextAccumulator, final int contextSize) {
    final String padding = StringUtil.repeatCharNTimes('N', contextSize);

    for (Map.Entry<String,AlignmentAccumulator[]> fullContext : fullContextAccumulator.artifactMap.entrySet()) {
        final String fullContextKey = fullContext.getKey();
        final char centralBase = fullContextKey.charAt(contextSize);
        final String leadingContextKey = fullContextKey.substring(0, contextSize) + centralBase + padding;
        final String trailingContextKey = padding + centralBase + fullContextKey.substring(contextSize + 1, fullContextKey.length());

        final AlignmentAccumulator[] trailingAlignmentAccumulators = this.artifactMap.get(trailingContextKey);
        final AlignmentAccumulator[] leadingAlignmentAccumulators = this.artifactMap.get(leadingContextKey);
        final AlignmentAccumulator[] fullAlignmentAccumulators = fullContext.getValue();

        for (int i=0; i < fullAlignmentAccumulators.length; i++) {
            trailingAlignmentAccumulators[i].merge(fullAlignmentAccumulators[i]);
            leadingAlignmentAccumulators[i].merge(fullAlignmentAccumulators[i]);
        }
    }
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:23,代码来源:ContextAccumulator.java

示例10: fillZeroRecords

import htsjdk.samtools.util.StringUtil; //导入依赖的package包/类
/**
 * Fills a zeroContextAccumulator by summing over the appropriate counts from a fullContextAccumulator.
 */
public void fillZeroRecords(final ContextAccumulator fullContextAccumulator, final int contextSize) {
    final String padding = StringUtil.repeatCharNTimes('N', contextSize);

    for (Map.Entry<String,AlignmentAccumulator[]> fullContext : fullContextAccumulator.artifactMap.entrySet()) {
        final String fullContextKey = fullContext.getKey();
        final char centralBase = fullContextKey.charAt(contextSize);
        final String zeroContextKey = padding + centralBase + padding;

        final AlignmentAccumulator[] zeroAlignmentAccumulators = this.artifactMap.get(zeroContextKey);
        final AlignmentAccumulator[] fullAlignmentAccumulators = fullContext.getValue();

        for (int i=0; i < fullAlignmentAccumulators.length; i++) {
            zeroAlignmentAccumulators[i].merge(fullAlignmentAccumulators[i]);
        }
    }
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:20,代码来源:ContextAccumulator.java

示例11: run

import htsjdk.samtools.util.StringUtil; //导入依赖的package包/类
public void run() {
    final int ITERATIONS = 1000000;
    final String[] fields = new String[10000];
    final StopWatch watch = new StopWatch();

    watch.start();
    for (int i=0; i<ITERATIONS; ++i) {
        if (StringUtil.split(TEXT, fields, '\t') > 100) {
            System.out.println("Mama Mia that's a lot of tokens!!");
        }
    }
    watch.stop();
    System.out.println("StringUtil.split() took " + watch.getElapsedTime());
    watch.reset();
    
    watch.start();
    for (int i=0; i<ITERATIONS; ++i) {
        if (split(TEXT, fields, "\t") > 100) {
            System.out.println("Mama Mia that's a lot of tokens!!");
        }
    }
    watch.stop();
    System.out.println("StringTokenizer took " + watch.getElapsedTime());
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:25,代码来源:Test.java

示例12: convertParamsFile

import htsjdk.samtools.util.StringUtil; //导入依赖的package包/类
private void convertParamsFile(String libraryParamsFile, int concatNColumnFields, File testDataDir, File outputDir, File libraryParams, List<File> outputPrefixes) throws FileNotFoundException {
    try (LineReader reader = new BufferedLineReader(new FileInputStream(new File(testDataDir, libraryParamsFile)))) {
        final PrintWriter writer = new PrintWriter(libraryParams);
        final String header = reader.readLine();
        writer.println(header + "\tOUTPUT_PREFIX");
        while (true) {
            final String line = reader.readLine();
            if (line == null) {
                break;
            }
            final String[] fields = line.split("\t");
            final File outputPrefix = new File(outputDir, StringUtil.join("", Arrays.copyOfRange(fields, 0, concatNColumnFields)));
            outputPrefixes.add(outputPrefix);
            writer.println(line + "\t" + outputPrefix);
        }
        writer.close();
    }
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:19,代码来源:IlluminaBasecallsToFastqTest.java

示例13: getRefFlatFile

import htsjdk.samtools.util.StringUtil; //导入依赖的package包/类
public File getRefFlatFile(String sequence) throws Exception {
    // Create a refFlat file with a single gene containing two exons, one of which is overlapped by the
    // ribosomal interval.
    final String[] refFlatFields = new String[RefFlatColumns.values().length];
    refFlatFields[RefFlatColumns.GENE_NAME.ordinal()] = "myGene";
    refFlatFields[RefFlatColumns.TRANSCRIPT_NAME.ordinal()] = "myTranscript";
    refFlatFields[RefFlatColumns.CHROMOSOME.ordinal()] = sequence;
    refFlatFields[RefFlatColumns.STRAND.ordinal()] = "+";
    refFlatFields[RefFlatColumns.TX_START.ordinal()] = "49";
    refFlatFields[RefFlatColumns.TX_END.ordinal()] = "500";
    refFlatFields[RefFlatColumns.CDS_START.ordinal()] = "74";
    refFlatFields[RefFlatColumns.CDS_END.ordinal()] = "400";
    refFlatFields[RefFlatColumns.EXON_COUNT.ordinal()] = "2";
    refFlatFields[RefFlatColumns.EXON_STARTS.ordinal()] = "49,249";
    refFlatFields[RefFlatColumns.EXON_ENDS.ordinal()] = "200,500";

    final File refFlatFile = File.createTempFile("tmp.", ".refFlat");
    refFlatFile.deleteOnExit();
    final PrintStream refFlatStream = new PrintStream(refFlatFile);
    refFlatStream.println(StringUtil.join("\t", refFlatFields));
    refFlatStream.close();

    return refFlatFile;
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:25,代码来源:CollectRnaSeqMetricsTest.java

示例14: saveResults

import htsjdk.samtools.util.StringUtil; //导入依赖的package包/类
private void saveResults(final MetricsFile<?, Integer> metrics, final SAMFileHeader readsHeader, final String inputFileName){
    MetricsUtils.saveMetrics(metrics, out);

    if (metrics.getAllHistograms().isEmpty()) {
        logger.warn("No valid bases found in input file.");
    } else if (chartOutput != null){
        // Now run R to generate a chart

        // If we're working with a single library, assign that library's name
        // as a suffix to the plot title
        final List<SAMReadGroupRecord> readGroups = readsHeader.getReadGroups();

        /*
         * A subtitle for the plot, usually corresponding to a library.
         */
        String plotSubtitle = "";
        if (readGroups.size() == 1) {
            plotSubtitle = StringUtil.asEmptyIfNull(readGroups.get(0).getLibrary());
        }
        final RScriptExecutor executor = new RScriptExecutor();
        executor.addScript(getMeanQualityByCycleRScriptResource());
        executor.addArgs(out, chartOutput.getAbsolutePath(), inputFileName, plotSubtitle);
        executor.exec();
    }
}
 
开发者ID:broadinstitute,项目名称:gatk,代码行数:26,代码来源:MeanQualityByCycleSpark.java

示例15: saveResults

import htsjdk.samtools.util.StringUtil; //导入依赖的package包/类
protected void saveResults(final MetricsFile<?, Integer> metrics, final SAMFileHeader readsHeader, final String inputFileName) {
    MetricsUtils.saveMetrics(metrics, out);

    if (metrics.getAllHistograms().isEmpty()) {
        logger.warn("No valid bases found in input file.");
    } else if (chartOutput != null) {
        // Now run R to generate a chart

        // If we're working with a single library, assign that library's name
        // as a suffix to the plot title
        final List<SAMReadGroupRecord> readGroups = readsHeader.getReadGroups();

        /*
         * A subtitle for the plot, usually corresponding to a library.
         */
        String plotSubtitle = "";
        if (readGroups.size() == 1) {
            plotSubtitle = StringUtil.asEmptyIfNull(readGroups.get(0).getLibrary());
        }
        final RScriptExecutor executor = new RScriptExecutor();
        executor.addScript(getBaseDistributionByCycleRScriptResource());
        executor.addArgs(out, chartOutput.getAbsolutePath(), inputFileName, plotSubtitle);
        executor.exec();
    }
}
 
开发者ID:broadinstitute,项目名称:gatk,代码行数:26,代码来源:CollectBaseDistributionByCycleSpark.java


注:本文中的htsjdk.samtools.util.StringUtil类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。