Java Code Examples for htsjdk.tribble.util.ParsingUtils

The following examples show how to use htsjdk.tribble.util.ParsingUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: gatk   Source File:    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
 * Try to load the tabix index from disk, checking for out of date indexes and old versions
 * @return an Index, or null if we're unable to load
public static Index loadTabixIndex(final File featureFile) {
    try {
        final String path = featureFile.getAbsolutePath();
        final boolean isTabix = new AbstractFeatureReader.ComponentMethods().isTabix(path, null);
        if (! isTabix){
            return null;
        final String indexPath = ParsingUtils.appendToPath(path, FileExtensions.TABIX_INDEX);
        logger.debug("Loading tabix index from disk for file " + featureFile);
        final Index index = IndexFactory.loadIndex(indexPath);
        final File indexFile = new File(indexPath);
        checkIndexVersionAndModificationTime(featureFile, indexFile, index);
        return index;
    } catch (final IOException | RuntimeException e) {
        return null;
Example 2
Source Project: gatk   Source File:    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
 * Splits a String using indexOf instead of regex to speed things up.
 * This method produces the same results as {@link String#split(String)} and {@code String.split(String, 0)},
 * but has been measured to be ~2x faster (see {@code StringSplitSpeedUnitTest} for details).
 * @param str       the string to split.
 * @param delimiter the delimiter used to split the string.
 * @return A {@link List} of {@link String} tokens.
public static List<String> split(final String str, final char delimiter) {

    final List<String> tokens;

    if ( str.isEmpty() ) {
        tokens = new ArrayList<>(1);
    else {
        tokens = ParsingUtils.split(str, delimiter);

    return tokens;
Example 3
 * Split each element of the given {@link List} into a key and value.
 * Assumes each element of the given {@link List} is formatted as follows:
 *     KEY:VALUE
 * @param annotationArgs {@link List} of strings formatted KEY:VALUE to turn into a {@link Map}.
 * @return A {@link LinkedHashMap} of KEY:VALUE pairs corresponding to entries in the given list.
public static LinkedHashMap<String, String> splitAnnotationArgsIntoMap( final List<String> annotationArgs ) {

    final LinkedHashMap<String, String> annotationMap = new LinkedHashMap<>();

    for ( final String s : annotationArgs ) {
        final List<String> keyVal = ParsingUtils.split(s, FuncotatorArgumentDefinitions.MAP_NAME_VALUE_DELIMITER);
        if ( keyVal.size() != 2) {
            throw new UserException.BadInput( "Argument annotation incorrectly formatted: " + s );

        annotationMap.put( keyVal.get(0), keyVal.get(1) );

    return annotationMap;
Example 4
public int compare(final VariantContext firstVariantContext, final VariantContext secondVariantContext) {
    int positionResult =, secondVariantContext);
    if (positionResult != 0) {
        return positionResult;

    final String firstAlleles = ParsingUtils.sortList(firstVariantContext.getAlleles()).toString();
    final String secondAlleles = ParsingUtils.sortList(secondVariantContext.getAlleles()).toString();

    return firstAlleles.compareTo(secondAlleles);
Example 5
Source Project: genomewarp   Source File:    License: Apache License 2.0 5 votes vote down vote up
static List<String> getFilter(VariantContext vc) {
  if (vc.isFiltered()) {
    return (List<String>) ParsingUtils.sortList(vc.getFilters());
  if (vc.filtersWereApplied()) {
    return Arrays.asList(VCFConstants.PASSES_FILTERS_v4);

  return Arrays.asList(VCFConstants.UNFILTERED);
Example 6
Source Project: picard   Source File:    License: MIT License 5 votes vote down vote up
 * Parses a "Directive" of the form "ERROR,STRATIFIER,STRATIFIER...etc." into a {@link BaseErrorAggregation} consisting of the appropriate
 * {@link BaseCalculator} and the {@link ReadBaseStratification.CollectionStratifier CollectionStratifier} constructed from the various
 * individual stratifiers.
 * The conversion from string to object is performed by the enums
 * {@link ErrorType Errors} and {@link ReadBaseStratification.Stratifier Stratifier}.
 * @param stratifierDirective The string directive describing the error type and collection of stratifiers to use
 * @return The appropriate {@link BaseErrorAggregation}.
protected static BaseErrorAggregation parseDirective(final String stratifierDirective) {
    final String[] directiveUnits = new String[MAX_DIRECTIVES + 1];
    final char directiveSeparator = ':';
    final int numberOfTerms = ParsingUtils.split(stratifierDirective, directiveUnits, directiveSeparator, false);

    if (numberOfTerms > MAX_DIRECTIVES) {
        throw new IllegalArgumentException(String.format("Cannot parse more than the number of different stratifiers plus one (%d) terms in a single directive. (What are you trying to do?)", MAX_DIRECTIVES));
    if (numberOfTerms == 0) {
        throw new IllegalArgumentException("Found no directives at all. Cannot process.");

    // make a linkedList due to removal and addition operations below
    final List<ReadBaseStratification.RecordAndOffsetStratifier<?>> stratifiers =, 1, numberOfTerms)

    final ReadBaseStratification.RecordAndOffsetStratifier jointStratifier;

    if (stratifiers.isEmpty()) {
        jointStratifier = ReadBaseStratification.nonStratifier;
    } else {
        jointStratifier = new ReadBaseStratification.CollectionStratifier(stratifiers);

    // build an error supplier from the first term
    final Supplier<? extends BaseCalculator> supplier =

    // return the aggregator made from the stratifier and the error supplier
    return new BaseErrorAggregation<>(supplier, jointStratifier);
Example 7
private static String simpleString(@NotNull final VariantContext context) {
    return "[" + context.getContig() + ":" + context.getStart() + " Type:" + context.getType() + " Alleles:" + ParsingUtils.sortList(
            context.getAlleles()) + "]";