/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package solodel;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import net.sf.picard.util.Interval;
import net.sf.picard.util.IntervalList;
import net.sf.picard.util.SamLocusIterator;
import net.sf.samtools.SAMFileReader;
/**
*
* @author kimjh
*/
public class DeletionInfo {
private String chr;
private int pos1;
private int pos2;
private int size;
private int num_read;
private boolean gap;
private boolean somatic;
private boolean homology;
private boolean homozygousDel;
private int windowStart;
private int windowEnd;
private double avgDepthDeletion;
private double avgDepthWindow;
// private double medianDepthDeletion;
// private double medianDepthWindow;
private double stdDeletion;
private double stdWindow;
private double avgMapQDeletion;
private double avgSeqQDeletion;
private double avgMapQWindow;
private double avgSeqQWindow;
private double cellularity;
private double coefficientOfvariation;
private double germlineProbability;
private double mixedProbability;
private double mixedSomaticProbability;
public DeletionInfo(String breakdancerString) {
String[] s;
s = breakdancerString.split("\t");
chr = s[0];
pos1 = Integer.parseInt(s[1]);
pos2 = Integer.parseInt(s[4]);
size = pos2 - pos1;
num_read = Integer.parseInt(s[9]);
somatic = false;
homology = false;
homozygousDel = false;
gap = false;
int window_size = pos2 - pos1;
if (pos1 - window_size < 0) {
windowStart = 0;
} else {
windowStart = pos1 - window_size;
}
windowEnd = pos2 + window_size;
cellularity = 0;
coefficientOfvariation = 0;
germlineProbability = 0;
mixedProbability = 0;
mixedSomaticProbability = 0;
}
public DeletionInfo() {
chr = "";
pos1 = 0;
pos2 = 0;
size = pos2 - pos1;
num_read = 0;
avgDepthDeletion = 0;
avgDepthWindow = 0;
stdDeletion = 0;
avgMapQDeletion = 0;
avgMapQWindow = 0;
somatic = false;
homology = false;
homozygousDel = false;
gap = false;
int window_size = pos2 - pos1;
if (pos1 - window_size < 0) {
windowStart = 0;
} else {
windowStart = pos1 - window_size;
}
windowEnd = pos2 + window_size;
cellularity = 0;
coefficientOfvariation = 0;
germlineProbability = 0;
mixedProbability = 0;
mixedSomaticProbability = 0;
}
/**
* @return the chr
*/
public String getChr() {
return chr;
}
/**
* @param chr the chr to set
*/
public void setChr(String chr) {
this.chr = chr;
}
/**
* @return the pos1
*/
public int getPos1() {
return pos1;
}
/**
* @param pos1 the pos1 to set
*/
public void setPos1(int pos1) {
this.pos1 = pos1;
}
/**
* @return the pos2
*/
public int getPos2() {
return pos2;
}
/**
* @param pos2 the pos2 to set
*/
public void setPos2(int pos2) {
this.pos2 = pos2;
}
/**
* @return the size
*/
public int getSize() {
return size;
}
/**
* @param size the size to set
*/
public void setSize(int size) {
this.size = size;
}
/**
* @return the somatic
*/
public boolean isSomatic() {
return somatic;
}
/**
* @param somatic the isSomatic to set
*/
public void setSomatic(boolean isSomatic) {
this.somatic = isSomatic;
}
/**
* @return the windowStart
*/
public int getWindowStart() {
return windowStart;
}
/**
* @param windowStart the windowStart to set
*/
public void setWindowStart(int windowStart) {
this.windowStart = windowStart;
}
/**
* @return the windowEnd
*/
public int getWindowEnd() {
return windowEnd;
}
/**
* @param windowEnd the windowEnd to set
*/
public void setWindowEnd(int windowEnd) {
this.windowEnd = windowEnd;
}
/**
* @return the avgDepthDeletion
*/
public double getAvgDepthDeletion() {
return avgDepthDeletion;
}
/**
* @param avgDepthDeletion the avgDepthDeletion to set
*/
public void setAvgDepthDeletion(double avgDepthDeletion) {
this.avgDepthDeletion = avgDepthDeletion;
}
/**
* @return the avgDepthWindow
*/
public double getAvgDepthWindow() {
return avgDepthWindow;
}
/**
* @param avgDepthWindow the avgDepthWindow to set
*/
public void setAvgDepthWindow(double avgDepthWindow) {
this.avgDepthWindow = avgDepthWindow;
}
/**
* @return the stdDeletion
*/
public double getStdDeletion() {
return stdDeletion;
}
/**
* @param stdDeletion the stdDeletion to set
*/
public void setStdDeletion(double stdDeletion) {
this.stdDeletion = stdDeletion;
}
/**
* @return the stdWindow
*/
public double getStdWindow() {
return stdWindow;
}
/**
* @param stdWindow the stdWindow to set
*/
public void setStdWindow(double stdWindow) {
this.stdWindow = stdWindow;
}
/**
* @return the avgSeqQDeletion
*/
public double getavgSeqQDeletion() {
return getAvgSeqQDeletion();
}
/**
* @param avgSeqQDeletion the avgSeqQDeletion to set
*/
public void setavgSeqQDeletion(double avgSeqQDeletion) {
this.setAvgSeqQDeletion(avgSeqQDeletion);
}
/**
* @return the avgMapQDeletion
*/
public double getAvgMapQDeletion() {
return avgMapQDeletion;
}
/**
* @param avgMapQDeletion the avgMapQDeletion to set
*/
public void setAvgMapQDeletion(double avgMapQDeletion) {
this.avgMapQDeletion = avgMapQDeletion;
}
/**
* @return the avgSeqQDeletion
*/
public double getAvgSeqQDeletion() {
return avgSeqQDeletion;
}
/**
* @param avgSeqQDeletion the avgSeqQDeletion to set
*/
public void setAvgSeqQDeletion(double avgSeqQDeletion) {
this.avgSeqQDeletion = avgSeqQDeletion;
}
/**
* @return the avgMapQWindow
*/
public double getAvgMapQWindow() {
return avgMapQWindow;
}
/**
* @param avgMapQWindow the avgMapQWindow to set
*/
public void setAvgMapQWindow(double avgMapQWindow) {
this.avgMapQWindow = avgMapQWindow;
}
/**
* @return the avgSeqQWindow
*/
public double getAvgSeqQWindow() {
return avgSeqQWindow;
}
/**
* @param avgSeqQWindow the avgSeqQWindow to set
*/
public void setAvgSeqQWindow(double avgSeqQWindow) {
this.avgSeqQWindow = avgSeqQWindow;
}
public void setDeletionInfo(SAMFileReader samReader, ArrayList overlappedAreaList) {
Interval interval = new Interval(getChr(), getWindowStart(), getWindowEnd());
IntervalList il = new IntervalList(samReader.getFileHeader());
il.add(interval);
ArrayList locusList = new ArrayList();
SamLocusIterator sli = new SamLocusIterator(samReader, il, true);
for (Iterator<SamLocusIterator.LocusInfo> iter = sli.iterator(); iter.hasNext();) {
SamLocusIterator.LocusInfo locusInfo = iter.next();
List recordList = locusInfo.getRecordAndPositions();
Locus loc = new Locus();
loc.setChr(getChr());
loc.setPos(locusInfo.getPosition());
loc.setDepth(recordList.size());
loc.setMeanQualities(recordList);
locusList.add(loc);
}
setLociValues(locusList, overlappedAreaList);
sli.close();
}
public void setLociValues(ArrayList l, ArrayList overlappedAreaList) {
double mapQDel = 0.0;
double seqQDel = 0.0;
double depthDel = 0.0;
double mapQWindow = 0.0;
double seqQWindow = 0.0;
double depthWindow = 0.0;
double WindowLociCnt = 0.0;
double DelLociCnt = 0.0;
double diffDel = 0.0;
double diffWindow = 0.0;
double adjustedMapQDel = 0.0;
double adjustedSeqQDel = 0.0;
double adjustedDepthDel = 0.0;
double adjustedMapQWindow = 0.0;
double adjustedSeqQWindow = 0.0;
double adjustedDepthWindow = 0.0;
double adjustedWindowLociCnt = 0.0;
double adjustedDelLociCnt = 0.0;
double adjustedDiffDel = 0.0;
double adjustedDiffWindow = 0.0;
// ArrayList windowList = new ArrayList();
// ArrayList deletionList = new ArrayList();
// ArrayList adjustedWindowList = new ArrayList();
// ArrayList adjustedDeletionList = new ArrayList();
int size = l.size();
int delStartIdx = getPos1() - getWindowStart();
int delEndIdx = getPos2() - getWindowStart();
if (!l.isEmpty()) {
for (int i = 0; i < size; i++) {
Locus loc = (Locus) l.get(i);
int pos = loc.getPos();
boolean overlapped = isOverlapped(pos, overlappedAreaList);
if (i < delStartIdx || i > delEndIdx) { // window
if (loc.getDepth() > 0) { // for avoiding gaps
mapQWindow += loc.getMeanMapQ();
seqQWindow += loc.getMeanSeqQ();
depthWindow += loc.getDepth();
WindowLociCnt = WindowLociCnt + 1;
// Integer dw = loc.getDepth();
// windowList.add(dw);
if (!overlapped) {
adjustedMapQWindow += loc.getMeanMapQ();
adjustedSeqQWindow += loc.getMeanSeqQ();
adjustedDepthWindow += loc.getDepth();
adjustedWindowLociCnt = adjustedWindowLociCnt + 1;
// Integer adw = loc.getDepth();
// adjustedWindowList.add(adw);
}
}
} else { // del
mapQDel += loc.getMeanMapQ();
seqQDel += loc.getMeanSeqQ();
depthDel += loc.getDepth();
DelLociCnt = DelLociCnt + 1;
// Integer dd = loc.getDepth();
// deletionList.add(dd);
if (!overlapped) {
adjustedMapQDel += loc.getMeanMapQ();
adjustedSeqQDel += loc.getMeanSeqQ();
adjustedDepthDel += loc.getDepth();
adjustedDelLociCnt = adjustedDelLociCnt + 1;
// Integer add = loc.getDepth();
// adjustedDeletionList.add(add);
}
}
}
// Collections.sort(deletionList);
// Collections.sort(adjustedDeletionList);
// Collections.sort(windowList);
// Collections.sort(adjustedWindowList);
double avgDepthDel = depthDel / DelLociCnt;
double adjustedAvgDepthDel = adjustedDepthDel / adjustedDelLociCnt;
boolean avgDepthDelIsAdjusted = false;
if (adjustedAvgDepthDel > avgDepthDel) {
setAvgDepthDeletion(adjustedAvgDepthDel);
setAvgMapQDeletion(adjustedMapQDel / adjustedDelLociCnt);
setAvgSeqQDeletion(adjustedSeqQDel / adjustedDelLociCnt);
avgDepthDelIsAdjusted = true;
// int medIndex = adjustedDeletionList.size();
// double median;
// if(medIndex%2==0){
// medIndex = medIndex / 2;
// median = (double)((Integer) adjustedDeletionList.get(medIndex-1) + (Integer)adjustedDeletionList.get(medIndex))/2.0;
// }else{
// medIndex = medIndex / 2;
// median = (double)(Integer)adjustedDeletionList.get(medIndex);
// }
// setMedianDepthDeletion(median);
} else {
setAvgDepthDeletion(avgDepthDel);
setAvgMapQDeletion(mapQDel / DelLociCnt);
setAvgSeqQDeletion(seqQDel / DelLociCnt);
// int medIndex = deletionList.size();
// double median;
// if(medIndex%2==0){
// medIndex = medIndex / 2;
// median = (double)((Integer) deletionList.get(medIndex-1) + (Integer)deletionList.get(medIndex))/2.0;
// }else{
// medIndex = medIndex / 2;
// median = (double)(Integer)deletionList.get(medIndex);
// }
// setMedianDepthDeletion(median);
}
double avgDepthWindow = depthWindow / WindowLociCnt;
double adjustedAvgDepthWindow = adjustedDepthWindow / adjustedWindowLociCnt;
boolean avgDepthWindowIsAdjusted = false;
if (adjustedAvgDepthWindow > avgDepthWindow) {
setAvgDepthWindow(adjustedAvgDepthWindow);
setAvgMapQWindow(adjustedMapQWindow / adjustedWindowLociCnt);
setAvgSeqQWindow(adjustedSeqQWindow / adjustedWindowLociCnt);
avgDepthWindowIsAdjusted = true;
// int medIndex = adjustedWindowList.size();
// double median;
// if(medIndex%2==0){
// medIndex = medIndex / 2;
// median = (double)((Integer) adjustedWindowList.get(medIndex-1) + (Integer)adjustedWindowList.get(medIndex))/2.0;
// }else{
// medIndex = medIndex / 2;
// median = (double)(Integer)adjustedWindowList.get(medIndex);
// }
// setMedianDepthWindow(median);
} else {
setAvgDepthWindow(avgDepthWindow);
setAvgMapQWindow(mapQWindow / WindowLociCnt);
setAvgSeqQWindow(seqQWindow / WindowLociCnt);
// int medIndex = windowList.size();
// double median;
// if(medIndex%2==0){
// medIndex = medIndex / 2;
// median = (double)((Integer) windowList.get(medIndex-1) + (Integer)windowList.get(medIndex))/2.0;
// }else{
// medIndex = medIndex / 2;
// median = (double)(Integer)windowList.get(medIndex);
// }
// setMedianDepthWindow(median);
}
setCellularity(1.0 - getAvgDepthDeletion() / getAvgDepthWindow()); // mean
// setCellularity(1.0 - getMedianDepthDeletion() / getMedianDepthWindow()); // median
for (int i = 0; i < size; i++) {
Locus loc = (Locus) l.get(i);
int pos = loc.getPos();
boolean overlapped = isOverlapped(pos, overlappedAreaList);
if (i < delStartIdx || i > delEndIdx) {
if (loc.getDepth() > 0) {
double diff = loc.getDepth() - getAvgDepthWindow();
diffWindow += diff * diff;
if(!overlapped){
adjustedDiffWindow += diff * diff;
}
}
} else {
double diff = loc.getDepth() - getAvgDepthDeletion();
diffDel += diff * diff;
if(!overlapped){
adjustedDiffDel += diff * diff;
}
}
}
if(avgDepthDelIsAdjusted){
setStdDeletion(Math.sqrt(adjustedDiffDel / adjustedDelLociCnt));
}else{
setStdDeletion(Math.sqrt(diffDel / DelLociCnt));
}
if(avgDepthWindowIsAdjusted){
setStdWindow(Math.sqrt(adjustedDiffWindow / adjustedWindowLociCnt));
}else{
setStdWindow(Math.sqrt(diffWindow / WindowLociCnt));
}
if(getAvgDepthDeletion() != 0){
// setCoefficientOfvariation(getStdDeletion()/getAvgDepthDeletion());
setCoefficientOfvariation((1+1/(4.0*DelLociCnt))*(getStdDeletion()/getAvgDepthDeletion())); // unbiased estimator for a sample size n
}
}
}
public String print() {
return getChr() + "\t" + getPos1() + "\t" + getPos2() + "\t" + (getPos2() - getPos1()) + "\t" + getNum_read() + "\t" + getAvgDepthDeletion() + "\t" + getAvgDepthWindow() + "\t" + getStdDeletion() + "\t" + getStdWindow() + "\t" + getCellularity();
}
/**
* @return the num_read
*/
public int getNum_read() {
return num_read;
}
/**
* @param num_read the num_read to set
*/
public void setNum_read(int num_read) {
this.num_read = num_read;
}
/**
* @return the cellularity
*/
public double getCellularity() {
if (cellularity == 0) {
cellularity = 1.0 - avgDepthDeletion / avgDepthWindow;
}
return cellularity;
}
/**
* @param cellularity the cellularity to set
*/
public void setCellularity(double cellularity) {
this.cellularity = cellularity;
}
public double getDeletionDepth() {
return avgDepthWindow - avgDepthDeletion;
}
/**
* @return the germlineProbability
*/
public double getGermlineProbability() {
return germlineProbability;
}
/**
* @param germlineProbability the germlineProbability to set
*/
public void setGermlineProbability(double germlineProbability) {
this.germlineProbability = germlineProbability;
}
/**
* @return the mixedProbability
*/
public double getMixedProbability() {
return mixedProbability;
}
/**
* @param mixedProbability the mixedProbability to set
*/
public void setMixedProbability(double mixedProbability) {
this.mixedProbability = mixedProbability;
}
/**
* @return the homology
*/
public boolean isHomology() {
return homology;
}
/**
* @param homology the homology to set
*/
public void setHomology(boolean homology) {
this.homology = homology;
}
/**
* @return the homozygousDel
*/
public boolean isHomozygousDel() {
return homozygousDel;
}
/**
* @param homozygousDel the homozygousDel to set
*/
public void setHomozygousDel(boolean homozygousDel) {
this.homozygousDel = homozygousDel;
}
/**
* @return the mixedSomaticProbability
*/
public double getMixedSomaticProbability() {
return mixedSomaticProbability;
}
/**
* @param mixedSomaticProbability the mixedSomaticProbability to set
*/
public void setMixedSomaticProbability(double mixedSomaticProbability) {
this.mixedSomaticProbability = mixedSomaticProbability;
}
/**
* @return the gap
*/
public boolean isGap() {
return gap;
}
/**
* @param gap the gap to set
*/
public void setGap(boolean gap) {
this.gap = gap;
}
public boolean isOverlapped(int pos, ArrayList overlappedAreaList) {
int size = overlappedAreaList.size();
boolean overlapped = false;
for (int i = 0; i < size; i++) {
Integer[] overlappedArea = (Integer[]) overlappedAreaList.get(i);
if (overlappedArea[0] <= pos && overlappedArea[1] >= pos) {
overlapped = true;
break;
}
}
return overlapped;
}
/**
* @return the coefficientOfvariation
*/
public double getCoefficientOfvariation() {
return coefficientOfvariation;
}
/**
* @param coefficientOfvariation the coefficientOfvariation to set
*/
public void setCoefficientOfvariation(double coefficientOfvariation) {
this.coefficientOfvariation = coefficientOfvariation;
}
// /**
// * @return the medianDepthDeletion
// */
// public double getMedianDepthDeletion() {
// return medianDepthDeletion;
// }
//
// /**
// * @param medianDepthDeletion the medianDepthDeletion to set
// */
// public void setMedianDepthDeletion(double medianDepthDeletion) {
// this.medianDepthDeletion = medianDepthDeletion;
// }
//
// /**
// * @return the medianDepthWindow
// */
// public double getMedianDepthWindow() {
// return medianDepthWindow;
// }
//
// /**
// * @param medianDepthWindow the medianDepthWindow to set
// */
// public void setMedianDepthWindow(double medianDepthWindow) {
// this.medianDepthWindow = medianDepthWindow;
// }
}