@Test public void testObjectGroup() { Column c0 = new Column(9, 0); Column c1 = new Column(9, 1); // Illustrates the Cell's actual index = colIndex * cellsPerColumn + indexOfCellWithinCol assertEquals(7, c0.getCell(7).getIndex()); assertEquals(12, c1.getCell(3).getIndex()); assertEquals(16, c1.getCell(7).getIndex()); DistalDendrite dd0 = new DistalDendrite(c0.getCell(7), 0, 0, 0); DistalDendrite dd1 = new DistalDendrite(c1.getCell(3 /* Col 1's Cells start at 9 */), 1, 0, 1); DistalDendrite dd2 = new DistalDendrite(c1.getCell(7 /* Col 1's Cells start at 9 */), 2, 0, 2); List<DistalDendrite> l = Arrays.asList(new DistalDendrite[] {dd0, dd1, dd2}); @SuppressWarnings("unchecked") List<Pair<DistalDendrite, Column>> expected = Arrays.asList( new Pair[] { new Pair<DistalDendrite, Column>(dd0, c0), new Pair<DistalDendrite, Column>(dd1, c1), new Pair<DistalDendrite, Column>(dd2, c1) }); GroupBy<DistalDendrite, Column> grouper = GroupBy.of(l, i -> i.getParentCell().getColumn()); int i = 0; for (Pair<DistalDendrite, Column> p : grouper) { assertEquals(expected.get(i++), p); } }
public List runOn(Collection list) { Map grouped = groupBy.runOn(list); Collection wrapped = new Wrap(klass).runOn(grouped); List sorted = (List) wrapped; new Sort().add(MapEntry.KEY, true).runOn(sorted); return sorted; }
@Test public void testIntegerGroup() { List<Integer> l = Arrays.asList(new Integer[] {7, 12, 16}); @SuppressWarnings("unchecked") List<Pair<Integer, Integer>> expected = Arrays.asList( new Pair[] { new Pair<Integer, Integer>(7, 7), new Pair<Integer, Integer>(12, 12), new Pair<Integer, Integer>(16, 16) }); GroupBy<Integer, Integer> grouper = GroupBy.of(l, i -> i); int i = 0; int pairCount = 0; for (Pair<Integer, Integer> p : grouper) { assertEquals(expected.get(i++), p); pairCount++; } assertEquals(3, pairCount); ////// pairCount = 0; l = Arrays.asList(new Integer[] {2, 4, 4, 5}); @SuppressWarnings("unchecked") List<Pair<Integer, Integer>> expected2 = Arrays.asList( new Pair[] { new Pair<Integer, Integer>(2, 6), new Pair<Integer, Integer>(4, 12), new Pair<Integer, Integer>(4, 12), new Pair<Integer, Integer>(5, 15) }); grouper = GroupBy.of(l, in -> in * 3); i = 0; for (Pair<Integer, Integer> p : grouper) { assertEquals(expected2.get(i++), p); pairCount++; } assertEquals(4, pairCount); }
private static String getSelectString(final Class<?> klass, final SelectFrom from) { final String columnString = getColumnString(klass); final String fromString = getFromString(klass, from); final String selectString = String.format("SELECT %s FROM (%s)", columnString, fromString); final StringBuilder selectBuilder = new StringBuilder(); selectBuilder.append(selectString); final GroupBy groupBy = klass.getAnnotation(GroupBy.class); if (groupBy != null) { selectBuilder.append(String.format(" GROUP BY %s", groupBy.value())); } final OrderBy orderBy = klass.getAnnotation(OrderBy.class); if (orderBy != null) { selectBuilder.append(String.format(" ORDER BY %s", orderBy.value())); } return selectBuilder.toString(); }
/** * Composes the column summary output header. * * <p>Returns a multiline header prepended with the comment scape '##' sequence for general * information an final uncommented single line with the column headers. * * @param commandLine the command-line. * @param targetCount number of targets processed. * @param totalSize combined total size of all targets processed in bps. * @return never {@code null}. */ private static String composeColumnSummaryHeader( final String commandLine, final GroupBy groupBy, final int targetCount, final long totalSize) { return String.format( String.join( LINE_SEPARATOR, "##fileFormat = tsv", "##commandLine = %s", "##title = Summary counts per %s", "##metaData = {", "## targetCount = %d,", "## totalSize = %d (bp)", "##}", String.join(COLUMN_SEPARATOR, groupBy.name(), SUM_COLUMN_NAME, AVG_BP_COLUMN_NAME)), commandLine, groupBy.toString(), targetCount, totalSize); }
/** * Composes the main output header. * * @param commandLine the tool command line. * @param groupBy the group-by argument used. * @param countColumnNames the column names. * @return never {@code null}. */ private static String composeMatrixOutputHeader( final String commandLine, final TargetOutInfo targetOutInfo, final GroupBy groupBy, final List<String> countColumnNames) { final String countColumnHeaderString = String.join(COLUMN_SEPARATOR, countColumnNames).replace("%", "%%"); final String formatString = String.join( LINE_SEPARATOR, "##fileFormat = tsv", "##commandLine = %s", "##title = Read counts per target and %s", String.join(COLUMN_SEPARATOR, targetOutInfo.headerString(), countColumnHeaderString)); return String.format(formatString, commandLine, groupBy.toString()); }
@Override public void onTraversalStart() { sampleCollection = new SampleCollection(getHeaderForReads()); logger.log(Level.INFO, "Reading targets locations from intervals..."); targetCollection = resolveTargetCollection(); // Initializing count and count column management member fields: countColumns = groupBy.countColumns(this); final int columnCount = countColumns.columnCount(); counts = new int[columnCount][targetCollection.targetCount()]; // Open output files and write headers: outputWriter = openOutputWriter( output, composeMatrixOutputHeader( getCommandLine(), targetOutInfo, groupBy, countColumns.columnNames())); if (columnSummaryOutput != null) { columnSummaryOutputWriter = openOutputWriter( columnSummaryOutput, composeColumnSummaryHeader( getCommandLine(), groupBy, targetCollection.targetCount(), targetCollection.totalSize())); } if (rowSummaryOutput != null) { rowSummaryOutputWriter = openOutputWriter( rowSummaryOutput, composeRowOutputHeader( getCommandLine(), targetOutInfo, groupBy, countColumns.columnCount())); } // Next we start the traversal: logger.log(Level.INFO, "Collecting read counts ..."); }