Skip to content

Commit

Permalink
Bug fix: incorrect order of pattern in figure drawing
Browse files Browse the repository at this point in the history
Draw pattern with allele first, which is consistent with assumption in drawASMFigure. Add test for this issue.
  • Loading branch information
lancelothk committed Aug 11, 2018
1 parent 934b9e4 commit 012a3c8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ static List<PatternResult> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -180,7 +180,7 @@ private static void addAllele(PatternResult patternResult, Graphics2D graphWrite
}

private static void addAverage(Graphics2D graphWriter, String fontChoice, List<? extends CpG> cpgList, int height,
int left) throws IOException {
int left) {
// 5. add average
DecimalFormat percentSmall = new DecimalFormat("##%");
height += HEIGHT_INTERVAL;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<PatternResult> 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");
}
}

0 comments on commit 012a3c8

Please sign in to comment.