From 012a3c8c6325831cc998052029008904b5e239e3 Mon Sep 17 00:00:00 2001 From: lancelothk Date: Sat, 11 Aug 2018 12:24:43 -0700 Subject: [PATCH] Bug fix: incorrect order of pattern in figure drawing Draw pattern with allele first, which is consistent with assumption in drawASMFigure. Add test for this issue. --- .../cwru/cbc/BSPAT/MethylFigure/IOUtils.java | 5 ++-- .../BSPAT/MethylFigure/MethylFigurePgm.java | 8 ++--- .../cbc/BSPAT/MethylFigure/IOUtilsTest.java | 29 +++++++++++++++++++ 3 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 BSPAT_standAlone/src/test/java/edu/cwru/cbc/BSPAT/MethylFigure/IOUtilsTest.java diff --git a/BSPAT_standAlone/src/main/java/edu/cwru/cbc/BSPAT/MethylFigure/IOUtils.java b/BSPAT_standAlone/src/main/java/edu/cwru/cbc/BSPAT/MethylFigure/IOUtils.java index f03ff3f..ad67ed6 100644 --- a/BSPAT_standAlone/src/main/java/edu/cwru/cbc/BSPAT/MethylFigure/IOUtils.java +++ b/BSPAT_standAlone/src/main/java/edu/cwru/cbc/BSPAT/MethylFigure/IOUtils.java @@ -42,9 +42,10 @@ static List readASMPatterns(String ASMPatternFileName) throws IOE cpg.setMethylLevel(methylLevel); } - patternResultLists.add(patternWithoutAllele); + // First result in patternResultLists is the one with allele. + // Should be consistent with implementation in MethylFigurePgm.drawASMFigure patternResultLists.add(patternWithAllele); - patternBuffReader.close(); + patternResultLists.add(patternWithoutAllele); } return patternResultLists; } diff --git a/BSPAT_standAlone/src/main/java/edu/cwru/cbc/BSPAT/MethylFigure/MethylFigurePgm.java b/BSPAT_standAlone/src/main/java/edu/cwru/cbc/BSPAT/MethylFigure/MethylFigurePgm.java index 657e2be..a23779c 100644 --- a/BSPAT_standAlone/src/main/java/edu/cwru/cbc/BSPAT/MethylFigure/MethylFigurePgm.java +++ b/BSPAT_standAlone/src/main/java/edu/cwru/cbc/BSPAT/MethylFigure/MethylFigurePgm.java @@ -104,7 +104,8 @@ private static void drawASMFigure(String regionName, String ASMPatternFileName, methylWriter.getGraphWriter().drawString(regionName, REGION_NAME_LEFTSTART, height); methylWriter.getGraphWriter().setFont(new Font(figureFont, Font.PLAIN, COMMON_FONT_SIZE)); - // pattern with allele + // order of drawing should be consistent with IOUtils.readASMPatterns. + // pattern with allele first addAverage(methylWriter.getGraphWriter(), figureFont, patternResultList.get(0).getCpGList(), height, left); addAllele(patternResultList.get(0), methylWriter.getGraphWriter(), height + HEIGHT_INTERVAL, left); height += 2 * HEIGHT_INTERVAL; @@ -169,8 +170,7 @@ private static void drawFigure(String regionName, String patternFileName, String methylWriter.close(); } - private static void addAllele(PatternResult patternResult, Graphics2D graphWriter, int height, int left) throws - IOException { + private static void addAllele(PatternResult patternResult, Graphics2D graphWriter, int height, int left) { if (patternResult.getSnp() != null) { graphWriter.setPaint(Color.BLUE); graphWriter.fill(new Rectangle2D.Double(left + (patternResult.getSnp().getPosition() * BPWIDTH), height, @@ -180,7 +180,7 @@ private static void addAllele(PatternResult patternResult, Graphics2D graphWrite } private static void addAverage(Graphics2D graphWriter, String fontChoice, List cpgList, int height, - int left) throws IOException { + int left) { // 5. add average DecimalFormat percentSmall = new DecimalFormat("##%"); height += HEIGHT_INTERVAL; diff --git a/BSPAT_standAlone/src/test/java/edu/cwru/cbc/BSPAT/MethylFigure/IOUtilsTest.java b/BSPAT_standAlone/src/test/java/edu/cwru/cbc/BSPAT/MethylFigure/IOUtilsTest.java new file mode 100644 index 0000000..eefeefd --- /dev/null +++ b/BSPAT_standAlone/src/test/java/edu/cwru/cbc/BSPAT/MethylFigure/IOUtilsTest.java @@ -0,0 +1,29 @@ +package edu.cwru.cbc.BSPAT.MethylFigure; + +import edu.cwru.cbc.BSPAT.commons.PatternResult; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import java.io.IOException; +import java.util.List; + +import static org.testng.Assert.*; + +public class IOUtilsTest { + private String testResourcePath; + + @BeforeMethod + public void setUp() { + String root = this.getClass().getClassLoader().getResource("").getFile(); + assertNotNull(root); + testResourcePath = root + "integration/"; + } + + @Test + public void testReadASMPatterns() throws IOException { + String ASMPatternFileName = testResourcePath + "/demoExpected/demoRef-10-96-test-plus_bismark.analysis_ASM.txt"; + List patternResultList = IOUtils.readASMPatterns(ASMPatternFileName); + assertNotNull(patternResultList.get(0).getSnp(), "First ASM pattern should be the one with allele"); + assertNull(patternResultList.get(1).getSnp(), "Second ASM pattern should be the one without allele"); + } +} \ No newline at end of file