Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
Conflicts:
	BSPAT/web/analysisResult.jsp
  • Loading branch information
Ke Hu committed Mar 24, 2016
2 parents 880c646 + e022fa9 commit f182f14
Show file tree
Hide file tree
Showing 34 changed files with 455 additions and 393 deletions.
2 changes: 1 addition & 1 deletion .idea/artifacts/BSPAT.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/artifacts/BSPAT_war_exploded.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion BSPAT/BSPAT.iml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
<SOURCES />
</library>
</orderEntry>
<orderEntry type="library" name="apache http" level="project" />
<orderEntry type="library" name="jstl-1.2.1" level="project" />
<orderEntry type="module-library" scope="TEST">
<library name="JUnit4">
Expand All @@ -54,6 +53,7 @@
<SOURCES />
</library>
</orderEntry>
<orderEntry type="library" name="apache http" level="project" />
</component>
<component name="org.twodividedbyzero.idea.findbugs">
<option name="_basePreferences">
Expand Down
8 changes: 4 additions & 4 deletions BSPAT/src/edu/cwru/cbc/BSPAT/Servlet/AnalysisServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,16 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) {
}
constant.figureFormat = request.getParameter("figureFormat"); // set figure format
if (request.getParameter("criticalValue") != null) {
constant.criticalValue = Double.valueOf(request.getParameter("criticalValue"));
constant.criticalValue = Double.parseDouble(request.getParameter("criticalValue"));
constant.minMethylThreshold = 0.1;
} else if (request.getParameter("minmethyltext") != null) {
constant.minMethylThreshold = Double.valueOf(request.getParameter("minmethyltext"));
constant.minMethylThreshold = Double.parseDouble(request.getParameter("minmethyltext"));
constant.criticalValue = -1;
}

constant.SNPThreshold = Double.valueOf(request.getParameter("SNPThreshold"));
constant.conversionRateThreshold = Double.valueOf(request.getParameter("conversionRateThreshold"));
constant.sequenceIdentityThreshold = Double.valueOf(request.getParameter("sequenceIdentityThreshold"));
constant.conversionRateThreshold = Double.parseDouble(request.getParameter("conversionRateThreshold"));
constant.sequenceIdentityThreshold = Double.parseDouble(request.getParameter("sequenceIdentityThreshold"));

// clean up result directory and result zip file
Utilities.deleteFolderContent(constant.patternResultPath);
Expand Down
6 changes: 3 additions & 3 deletions BSPAT/src/edu/cwru/cbc/BSPAT/Servlet/MappingServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) {
constant.refVersion = request.getParameter("refVersion");
constant.coorFileName = "coordinates.coor";
constant.qualsType = request.getParameter("qualsType");
constant.maxmis = Integer.valueOf(request.getParameter("maxmis"));
constant.maxmis = Integer.parseInt(request.getParameter("maxmis"));
constant.experiments = experiments;
constant.email = request.getParameter("email");
// execute BLAT query
Expand All @@ -105,7 +105,7 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) {

// multiple threads to execute bismark mapping
ExecutorService executor;
if (Boolean.valueOf(properties.getProperty("useSingleThread"))) {
if (Boolean.parseBoolean(properties.getProperty("useSingleThread"))) {
executor = Executors.newSingleThreadExecutor(); // single thread
} else {
executor = Executors.newCachedThreadPool(); // multiple threads
Expand Down Expand Up @@ -185,7 +185,7 @@ private void handleUploadedFiles(Constant constant, HttpServletRequest request,
// save ref file in ref folder
IO.saveFileToDisk(part, constant.originalRefPath, fileName);
} else if (fieldName.startsWith("seqFile")) { // deal with uploaded seq file
int seqFileIndex = Integer.valueOf(part.getName().replace("seqFile", ""));
int seqFileIndex = Integer.parseInt(part.getName().replace("seqFile", ""));
for (Experiment experiment : experiments) { // match file index and seq file index
if (experiment.getIndex() == seqFileIndex) {
experiment.setSeqFile(fileName);
Expand Down
67 changes: 43 additions & 24 deletions BSPAT/src/edu/cwru/cbc/BSPAT/core/BSSeqAnalysis.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,17 @@ public List<ReportSummary> execute(String experimentName,
.length()) {
throw new RuntimeException("invalid target coordinates! out of reference!");
}
String tmpTargetRefSeq;
if (targetStart != 0 && targetEnd != refSeq.length() - 1) {
tmpTargetRefSeq = refSeq.substring(targetStart - 1,
targetEnd + 2); // used to include one more bp on both ends to detect CpG sites.
} else {
tmpTargetRefSeq = refSeq.substring(targetStart,
targetEnd + 1);
int tmpStart = 0, tmpEnd = 0;
// used to include one more bp on both ends to detect CpG sites.
if (targetStart != 0) {
tmpStart--;
}
if (targetEnd != refSeq.length() - 1) {
tmpEnd++;
}
int startCpGPos = tmpTargetRefSeq.indexOf("CG") + targetStart - 1;
int endCpGPos = tmpTargetRefSeq.lastIndexOf("CG") + targetStart - 1;
String tmpTargetRefSeq = refSeq.substring(targetStart + tmpStart, targetEnd + tmpEnd + 1);
int startCpGPos = tmpTargetRefSeq.indexOf("CG") + targetStart + tmpStart;
int endCpGPos = tmpTargetRefSeq.lastIndexOf("CG") + targetStart + tmpStart;
String targetRefSeq = refSeq.substring(targetStart, targetEnd + 1);
boolean isStartCpGPartial = (startCpGPos == targetStart - 1);
boolean isEndCpGPartial = (endCpGPos == targetEnd);
Expand Down Expand Up @@ -196,28 +197,47 @@ public List<ReportSummary> execute(String experimentName,
return reportSummaries;
}

private Map<String, Coordinate> getStringCoordinateMap(Constant constant, Map<String, String> referenceSeqs,
Map<String, Coordinate> refCoorMap) {
private synchronized Map<String, Coordinate> getStringCoordinateMap(Constant constant, Map<String, String> referenceSeqs,
Map<String, Coordinate> refCoorMap) throws
IOException {
Map<String, Coordinate> targetCoorMap = IO.readCoordinates(constant.targetPath, constant.targetFileName);
for (String key : refCoorMap.keySet()) {
// if no given targetCoor, get position of first CpG and generate DEFAULT_TARGET_LENGTH bp region.
if (!targetCoorMap.containsKey(key)) {
String refString = referenceSeqs.get(key);
int firstPos = refString.indexOf("CG");
// no CpG found in ref seq, use ref start and DEFAULT_TARGET_LENGTH.
if (firstPos == -1) {
targetCoorMap.put(key, new Coordinate(refCoorMap.get(key).getId(), refCoorMap.get(key).getChr(),
refCoorMap.get(key).getStrand(), refCoorMap.get(key).getStart(),
refCoorMap.get(key).getStart() + DEFAULT_TARGET_LENGTH));
} else {
// from first CpG to min(ref end, fisrt CpG + DEFAULT_TARGET_LENGTH)
int endPos = refCoorMap.get(key).getStart() + firstPos + DEFAULT_TARGET_LENGTH;
targetCoorMap.put(key, new Coordinate(refCoorMap.get(key).getId(), refCoorMap.get(key).getChr(),
refCoorMap.get(key).getStrand(), refCoorMap.get(key).getStart() + firstPos,
endPos < refCoorMap.get(key).getEnd() ? endPos : refCoorMap.get(key).getEnd()));
String strand = refCoorMap.get(key).getStrand();
if (strand.equals("+")) {
int firstPos = refString.indexOf("CG");
if (firstPos == -1) {
throw new RuntimeException("no CG found in reference!");
} else {
// from first CpG to min(ref end, fisrt CpG + DEFAULT_TARGET_LENGTH)
int startPos = refCoorMap.get(key).getStart() + firstPos;
int endPos = refCoorMap.get(key).getStart() + firstPos + DEFAULT_TARGET_LENGTH - 1;
targetCoorMap.put(key,
new Coordinate(refCoorMap.get(key).getId(), refCoorMap.get(key).getChr(), strand,
startPos,
endPos < refCoorMap.get(key).getEnd() ? endPos : refCoorMap.get(key).getEnd()));
}
} else if (strand.equals("-")) {
int firstPos = refString.lastIndexOf("CG") + 2;
if (firstPos == -1) {
throw new RuntimeException("no CG found in reference!");
} else {
int startPos = refCoorMap.get(key).getEnd() - firstPos + 1;
int endPos = startPos + DEFAULT_TARGET_LENGTH - 1;
targetCoorMap.put(key,
new Coordinate(refCoorMap.get(key).getId(), refCoorMap.get(key).getChr(), strand,
startPos,
endPos < refCoorMap.get(key).getEnd() ? endPos : refCoorMap.get(key).getEnd()));
}
}
}
}
if (constant.getTargetFileName() == null) {
constant.targetFileName = "defaultTarget.coor";
IO.writeCoordinates(constant.targetPath + constant.targetFileName, targetCoorMap);
}
return targetCoorMap;
}

Expand Down Expand Up @@ -527,7 +547,6 @@ private List<Pattern> getMethylPattern(List<Sequence> allMethylSequences,
private int[][] calculateMismatchStat(String targetRefSeq, int targetStart, int targetEnd,
List<Sequence> targetSequencesList) {
int[][] mismatchStat = new int[targetRefSeq.length()][6]; // 6 possible values.
// TODO double check and refactor
for (Sequence seq : targetSequencesList) {
char[] seqArray = seq.getOriginalSeq().toCharArray();
Arrays.fill(seqArray, '-');
Expand Down
43 changes: 34 additions & 9 deletions BSPAT/src/edu/cwru/cbc/BSPAT/core/DrawPattern.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,12 @@ public void drawPattern(PatternLink patternLink) throws IOException {
statList = updatedStatList;
}

String coordinate = String.format("chr%s:%d-%d (%s strand)", chr, beginCoor, endCoor, strand);
int height = FIGURE_STARTY;
int left = FIGURE_STARTX + cellLine.length() * CELLLINE_CHAR_LENGTH;
int left = FIGURE_STARTX + (int) (cellLine.length() * CELLLINE_CHAR_LENGTH / 2 * 1.3);

int imageWidth = targetLength * BPWIDTH + left + (Integer.toString(beginCoor).length() + Integer.toString(
endCoor)
.length() + chr.length()) * 15;
int imageWidth = left + ((targetLength * BPWIDTH + 13 * 20) > coordinate.length() * COMMON_FONT_SIZE / 2 ? targetLength * BPWIDTH + 13 * 20 : coordinate
.length() * COMMON_FONT_SIZE / 2);
int imageHeight = FIGURE_STARTY + 180 + patternResultLists.size() * HEIGHT_INTERVAL;

FigureWriter methylWriter = new FigureWriter(patternResultPath, figureFormat, region,
Expand Down Expand Up @@ -250,11 +250,23 @@ public void drawASMPattern(ReportSummary reportSummary, PatternResult patternWit
String strand = data.getCoordinate().getStrand();
int beginCoor = data.getCoordinate().getStart();
int endCoor = data.getCoordinate().getEnd();
String coordinate = String.format("chr%s:%d-%d (%s strand)", chr, beginCoor, endCoor, strand);
List<CpGStatistics> statList = data.getStatList();

if (strand.equals("-")) {
patternWithAllele.getCpGList()
.forEach(cpgPattern -> cpgPattern.setPosition(refLength - cpgPattern.getPosition() - 2));
patternWithoutAllele.getCpGList()
.forEach(cpgPattern -> cpgPattern.setPosition(refLength - cpgPattern.getPosition() - 2));
for (int i = 0; i < patternWithAllele.getAlleleList().size(); i++) {
patternWithAllele.getAlleleList().set(i, refLength - patternWithAllele.getAlleleList().get(i) - 2);
}
}

int height = FIGURE_STARTY;
int left = FIGURE_STARTX + cellLine.length() * CELLLINE_CHAR_LENGTH;
int imageWidth = refLength * BPWIDTH + left + 240;
int left = FIGURE_STARTX + (int) (cellLine.length() * CELLLINE_CHAR_LENGTH / 2 * 1.3);
int imageWidth = left + ((refLength * BPWIDTH + 13 * 20) > coordinate.length() * COMMON_FONT_SIZE / 2 ? refLength * BPWIDTH + 13 * 20 : coordinate
.length() * COMMON_FONT_SIZE / 2);
int imageHeight = FIGURE_STARTY + 180 + 10 * HEIGHT_INTERVAL;

FigureWriter ASMWriter = new FigureWriter(patternResultPath, figureFormat, region, "ASM", imageWidth,
Expand Down Expand Up @@ -286,6 +298,7 @@ public void drawASMPattern(ReportSummary reportSummary, PatternResult patternWit
endCoor, strand, beginCoor - 1, beginCoor - 1));
addAverage(ASMWriter.getGraphWriter(), figure_font, patternWithoutAllele.getCpGList(), chr, beginCoor,
"PatternA", ASMWriter.getBedWriter(), height, left);
ASMWriter.getGraphWriter().setFont(new Font(figure_font, Font.PLAIN, COMMON_FONT_SIZE));
addAllele(patternWithoutAllele, ASMWriter.getGraphWriter(), ASMWriter.getBedWriter(), chr, beginCoor,
height + HEIGHT_INTERVAL, left);
height += HEIGHT_INTERVAL * 1.5;
Expand All @@ -303,13 +316,25 @@ public void drawASMPattern(ReportSummary reportSummary, PatternResult patternWit
height += 2 * HEIGHT_INTERVAL;
addAverage(ASMWriter.getGraphWriter(), figure_font, patternWithAllele.getCpGList(), chr, beginCoor, "PatternB",
ASMWriter.getBedWriter(), height, left);
ASMWriter.getGraphWriter().setFont(new Font(figure_font, Font.PLAIN, COMMON_FONT_SIZE));
addAllele(patternWithAllele, ASMWriter.getGraphWriter(), ASMWriter.getBedWriter(), chr, beginCoor,
height + HEIGHT_INTERVAL, left);
// set snp info
if (patternWithAllele.hasAllele()) {
String ASMSNPrsId = retrieveSNP(chr, convertCoordinates(chr, coordinateMap.get(region).getStart(), "hg38",
patternResultPath, logPath) +
patternWithAllele.getAlleleList().get(0));
long snpQueryPos;
switch (strand) {
case "+":
snpQueryPos = convertCoordinates(chr, coordinateMap.get(region).getStart(), "hg38",
patternResultPath, logPath) + patternWithAllele.getAlleleList().get(0);
break;
case "-":
snpQueryPos = convertCoordinates(chr, coordinateMap.get(region).getEnd(), "hg38",
patternResultPath, logPath) - patternWithAllele.getAlleleList().get(0);
break;
default:
throw new RuntimeException("invalid strand:" + strand);
}
String ASMSNPrsId = retrieveSNP(chr, snpQueryPos);
if (ASMSNPrsId != null) {
reportSummary.setASMSNPrsId(ASMSNPrsId);
}
Expand Down
28 changes: 17 additions & 11 deletions BSPAT/src/edu/cwru/cbc/BSPAT/core/IO.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,15 @@
import edu.cwru.cbc.BSPAT.DataType.MappingSummary;

import javax.servlet.http.Part;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class IO {
/**
* read coordinates file
*
* @param coorPath
* @param coorFileName
* @return coordinateHash
* @throws IOException
*/
public static HashMap<String, Coordinate> readCoordinates(String coorPath, String coorFileName) {
/**
Expand All @@ -45,8 +38,9 @@ public static HashMap<String, Coordinate> readCoordinates(String coorPath, Strin
throw new RuntimeException(
"invalid coordinate file! Please double check your uploaded coordinate file");
}
coordinateHash.put(items[0], new Coordinate(items[0], items[1], items[2], Integer.valueOf(items[3]),
Integer.valueOf(items[4])));
coordinateHash.put(items[0],
new Coordinate(items[0], items[1], items[2], Integer.parseInt(items[3]),
Integer.parseInt(items[4])));
}
line = coordinatesBuffReader.readLine();
}
Expand All @@ -57,6 +51,18 @@ public static HashMap<String, Coordinate> readCoordinates(String coorPath, Strin
return coordinateHash;
}

public static void writeCoordinates(String outFileName, Map<String, Coordinate> coorHashMap) throws
IOException {
try (BufferedWriter writer = new BufferedWriter(new FileWriter(outFileName))) {
for (String key : coorHashMap.keySet()) {
Coordinate coor = coorHashMap.get(key);
writer.write(
String.format("%s\t%s\t%s\t%s\t%s\n", key, coor.getChr(), coor.getStrand(), coor.getStart(),
coor.getEnd()));
}
}
}

public static void createFolder(String path) {
File folder = new File(path);
if (!folder.isDirectory()) {
Expand Down
34 changes: 24 additions & 10 deletions BSPAT/src/edu/cwru/cbc/BSPAT/core/ReadAnalysisResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ private void readStatFile(String ID) throws IOException {
if (line == null) {
throw new RuntimeException("analysis report is empty!");
}
int targetLength = Integer.parseInt(line.split("\t")[1]);
// skip 6 lines
for (int i = 0; i < 9; i++) {
statBuffReader.readLine();
Expand All @@ -47,8 +48,12 @@ private void readStatFile(String ID) throws IOException {
break;
}
// start from target start. 0-based.
CpGStatistics cpgStat = new CpGStatistics(Integer.valueOf(items[0]) - targetStart);
cpgStat.setMethylLevel(Double.valueOf(items[1]));
int pos = Integer.parseInt(items[0]) - targetStart;
if (coordinate.getStrand().equals("-")) {
pos = targetLength - pos - 2;
}
CpGStatistics cpgStat = new CpGStatistics(pos);
cpgStat.setMethylLevel(Double.parseDouble(items[1]));
statList.add(cpgStat);
line = statBuffReader.readLine();
}
Expand All @@ -74,33 +79,42 @@ public List<PatternResult> readPatternFile(String region, String patternType) th

while (line != null) {
items = line.split("\t");
String patternString = items[0];
if (coordinate.getStrand().equals("-")) {
patternString = new StringBuilder(items[0]).reverse().toString();
}
patternResult = new PatternResult();
for (int i = 0; i < regionLength; i++) {
CpGSitePattern cpg;
if (items[0].charAt(i) == '*') {
if (patternString.charAt(i) == '*') {
cpg = new CpGSitePattern(i, false);
if (i + 1 < regionLength && items[0].charAt(i + 1) == '*') {
if (i + 1 < regionLength && patternString.charAt(i + 1) == '*') {
i++;
} else if (i == 0) {
cpg = new CpGSitePattern(i - 1, false);
} else if (patternString.charAt(i - 1) != '-') {
cpg = new CpGSitePattern(i - 1, false);
}
patternResult.addCpG(cpg);
} else if (items[0].charAt(i) == '@') {
} else if (patternString.charAt(i) == '@') {
cpg = new CpGSitePattern(i, true);
if (i + 1 < regionLength && items[0].charAt(i + 1) == '@') {
if (i + 1 < regionLength && patternString.charAt(i + 1) == '@') {
i++;
} else if (i == 0) {
cpg = new CpGSitePattern(i - 1, true);
} else if (patternString.charAt(i - 1) != '-') {
cpg = new CpGSitePattern(i - 1, false);
}
patternResult.addCpG(cpg);
} else if (items[0].charAt(i) == 'A' || items[0].charAt(i) == 'C' || items[0].charAt(i) == 'G' ||
items[0].charAt(i) == 'T') {
} else if (patternString.charAt(i) == 'A' || patternString.charAt(i) == 'C' || patternString.charAt(
i) == 'G' ||
patternString.charAt(i) == 'T') {
patternResult.addAllele(i);
}
}
patternResultLists.add(patternResult);
patternResult.setCount(Integer.valueOf(items[1]));
patternResult.setPercent(Double.valueOf(items[2]));
patternResult.setCount(Integer.parseInt(items[1]));
patternResult.setPercent(Double.parseDouble(items[2]));
line = patternBuffReader.readLine();
}
}
Expand Down
1 change: 1 addition & 0 deletions BSPAT/src/edu/cwru/cbc/BSPAT/core/Utilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public static List<String> convertPSLtoCoorPair(String path, String outFileName)
throw new RuntimeException(
"No matched coordinate found by Blat for given reference file. Please double check your reference file");
}
IO.writeCoordinates(path + outFileName, coorHashMap);
return warnings;
}

Expand Down
Loading

0 comments on commit f182f14

Please sign in to comment.