ViralInsertionAnalyzer { @Nullable public static List<ViralInsertion> analyzeViralInsertions(@NotNull List<LinxViralInsertion> linxViralInsertions) { Map<ViralInsertionAnalyzer.VirusKey, List<LinxViralInsertion>> itemsPerKey = Maps.newHashMap(); for (LinxViralInsertion viralInsertion : linxViralInsertions) { ViralInsertionAnalyzer.VirusKey key = new ViralInsertionAnalyzer.VirusKey(viralInsertion.VirusId); List<LinxViralInsertion> items = itemsPerKey.get(key); if (items == null) { items = Lists.newArrayList(); } items.add(viralInsertion); itemsPerKey.put(key, items); } List<ViralInsertion> viralInsertions = Lists.newArrayList(); for (Map.Entry<ViralInsertionAnalyzer.VirusKey, List<LinxViralInsertion>> entry : itemsPerKey.entrySet()) { List<LinxViralInsertion> itemsForKey = entry.getValue(); int count = itemsForKey.size(); assert count > 0; String virusName = itemsForKey.get(0).VirusName; if (!EXCLUDED_VIRAL_INSERTIONS.contains(virusName)) { viralInsertions.add(ImmutableViralInsertion.builder().virus(virusName).viralInsertionCount(count).build()); } } return viralInsertions; } private  ViralInsertionAnalyzer(); @Nullable static List<ViralInsertion> analyzeViralInsertions(@NotNull List<LinxViralInsertion> linxViralInsertions);  }
@Test public void canMergeViralInsertionsForReporting() throws IOException { List<LinxViralInsertion> linxViralInsertions = LinxViralInsertion.read(LINX_VIRAL_INSERTIONS_TSV); List<ViralInsertion> viralInsertions = ViralInsertionAnalyzer.analyzeViralInsertions(linxViralInsertions); assertEquals(2, viralInsertions.size()); ViralInsertion viralInsertion1 = viralInsertions.get(0); assertEquals("Human papillomavirus type 15", viralInsertion1.virus()); assertEquals(1, viralInsertion1.viralInsertionCount()); ViralInsertion viralInsertion2 = viralInsertions.get(1); assertEquals("Human papillomavirus type 16", viralInsertion2.virus()); assertEquals(2, viralInsertion2.viralInsertionCount()); }