private List<VariantContextUtils.JexlVCMatchExp> initializeJexl(ArrayList<String> genotypeFilterExpressions) { ArrayList<String> dummyNames = new ArrayList<String>(genotypeFilterExpressions.size()); int expCount = 1; for ( String exp : genotypeFilterExpressions ) { dummyNames.add(String.format("gfe%d",expCount++)); } return VariantContextUtils.initializeMatchExps(dummyNames, genotypeFilterExpressions); }
public static List<JexlVCMatchExp> initializeMatchExps(ArrayList<String> names, ArrayList<String> exps) { String[] nameArray = new String[names.size()]; String[] expArray = new String[exps.size()]; return initializeMatchExps(names.toArray(nameArray), exps.toArray(expArray)); }
/** * Method for creating JexlVCMatchExp from input walker arguments names and exps. These two lists contain * the name associated with each JEXL expression. initializeMatchExps will parse each expression and return * a list of JexlVCMatchExp, in order, that correspond to the names and exps. These are suitable input to * match() below. * * @param names names * @param exps expressions * @return list of matches */ public static List<JexlVCMatchExp> initializeMatchExps(List<String> names, List<String> exps) { String[] nameArray = new String[names.size()]; String[] expArray = new String[exps.size()]; return initializeMatchExps(names.toArray(nameArray), exps.toArray(expArray)); }
/** * Method for creating JexlVCMatchExp from input walker arguments names and exps. These two lists contain * the name associated with each JEXL expression. initializeMatchExps will parse each expression and return * a list of JexlVCMatchExp, in order, that correspond to the names and exps. These are suitable input to * match() below. * * @param names names * @param exps expressions * @return list of matches */ public static List<JexlVCMatchExp> initializeMatchExps(List<String> names, List<String> exps) { String[] nameArray = new String[names.size()]; String[] expArray = new String[exps.size()]; return initializeMatchExps(names.toArray(nameArray), exps.toArray(expArray)); }
/** * Method for creating JexlVCMatchExp from input walker arguments names and exps. These two arrays contain * the name associated with each JEXL expression. initializeMatchExps will parse each expression and return * a list of JexlVCMatchExp, in order, that correspond to the names and exps. These are suitable input to * match() below. * * @param names names * @param exps expressions * @return list of matches */ public static List<JexlVCMatchExp> initializeMatchExps(String[] names, String[] exps) { if ( names == null || exps == null ) throw new IllegalArgumentException("BUG: neither names nor exps can be null: names " + Arrays.toString(names) + " exps=" + Arrays.toString(exps) ); if ( names.length != exps.length ) throw new IllegalArgumentException("Inconsistent number of provided filter names and expressions: names=" + Arrays.toString(names) + " exps=" + Arrays.toString(exps)); Map<String, String> map = new HashMap<String, String>(); for ( int i = 0; i < names.length; i++ ) { map.put(names[i], exps[i]); } return VariantContextUtils.initializeMatchExps(map); }
/** * Method for creating JexlVCMatchExp from input walker arguments names and exps. These two arrays contain * the name associated with each JEXL expression. initializeMatchExps will parse each expression and return * a list of JexlVCMatchExp, in order, that correspond to the names and exps. These are suitable input to * match() below. * * @param names names * @param exps expressions * @return list of matches */ public static List<JexlVCMatchExp> initializeMatchExps(String[] names, String[] exps) { if ( names == null || exps == null ) throw new IllegalArgumentException("BUG: neither names nor exps can be null: names " + Arrays.toString(names) + " exps=" + Arrays.toString(exps) ); if ( names.length != exps.length ) throw new IllegalArgumentException("Inconsistent number of provided filter names and expressions: names=" + Arrays.toString(names) + " exps=" + Arrays.toString(exps)); Map<String, String> map = new HashMap<String, String>(); for ( int i = 0; i < names.length; i++ ) { map.put(names[i], exps[i]); } return VariantContextUtils.initializeMatchExps(map); }
/** * Method for creating JexlVCMatchExp from input walker arguments names and exps. These two arrays contain * the name associated with each JEXL expression. initializeMatchExps will parse each expression and return * a list of JexlVCMatchExp, in order, that correspond to the names and exps. These are suitable input to * match() below. * * @param names names * @param exps expressions * @return list of matches */ public static List<JexlVCMatchExp> initializeMatchExps(String[] names, String[] exps) { if ( names == null || exps == null ) throw new IllegalArgumentException("BUG: neither names nor exps can be null: names " + Arrays.toString(names) + " exps=" + Arrays.toString(exps) ); if ( names.length != exps.length ) throw new IllegalArgumentException("Inconsistent number of provided filter names and expressions: names=" + Arrays.toString(names) + " exps=" + Arrays.toString(exps)); Map<String, String> map = new HashMap<String, String>(); for ( int i = 0; i < names.length; i++ ) { map.put(names[i], exps[i]); } return VariantContextUtils.initializeMatchExps(map); }
@Test public void testApplyVCFilters(){ final VariantContext vcNoFilters = buildDataForFilters().make(); // assumes this vc doesn't hold any filters yet String filterName = "LowDP"; String filterExpr = "DP < 23"; List<VariantContextUtils.JexlVCMatchExp> vcFilterExps = VariantContextUtils.initializeMatchExps(Arrays.asList(filterName), Arrays.asList(filterExpr)); final Set<String> filters = VariantFiltration.buildVCfilters(vcNoFilters, vcFilterExps, false, false); Assert.assertFalse(vcNoFilters.isFiltered()); Assert.assertEquals(filters.size(), 1); Assert.assertTrue(filters.contains(filterName)); filterName = "ID"; filterExpr = "ID = rs123"; vcFilterExps = VariantContextUtils.initializeMatchExps(Arrays.asList(filterName), Arrays.asList(filterExpr)); Set<String> filterWhenFailMissing = VariantFiltration.buildVCfilters(vcNoFilters, vcFilterExps, false, true); // Assert.assertEquals(filterWhenFailMissing.size(), 1); // Assert.assertTrue(filterWhenFailMissing.contains(filterName)); filterWhenFailMissing = VariantFiltration.buildVCfilters(vcNoFilters, vcFilterExps, false, false); Assert.assertTrue(filterWhenFailMissing.isEmpty()); }
@Override public void initialize() { if ( maskExtension < 0 ) { throw new UserException.BadArgumentValue("maskExtension", "negative values are not allowed"); } if (filterRecordsNotInMask && !mask.isBound()) { throw new UserException.BadArgumentValue("filterNotInMask", "argument not allowed if mask argument is not provided"); } if ( clusterWindow > 0 ) { clusteredSNPs = new ClusteredSnps(getToolkit().getGenomeLocParser(), clusterSize, clusterWindow); } filterExps = VariantContextUtils.initializeMatchExps(filterNames, filterExpressions); genotypeFilterExps = VariantContextUtils.initializeMatchExps(genotypeFilterNames, genotypeFilterExpressions); VariantContextUtils.engine.get().setSilent(true); initializeVcfWriter(); }
jexls = VariantContextUtils.initializeMatchExps(selectNames, selectExpressions);
for (VariantContextUtils.JexlVCMatchExp jexl : VariantContextUtils.initializeMatchExps(SELECT_NAMES, SELECT_EXPS)) { SortableJexlVCMatchExp sjexl = new SortableJexlVCMatchExp(jexl.name, jexl.exp); jexlExpressions.add(sjexl);
@Test public void testApplyGenotypeFilters(){ final VariantContext vc = buildDataForFilters().make(); final String filterName = "LowZ"; //an attribute that doesn't appear in the VariantContext, so there isn't any chance of confusion like with the INFO DP final String filterExpr = "Z < 10"; final List<VariantContextUtils.JexlVCMatchExp> genotypeFilterExps = VariantContextUtils.initializeMatchExps(Arrays.asList(filterName), Arrays.asList(filterExpr)); final VariantContextBuilder anotherVCBuilder = VariantFiltration.applyGenotypeFilters(vc, genotypeFilterExps, false, false, false); final VariantContext anotherVC = anotherVCBuilder.filters().make(); Assert.assertEquals(anotherVC.getGenotype("one").isFiltered(), true); Assert.assertTrue(anotherVC.getGenotype("one").getFilters().equals(filterName)); Assert.assertEquals(anotherVC.getGenotype("two").isFiltered(), false); Assert.assertEquals(anotherVC.getGenotype("three").isFiltered(), false); Assert.assertEquals(anotherVC.getGenotype("four").isFiltered(), false); Assert.assertEquals(anotherVC.getGenotype("five").isFiltered(), false); Assert.assertEquals(anotherVC.getGenotype("six").isFiltered(), false); final VariantContextBuilder yetAnotherVCBuilder = VariantFiltration.applyGenotypeFilters(anotherVC, genotypeFilterExps, false, true, false); final VariantContext yetAnotherVC = yetAnotherVCBuilder.filters().make(); Assert.assertEquals(yetAnotherVC.getGenotype("six").isFiltered(), true); Assert.assertTrue(yetAnotherVC.getGenotype("six").getFilters().equals(filterName)); }