/** * Split the string into tokesn separated by the given delimiter. Profiling has * revealed that the standard string.split() method typically takes > 1/2 * the total time when used for parsing ascii files. * * @param aString the string to split * @param tokens an array to hold the parsed tokens * @param delim character that delimits tokens * @return the number of tokens parsed */ public static int split(String aString, String[] tokens, char delim) { return split(aString, tokens, delim, false); }
/** * join an array of strings given a seperator * * @param separator the string to insert between each array element * @param strings the array of strings * @return a string, which is the joining of all array values with the separator */ public static String join(String separator, String[] strings) { return join(separator, strings, 0, strings.length); }
/** * @return an input stream from the given path * @throws IOException */ public static InputStream openInputStream(String path) throws IOException { return openInputStream(path, null); }
public static boolean isTabix(String resourcePath, String indexPath) throws IOException { if(indexPath == null){ indexPath = ParsingUtils.appendToPath(resourcePath, TabixUtils.STANDARD_INDEX_EXTENSION); } return IOUtil.hasBlockCompressedExtension(resourcePath) && ParsingUtils.resourceExists(indexPath); }
/** * Tells this builder to make a Genotype object that has had filters applied, * which may be empty (passes) or have some value indicating the reasons * why it's been filtered. * * @param filters non-null list of filters. empty list => PASS * @return this builder */ public GenotypeBuilder filters(final List<String> filters) { if ( filters.isEmpty() ) return filter(null); else if ( filters.size() == 1 ) return filter(filters.get(0)); else return filter(ParsingUtils.join(";", ParsingUtils.sortList(filters))); }
/** * Tests that the string "joined", when split by "delim" using ParsingUtils.split(String, char), * <ol> * <li>Ends up with the expected number of items</li> * <li>Ends up with the expected items</li> * <li>Ends up with the same items as when the split is performed using String.split</li> * <li>When re-joined (using ParsingUtils.join(String, Collection>String<) ) results in * the original string</li> * </ol> * * @param joined * @param delim * @param expectedItems */ private void testSplitJoinRoundtrip(String joined, char delim, List<String> expectedItems) { List<String> split = ParsingUtils.split(joined, delim); Assert.assertEquals(split.size(), expectedItems.size()); Assert.assertEquals(joined.split(Character.toString(delim), -1), split.toArray()); Assert.assertEquals(joined, ParsingUtils.join(Character.toString(delim), split)); }
public String toStringWithoutGenotypes() { return String.format("[VC %s @ %s Q%s of type=%s alleles=%s attr=%s filters=%s", getSource(), contig + ":" + (start - stop == 0 ? start : start + "-" + stop), hasLog10PError() ? String.format("%.2f", getPhredScaledQual()) : ".", this.getType(), ParsingUtils.sortList(this.getAlleles()), ParsingUtils.sortedString(this.getAttributes()), String.join(",", commonInfo.getFilters())); }
private void tstExists(String path, boolean expectExists) throws IOException{ boolean exists = ParsingUtils.resourceExists(path); Assert.assertEquals(exists, expectExists); }
/** * Return the name of the index file for the provided {@code filename} and {@code extension} * Does not actually create an index * @param filename name of the file * @param extension the extension to use for the index * @return non-null String representing the index filename */ private static String indexFile(final String filename, final String extension) { return ParsingUtils.appendToPath(filename, extension); }
/** * Return the registered URLHelper, constructed with the provided URL * @see #registerHelperClass(Class) * @param url * @return */ public static URLHelper getURLHelper(URL url) { try { return getURLHelper(urlHelperClass, url); } catch (Exception e) { return getURLHelper(defaultUrlHelperClass, url); } }
public VCFHeader(final Set<VCFHeaderLine> metaData, final List<String> genotypeSampleNames) { this(metaData); if ( genotypeSampleNames.size() != new HashSet<String>(genotypeSampleNames).size() ) throw new TribbleException.InvalidHeader("BUG: VCF header has duplicate sample names"); mGenotypeSampleNames.addAll(genotypeSampleNames); samplesWereAlreadySorted = ParsingUtils.isSorted(genotypeSampleNames); buildVCFReaderMaps(genotypeSampleNames); }
@VisibleForTesting 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); }
/** * Tells this builder to make a Genotype object that has had filters applied, * which may be empty (passes) or have some value indicating the reasons * why it's been filtered. * * @param filters non-null list of filters. empty list => PASS * @return this builder */ public GenotypeBuilder filters(final List<String> filters) { if ( filters.isEmpty() ) return filter(null); else if ( filters.size() == 1 ) return filter(filters.get(0)); else return filter(ParsingUtils.join(";", ParsingUtils.sortList(filters))); }
public static boolean isTabix(String resourcePath, String indexPath) throws IOException { if(indexPath == null){ indexPath = ParsingUtils.appendToPath(resourcePath, TabixUtils.STANDARD_INDEX_EXTENSION); } return IOUtil.hasBlockCompressedExtension(resourcePath) && ParsingUtils.resourceExists(indexPath); }
public String toStringWithoutGenotypes() { return String.format("[VC %s @ %s Q%s of type=%s alleles=%s attr=%s", getSource(), contig + ":" + (start - stop == 0 ? start : start + "-" + stop), hasLog10PError() ? String.format("%.2f", getPhredScaledQual()) : ".", this.getType(), ParsingUtils.sortList(this.getAlleles()), ParsingUtils.sortedString(this.getAttributes())); }
/** * @param featureFile - path to the feature file, can be a local file path, http url, or ftp url * @param indexFile - path to the index file * @param codec - codec to decode the features * @param requireIndex - true if the reader will be queries for specific ranges. An index (idx) file must exist * @throws IOException */ public TribbleIndexedFeatureReader(final String featureFile, final String indexFile, final FeatureCodec<T, SOURCE> codec, final boolean requireIndex) throws IOException { this(featureFile, codec, false); // required to read the header if (indexFile != null && ParsingUtils.resourceExists(indexFile)) { index = IndexFactory.loadIndex(indexFile); this.needCheckForIndex = false; } else { if (requireIndex) { this.loadIndex(); if(!this.hasIndex()){ throw new TribbleException("An index is required, but none found."); } } } }
/** * Return the name of the index file for the provided {@code filename} and {@code extension} * Does not actually create an index * @param filename name of the file * @param extension the extension to use for the index * @return non-null String representing the index filename */ private static String indexFile(final String filename, final String extension) { return ParsingUtils.appendToPath(filename, extension); }
/** * Return the registered URLHelper, constructed with the provided URL * @see #registerHelperClass(Class) * @param url * @return */ public static URLHelper getURLHelper(URL url) { try { return getURLHelper(urlHelperClass, url); } catch (Exception e) { return getURLHelper(defaultUrlHelperClass, url); } }
public VCFHeader(final Set<VCFHeaderLine> metaData, final List<String> genotypeSampleNames) { this(metaData); if ( genotypeSampleNames.size() != new HashSet<String>(genotypeSampleNames).size() ) throw new TribbleException.InvalidHeader("BUG: VCF header has duplicate sample names"); mGenotypeSampleNames.addAll(genotypeSampleNames); samplesWereAlreadySorted = ParsingUtils.isSorted(genotypeSampleNames); buildVCFReaderMaps(genotypeSampleNames); }
if ( sawGenotypeFilter ) keys.add(VCFConstants.GENOTYPE_FILTER_KEY); List<String> sortedList = ParsingUtils.sortList(new ArrayList<>(keys));