Skip to content

Commit a6682d5

Browse files
committed
added CNV compare feature
1 parent ad1fa18 commit a6682d5

File tree

8 files changed

+581
-22
lines changed

8 files changed

+581
-22
lines changed

src/bedUtils/BedUtils.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
package bedUtils;
2-
import java.beans.IntrospectionException;
32
import java.io.BufferedReader;
43
import java.io.File;
54
import java.io.FileNotFoundException;
65
import java.io.FileReader;
76
import java.io.IOException;
87
import java.io.PrintWriter;
98
import java.nio.file.Path;
10-
import java.nio.file.Paths;
119
import java.util.HashMap;
1210
import java.util.List;
1311
import java.util.Map;
1412
import java.util.Set;
1513
import java.util.TreeSet;
1614

17-
import liftoverutils.*;
15+
import liftoverutils.BedInterval;
16+
import liftoverutils.Interval;
17+
import liftoverutils.IntervalTree;
18+
import liftoverutils.IntervalUtils;
1819

1920
public class BedUtils {
2021

src/cnv_compare/CnvCompare.java

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
package cnv_compare;
2+
3+
import java.io.BufferedReader;
4+
import java.io.File;
5+
import java.io.FileNotFoundException;
6+
import java.io.FileReader;
7+
import java.io.IOException;
8+
import java.io.PrintWriter;
9+
import java.nio.file.Path;
10+
import java.nio.file.Paths;
11+
import java.util.ArrayList;
12+
import java.util.List;
13+
14+
import liftoverutils.Interval;
15+
import liftoverutils.IntervalNode;;
16+
17+
public class CnvCompare {
18+
19+
20+
public static void main(String[] args) {
21+
File cnvFile1 = new File("C:\\Users\\manojkumar_bhosale\\Desktop\\ToDelete\\forCNV\\test1.txt");
22+
File cnvFile2 = new File("C:\\Users\\manojkumar_bhosale\\Desktop\\ToDelete\\forCNV\\test2.txt");
23+
Path outDir = Paths.get("C:\\Users\\manojkumar_bhosale\\Desktop\\ToDelete\\forCNV");
24+
}
25+
26+
public static void compareCnvFilesToFolder(File cnvFile1, File cnvFile2, Path outDir) {
27+
CnvCompare cc = new CnvCompare();
28+
cc.compareCnv(cnvFile1, cnvFile2, outDir);
29+
}
30+
31+
32+
void compareCnv(File cnvFile1, File cnvFile2, Path outDir) {
33+
List<Interval<CnvInterval>> intervalList = new ArrayList<Interval<CnvInterval>>();
34+
File comparisonFile = outDir.resolve(cnvFile1.getName().replace(".", "_")+""+cnvFile2.getName()).toFile();
35+
int leftNumIntervals = 0;
36+
int rightNumIntervals = 0;
37+
int leftOverlap = 0;
38+
int rightOverlap = 0;
39+
int exactMatch = 0;
40+
int within = 0;
41+
int covering = 0;
42+
int noMatch = 0;
43+
44+
try(BufferedReader br = new BufferedReader(new FileReader(cnvFile1));BufferedReader br1 = new BufferedReader(new FileReader(cnvFile2)); PrintWriter pw = new PrintWriter(comparisonFile)){
45+
String line = "";
46+
while((line = br1.readLine()) != null) {
47+
if(line.startsWith("#"))
48+
continue;
49+
leftNumIntervals++;
50+
String[] splitedRec = line.split("\t");
51+
String chr = splitedRec[0];
52+
int start = Integer.parseInt(splitedRec[1]);
53+
int stop = Integer.parseInt(splitedRec[2]);
54+
String type = splitedRec[6];
55+
CnvInterval cnvInterval = new CnvInterval(chr, start, stop, type);
56+
Interval<CnvInterval> interval = new Interval<CnvInterval>(start, stop, cnvInterval);
57+
intervalList.add(interval);
58+
}
59+
60+
IntervalNode<CnvInterval> masterNode = new IntervalNode<>(intervalList);
61+
line = "";
62+
63+
while((line = br.readLine()) != null) {
64+
if(line.startsWith("#"))
65+
continue;
66+
rightNumIntervals++;
67+
String[] splitedRec = line.split("\t");
68+
String chr = splitedRec[0];
69+
int start = Integer.parseInt(splitedRec[1]);
70+
int stop = Integer.parseInt(splitedRec[2]);
71+
String type = splitedRec[6];
72+
CnvInterval cnvInterval = new CnvInterval(chr, start, stop, type);
73+
Interval<CnvInterval> interval = new Interval<CnvInterval>(start, stop, cnvInterval);
74+
List<Interval<CnvInterval>> intersectList = masterNode.query(interval);
75+
boolean noMatchFlag = true;
76+
for(Interval<CnvInterval> intersect : intersectList){
77+
int res = getVerdict(cnvInterval, intersect.getData());
78+
if(res == 0) {
79+
exactMatch++;
80+
noMatchFlag = false;
81+
}else if(res == 1) {
82+
covering++;
83+
noMatchFlag = false;
84+
}else if(res == 2) {
85+
within++;
86+
noMatchFlag = false;
87+
}else if(res == 3) {
88+
leftOverlap++;
89+
noMatchFlag = false;
90+
}else if(res == 4){
91+
rightOverlap++;
92+
noMatchFlag = false;
93+
}
94+
}
95+
96+
if(noMatchFlag)
97+
noMatch++;
98+
99+
}
100+
101+
pw.println("File1\tFile2\t#Intervals in File1\t#Intervals in File2\tExact matches\tCovering\tWithin\tLeft overlap\tRight Overlap\tNo overlap");
102+
pw.println(cnvFile1+"\t"+cnvFile2+"\t"+rightNumIntervals+"\t"+leftNumIntervals+"\t"+exactMatch+"\t"+covering+"\t"+within+"\t"+leftOverlap+"\t"+rightOverlap+"\t"+noMatch);
103+
104+
} catch (FileNotFoundException e) {
105+
// TODO Auto-generated catch block
106+
e.printStackTrace();
107+
} catch (IOException e) {
108+
// TODO Auto-generated catch block
109+
e.printStackTrace();
110+
}
111+
}
112+
113+
int getVerdict(CnvInterval inter1, CnvInterval inter2){
114+
if(cnvOfSameType(inter1, inter2) && isSameChr(inter1, inter2)) {
115+
if(inter1.getStartPosition() == inter2.getStartPosition() && inter1.getStopPosition() == inter2.getStopPosition()) {
116+
return 0; //exact match
117+
}else if(inter1.getStartPosition() <= inter2.getStartPosition() && inter1.getStopPosition() >= inter2.getStopPosition()) {
118+
return 1; //covering
119+
}else if(inter1.getStartPosition() >= inter2.getStartPosition() && inter1.getStopPosition() <= inter2.getStopPosition()){
120+
return 2; //within
121+
}else if(inter1.getStartPosition() <= inter2.getStartPosition() && inter1.getStopPosition() <= inter2.getStopPosition()){
122+
return 3; //left overlap
123+
}else if(inter1.getStartPosition() >= inter2.getStartPosition() && inter1.getStopPosition() >= inter2.getStopPosition()){
124+
return 4; //right overlap
125+
}
126+
}
127+
return 5;
128+
}
129+
130+
boolean cnvOfSameType(CnvInterval inter1, CnvInterval inter2) {
131+
return (inter1.getType()).equals(inter2.getType());
132+
}
133+
134+
boolean isSameChr(CnvInterval inter1, CnvInterval inter2) {
135+
return (inter1.getChromosome()).equals(inter2.getChromosome());
136+
}
137+
138+
139+
public static void readCnvFile(File cnvFile) {
140+
141+
142+
143+
}
144+
145+
}

src/cnv_compare/CnvInterval.java

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package cnv_compare;
2+
3+
public class CnvInterval {
4+
5+
private String chromosome;
6+
private int startPosition;
7+
private int stopPosition;
8+
private String type;
9+
private float logRatio;
10+
private int copyNumber;
11+
12+
public CnvInterval(String chromosome, int startPosition, int stopPosition, String type, float logRatio,
13+
int copyNumber) {
14+
super();
15+
this.chromosome = chromosome;
16+
this.startPosition = startPosition;
17+
this.stopPosition = stopPosition;
18+
this.type = type;
19+
this.logRatio = logRatio;
20+
this.copyNumber = copyNumber;
21+
}
22+
23+
public CnvInterval(String chromosome, int startPosition, int stopPosition, String type) {
24+
super();
25+
this.chromosome = chromosome.toUpperCase();
26+
this.startPosition = startPosition;
27+
this.stopPosition = stopPosition;
28+
this.type = type.toUpperCase();
29+
this.logRatio = 0;
30+
this.copyNumber = 0;
31+
}
32+
33+
public CnvInterval(String chromosome, int startPosition, int stopPosition) {
34+
super();
35+
this.chromosome = chromosome;
36+
this.startPosition = startPosition;
37+
this.stopPosition = stopPosition;
38+
this.type = "";
39+
this.logRatio = 0;
40+
this.copyNumber = 0;
41+
}
42+
43+
public String getChromosome() {
44+
return chromosome;
45+
}
46+
47+
public void setChromosome(String chromosome) {
48+
this.chromosome = chromosome;
49+
}
50+
51+
public int getStartPosition() {
52+
return startPosition;
53+
}
54+
55+
public void setStartPosition(int startPosition) {
56+
this.startPosition = startPosition;
57+
}
58+
59+
public int getStopPosition() {
60+
return stopPosition;
61+
}
62+
63+
public void setStopPosition(int stopPosition) {
64+
this.stopPosition = stopPosition;
65+
}
66+
67+
public String getType() {
68+
return type;
69+
}
70+
71+
public void setType(String type) {
72+
this.type = type;
73+
}
74+
75+
public float getLogRatio() {
76+
return logRatio;
77+
}
78+
79+
public void setLogRatio(float logRatio) {
80+
this.logRatio = logRatio;
81+
}
82+
83+
public int getCopyNumber() {
84+
return copyNumber;
85+
}
86+
87+
public void setCopyNumber(int copyNumber) {
88+
this.copyNumber = copyNumber;
89+
}
90+
91+
}

src/com/psl/automation/main/MainGui.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
package com.psl.automation.main;
22

3-
import hsutils.BamSorter;
4-
53
import java.awt.Color;
6-
import java.awt.Dimension;
7-
import java.awt.FlowLayout;
84
import java.awt.Font;
9-
import java.awt.GridLayout;
105
import java.awt.Insets;
116
import java.awt.event.ActionEvent;
127
import java.awt.event.ActionListener;
@@ -39,11 +34,14 @@
3934

4035
import com.psl.automation.panels.BarcodeMetricsPanel;
4136
import com.psl.automation.panels.BedUtilitiesPanel;
37+
import com.psl.automation.panels.CnvComparePanel;
4238
import com.psl.automation.panels.CompareVcfPanel;
4339
import com.psl.automation.panels.QCComparePanel;
4440
import com.psl.automation.panels.TsTvMetricsPanel;
4541
import com.psl.automation.panels.VcfBedIntersectionPanel;
4642

43+
import hsutils.BamSorter;
44+
4745
public class MainGui implements ActionListener,Runnable{
4846
//Log4j logger
4947
private static Logger log4jLog = Logger.getLogger(MainGui.class.getName());
@@ -81,12 +79,14 @@ public void run(){
8179
QCComparePanel qcp = new QCComparePanel();
8280
VcfBedIntersectionPanel vbedp = new VcfBedIntersectionPanel();
8381
BedUtilitiesPanel bup = new BedUtilitiesPanel();
82+
CnvComparePanel ccp = new CnvComparePanel();
8483
jtp.addTab("VCF comparator", cvp.createCompareVcfPanel());
8584
jtp.addTab("HS Util", bmp.createFileConfigPanel());
8685
jtp.addTab("VCF Util", tstvp.createVcfUtilPanel());
8786
jtp.addTab("QC compare", qcp.createCompareQcPanel());
8887
jtp.addTab("VCF BED intersect", vbedp.createIntersectVcfPanel());
8988
jtp.addTab("BED intersect", bup.createIntersectBedPanel());
89+
jtp.addTab("CNV intersect", ccp.createCnvComparePanel());
9090

9191
jtp.addChangeListener(new TabSelected());
9292

src/com/psl/automation/panels/BedUtilitiesPanel.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
package com.psl.automation.panels;
22

3-
import java.awt.Color;
4-
import java.awt.Component;
53
import java.awt.Dimension;
64
import java.awt.FlowLayout;
7-
import java.awt.GridLayout;
85
import java.awt.event.ActionEvent;
96
import java.awt.event.ActionListener;
10-
import java.io.BufferedReader;
117
import java.io.File;
12-
import java.io.FileReader;
13-
import java.io.IOException;
148

159
import javax.swing.BorderFactory;
1610
import javax.swing.Box;
@@ -19,17 +13,12 @@
1913
import javax.swing.JFileChooser;
2014
import javax.swing.JLabel;
2115
import javax.swing.JPanel;
22-
import javax.swing.JScrollPane;
23-
import javax.swing.JTable;
2416
import javax.swing.JTextField;
2517
import javax.swing.filechooser.FileNameExtensionFilter;
26-
import javax.swing.table.DefaultTableModel;
27-
import javax.swing.table.TableCellRenderer;
2818

2919
import bedUtils.BedUtils;
3020
import vcfutils.CompareUtils;
3121
import vcfutils.ComparisonResult;
32-
import vcfutils.VCFBedIntersect;
3322

3423
public class BedUtilitiesPanel {
3524

0 commit comments

Comments
 (0)