/** * 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); }
/** * 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); }
/** * 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); }
public static <T extends Comparable<T>, V> String sortedString(Map<T, V> c) { List<T> t = new ArrayList<>(c.keySet()); Collections.sort(t); List<String> pairs = new ArrayList<>(); for (T k : t) { pairs.add(k + "=" + c.get(k)); } return "{" + ParsingUtils.join(", ", pairs.toArray(new String[pairs.size()])) + "}"; }
public static <T extends Comparable<T>, V> String sortedString(Map<T, V> c) { List<T> t = new ArrayList<>(c.keySet()); Collections.sort(t); List<String> pairs = new ArrayList<>(); for (T k : t) { pairs.add(k + "=" + c.get(k)); } return "{" + ParsingUtils.join(", ", pairs.toArray(new String[pairs.size()])) + "}"; }
public static <T extends Comparable<T>, V> String sortedString(Map<T, V> c) { List<T> t = new ArrayList<T>(c.keySet()); Collections.sort(t); List<String> pairs = new ArrayList<String>(); for (T k : t) { pairs.add(k + "=" + c.get(k)); } return "{" + ParsingUtils.join(", ", pairs.toArray(new String[pairs.size()])) + "}"; }
/** * a utility method for generating sorted strings from a map key set. * @param c the map * @param <T> the key type * @param <V> the value type * @return a sting, enclosed in {}, with comma seperated key value pairs in order of the keys */ protected static <T extends Comparable<T>, V> String sortedString(Map<T, V> c) { // NOTE -- THIS IS COPIED FROM GATK UTILS TO ALLOW US TO KEEP A SEPARATION BETWEEN THE GATK AND VCF CODECS final List<T> t = new ArrayList<T>(c.keySet()); Collections.sort(t); final List<String> pairs = new ArrayList<String>(); for (final T k : t) { pairs.add(k + "=" + c.get(k)); } return pairs.isEmpty() ? "" : " {" + ParsingUtils.join(", ", pairs.toArray(new String[pairs.size()])) + "}"; }
/** * a utility method for generating sorted strings from a map key set. * @param c the map * @param <T> the key type * @param <V> the value type * @return a sting, enclosed in {}, with comma seperated key value pairs in order of the keys */ protected static <T extends Comparable<T>, V> String sortedString(Map<T, V> c) { // NOTE -- THIS IS COPIED FROM GATK UTILS TO ALLOW US TO KEEP A SEPARATION BETWEEN THE GATK AND VCF CODECS final List<T> t = new ArrayList<T>(c.keySet()); Collections.sort(t); final List<String> pairs = new ArrayList<String>(); for (final T k : t) { pairs.add(k + "=" + c.get(k)); } return pairs.isEmpty() ? "" : " {" + ParsingUtils.join(", ", pairs.toArray(new String[pairs.size()])) + "}"; }
/** * a utility method for generating sorted strings from a map key set. * @param c the map * @param <T> the key type * @param <V> the value type * @return a sting, enclosed in {}, with comma seperated key value pairs in order of the keys */ @Requires("c != null") protected static <T extends Comparable<T>, V> String sortedString(Map<T, V> c) { // NOTE -- THIS IS COPIED FROM GATK UTILS TO ALLOW US TO KEEP A SEPARATION BETWEEN THE GATK AND VCF CODECS final List<T> t = new ArrayList<T>(c.keySet()); Collections.sort(t); final List<String> pairs = new ArrayList<String>(); for (final T k : t) { pairs.add(k + "=" + c.get(k)); } return pairs.isEmpty() ? "" : " {" + ParsingUtils.join(", ", pairs.toArray(new String[pairs.size()])) + "}"; }
/** * 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))); }
/** * 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))); }
@Test(dataProvider = "indexProvider") public void testBedNames(final File featureFile, final IndexFactory.IndexType indexType, final FeatureCodec<Feature, LocationAware> codec) throws IOException { final AbstractFeatureReader<Feature, ?> reader = getReader(featureFile, indexType, codec); final String[] expectedSequences = {"chr1", "chr2"}; final List<String> seqNames = reader.getSequenceNames(); Assert.assertEquals(seqNames.size(), expectedSequences.length, "Expected sequences " + ParsingUtils.join(",", expectedSequences) + " but saw " + ParsingUtils.join(",", seqNames)); for (final String s : expectedSequences) { Assert.assertTrue(seqNames.contains(s)); } }
/** * 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 */ @Requires("filters != null") 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)); }
/** * Return a VCF-like string representation for the alleles of this genotype. * * If ignoreRefState is true, will not append the reference * marker on the alleles. * * @return a string representing the genotypes, or null if the type is unavailable. */ public String getGenotypeString(boolean ignoreRefState) { if ( getPloidy() == 0 ) return "NA"; // Notes: // 1. Make sure to use the appropriate separator depending on whether the genotype is phased final String separator = isPhased() ? PHASED_ALLELE_SEPARATOR : UNPHASED_ALLELE_SEPARATOR; // 2. If ignoreRefState is true, then we want just the bases of the Alleles (ignoring the '*' indicating a ref Allele) if (ignoreRefState) { return ParsingUtils.join(separator, getAlleleStrings()); } // 3. So that everything is deterministic with regards to integration tests, we sort Alleles (when the genotype isn't phased, of course) List<Allele> alleles = isPhased() ? getAlleles() : ParsingUtils.sortList(getAlleles()); return ParsingUtils.join(separator, alleles); }
/** * Return a VCF-like string representation for the alleles of this genotype. * * If ignoreRefState is true, will not append the reference * marker on the alleles. * * @return a string representing the genotypes, or null if the type is unavailable. */ public String getGenotypeString(boolean ignoreRefState) { if ( getPloidy() == 0 ) return "NA"; // Notes: // 1. Make sure to use the appropriate separator depending on whether the genotype is phased final String separator = isPhased() ? PHASED_ALLELE_SEPARATOR : UNPHASED_ALLELE_SEPARATOR; // 2. If ignoreRefState is true, then we want just the bases of the Alleles (ignoring the '*' indicating a ref Allele) if (ignoreRefState) { return ParsingUtils.join(separator, getAlleleStrings()); } // 3. So that everything is deterministic with regards to integration tests, we sort Alleles (when the genotype isn't phased, of course) List<Allele> alleles = isPhased() ? getAlleles() : ParsingUtils.sortList(getAlleles()); return ParsingUtils.join(separator, alleles); }
private String getFilterString(final VariantContext vc) { if (vc.isFiltered()) { for (final String filter : vc.getFilters()) { if (!this.header.hasFilterLine(filter)) fieldIsMissingFromHeaderError(vc, filter, "FILTER"); } return ParsingUtils.join(";", ParsingUtils.sortList(vc.getFilters())); } else if (vc.filtersWereApplied()) return VCFConstants.PASSES_FILTERS_v4; else return VCFConstants.UNFILTERED; }
private String getFilterString(final VariantContext vc) { if (vc.isFiltered()) { for (final String filter : vc.getFilters()) { if ( ! this.header.hasFilterLine(filter)) fieldIsMissingFromHeaderError(vc, filter, "FILTER"); } return ParsingUtils.join(";", ParsingUtils.sortList(vc.getFilters())); } else if (vc.filtersWereApplied()) return VCFConstants.PASSES_FILTERS_v4; else return VCFConstants.UNFILTERED; }
private String getFilterString(final VariantContext vc) { if (vc.isFiltered()) { for (final String filter : vc.getFilters()) { if (!this.header.hasFilterLine(filter)) fieldIsMissingFromHeaderError(vc, filter, "FILTER"); } return ParsingUtils.join(";", ParsingUtils.sortList(vc.getFilters())); } else if (vc.filtersWereApplied()) return VCFConstants.PASSES_FILTERS_v4; else return VCFConstants.UNFILTERED; }
/** * Return a VCF-like string representation for the alleles of this genotype. * * If ignoreRefState is true, will not append the reference * marker on the alleles. * * @return a string representing the genotypes, or null if the type is unavailable. */ @Ensures("result != null || ! isAvailable()") public String getGenotypeString(boolean ignoreRefState) { if ( getPloidy() == 0 ) return "NA"; // Notes: // 1. Make sure to use the appropriate separator depending on whether the genotype is phased // 2. If ignoreRefState is true, then we want just the bases of the Alleles (ignoring the '*' indicating a ref Allele) // 3. So that everything is deterministic with regards to integration tests, we sort Alleles (when the genotype isn't phased, of course) return ParsingUtils.join(isPhased() ? PHASED_ALLELE_SEPARATOR : UNPHASED_ALLELE_SEPARATOR, ignoreRefState ? getAlleleStrings() : (isPhased() ? getAlleles() : ParsingUtils.sortList(getAlleles()))); }