Skip to content

Commit ad9b667

Browse files
authored
Merge pull request #120 from CEGRcode/archtex
Add Cross Correlation from Archtex
2 parents f9b4a0c + bf1d10c commit ad9b667

File tree

10 files changed

+1437
-6
lines changed

10 files changed

+1437
-6
lines changed
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
package scriptmanager.cli.BAM_Statistics;
2+
3+
import java.io.File;
4+
import java.io.IOException;
5+
import java.util.concurrent.Callable;
6+
7+
import picocli.CommandLine.ArgGroup;
8+
import picocli.CommandLine.Command;
9+
import picocli.CommandLine.Option;
10+
import picocli.CommandLine.Parameters;
11+
import scriptmanager.objects.ToolDescriptions;
12+
import scriptmanager.objects.ArchTEx.CorrParameter;
13+
import scriptmanager.scripts.BAM_Statistics.CrossCorrelation;
14+
import scriptmanager.util.ExtensionFileFilter;
15+
16+
/**
17+
* Command line interface class for performing the ArchTEX cross correlation
18+
* analysis by calling a method implemented in the scripts package.
19+
*
20+
* @author Olivia Lang
21+
* @see scriptmanager.objects.ArchTEx.CorrParameter
22+
* @see scriptmanager.scripts.BAM_Statistics.CrossCorrelation
23+
*/
24+
@Command(name = "cross-corr", mixinStandardHelpOptions = true,
25+
description = ToolDescriptions.archtex_crosscorrelation_description,
26+
version = "ScriptManager "+ ToolDescriptions.VERSION,
27+
sortOptions = false,
28+
exitCodeOnInvalidInput = 1,
29+
exitCodeOnExecutionException = 1)
30+
public class CrossCorrelationCLI implements Callable<Integer> {
31+
32+
@Parameters( index = "0", description = "The BAM file to perform the cross-correlation on")
33+
private File bamFile;
34+
35+
@Option(names = {"-o", "--output"}, description = "specify output basename, default is the BAM input filename without extension")
36+
private File outputBasename = null;
37+
38+
@ArgGroup(exclusive = true, multiplicity = "0..1", heading = "%nSelect correlation strategy:%n\t@|fg(red) (select no more than one of these options)|@%n")
39+
CorrType corrType = new CorrType();
40+
static class CorrType {
41+
@Option(names = {"-g", "--genome"}, description = "Use the full genome correlation method")
42+
private boolean corrGenome = false;
43+
@Option(names = {"-r", "--random"}, description = "Use the random sampling correlation method (default)")
44+
private boolean corrRandom = false;
45+
}
46+
47+
@Option(names = {"-t", "--cpu"}, description = "set number of threads for performance tuning (default=1)")
48+
private int cpu = 1;
49+
50+
@ArgGroup(exclusive = true, multiplicity = "0..1", heading = "%nRandom Sampling Options:%n\t@|fg(red) (ignored if full genome correlation method selected)|@%n")
51+
SamplingParams samplingParams = new SamplingParams();
52+
static class SamplingParams {
53+
@Option(names = {"-w", "--window"}, description = "set window frame size for each extraction (default=50kb)")
54+
private int windowSize = 50000;
55+
@Option(names = {"-i", "--iterations"}, description = "set number of random iterations per chromosome (default=10)")
56+
private int iterations = 10;
57+
}
58+
59+
CorrParameter param = new CorrParameter();
60+
61+
@Override
62+
public Integer call() throws Exception {
63+
System.err.println( ">CrossCorrelationCLI.call()" );
64+
String validate = validateInput();
65+
if(!validate.equals("")){
66+
System.err.println( validate );
67+
System.err.println("Invalid input. Check usage using '-h' or '--help'");
68+
System.exit(1);
69+
}
70+
71+
CrossCorrelation.correlate( outputBasename, bamFile, param, null);
72+
73+
System.err.println("Calculations Complete");
74+
return(0);
75+
}
76+
77+
/**
78+
* Validate the input values before executing the script.
79+
*
80+
* @return a multi-line string describing input validation issues
81+
* @throws IOException
82+
*/
83+
private String validateInput() throws IOException {
84+
String r = "";
85+
86+
//check inputs exist
87+
if(!bamFile.exists()){
88+
r += "(!)BAM file does not exist: " + bamFile.getName() + "\n";
89+
return(r);
90+
}
91+
//check BAI exists
92+
File f = new File(bamFile+".bai");
93+
if(!f.exists() || f.isDirectory()){
94+
r += "(!)BAI Index File does not exist for: " + bamFile.getName() + "\n";
95+
}
96+
//set default output filename
97+
if(outputBasename==null){
98+
// output = new File("output_bam_stats.txt"); //this default name mimics the gui
99+
outputBasename = new File(ExtensionFileFilter.stripExtension(bamFile) + "_CrossCorrelation.txt");
100+
//check output filename is valid
101+
}else{
102+
//no check ext
103+
//check directory
104+
if(outputBasename.getParent()==null){
105+
// System.err.println("default to current directory");
106+
} else if(!new File(outputBasename.getParent()).exists()){
107+
r += "(!)Check output directory exists: " + outputBasename.getParent() + "\n";
108+
}
109+
}
110+
111+
//validate random sampling params
112+
if (corrType.corrGenome) {
113+
param.setCorrType(true);
114+
} else {
115+
param.setCorrType(false);
116+
if (samplingParams.windowSize<1) { r += "(!)Window size must be at least 1\n"; }
117+
if (samplingParams.iterations<1) { r += "(!)Num iterations must be at least 1\n"; }
118+
param.setWindow(samplingParams.windowSize);
119+
}
120+
// valiate CPU
121+
if (cpu<1) { r += "(!)CPU count must be at least 1\n"; }
122+
param.setThreads(cpu);
123+
124+
return(r);
125+
}
126+
}

src/main/java/scriptmanager/main/ScriptManager.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import scriptmanager.cli.BAM_Manipulation.MergeBAMCLI;
1919
import scriptmanager.cli.BAM_Manipulation.SortBAMCLI;
2020

21+
import scriptmanager.cli.BAM_Statistics.CrossCorrelationCLI;
2122
import scriptmanager.cli.BAM_Statistics.BAMGenomeCorrelationCLI;
2223
import scriptmanager.cli.BAM_Statistics.PEStatsCLI;
2324
import scriptmanager.cli.BAM_Statistics.SEStatsCLI;
@@ -42,7 +43,6 @@
4243
import scriptmanager.cli.File_Utilities.MD5ChecksumCLI;
4344
import scriptmanager.cli.File_Utilities.ConvertBEDChrNamesCLI;
4445
import scriptmanager.cli.File_Utilities.ConvertGFFChrNamesCLI;
45-
4646
import scriptmanager.cli.Peak_Analysis.BEDPeakAligntoRefCLI;
4747
import scriptmanager.cli.Peak_Analysis.FilterBEDbyProximityCLI;
4848
import scriptmanager.cli.Peak_Analysis.RandomCoordinateCLI;
@@ -141,11 +141,12 @@ class BAM_ManipulationCLI extends SubcommandCLI {}
141141

142142
@Command(name = "bam-statistics",
143143
subcommands = {
144+
CrossCorrelationCLI.class,
144145
BAMGenomeCorrelationCLI.class,
145146
PEStatsCLI.class,
146147
SEStatsCLI.class
147148
},
148-
description = "Includes tools like BAMGenomeCorrelationCLI, PEStatsCLI, and SEStatsCLI.")
149+
description = "Includes tools like SEStatsCLI, PEStatsCLI, BAMGenomeCorrelationCLI, and CrossCorrelationCLI.")
149150
class BAM_StatisticsCLI extends SubcommandCLI {}
150151

151152

src/main/java/scriptmanager/main/ScriptManagerGUI.java

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import scriptmanager.window_interface.BAM_Statistics.PEStatWindow;
2020
import scriptmanager.window_interface.BAM_Statistics.SEStatWindow;
2121
import scriptmanager.window_interface.BAM_Statistics.BAMGenomeCorrelationWindow;
22+
import scriptmanager.window_interface.BAM_Statistics.CrossCorrelationWindow;
2223
import scriptmanager.window_interface.BAM_Manipulation.BAIIndexerWindow;
2324
import scriptmanager.window_interface.BAM_Manipulation.BAMMarkDupWindow;
2425
import scriptmanager.window_interface.BAM_Manipulation.FilterforPIPseqWindow;
@@ -176,13 +177,40 @@ public void run() {
176177
});
177178
}
178179
});
179-
sl_pnlStat.putConstraint(SpringLayout.NORTH, btnBamGenomeCorrelation, 0, SpringLayout.NORTH,
180-
txtBamGenomeCorrelation);
180+
sl_pnlStat.putConstraint(SpringLayout.NORTH, btnBamGenomeCorrelation, 0, SpringLayout.NORTH, txtBamGenomeCorrelation);
181181
sl_pnlStat.putConstraint(SpringLayout.WEST, btnBamGenomeCorrelation, 10, SpringLayout.WEST, pnlStat);
182-
sl_pnlStat.putConstraint(SpringLayout.WEST, txtBamGenomeCorrelation, 10, SpringLayout.EAST,
183-
btnBamGenomeCorrelation);
182+
sl_pnlStat.putConstraint(SpringLayout.WEST, txtBamGenomeCorrelation, 10, SpringLayout.EAST, btnBamGenomeCorrelation);
184183
pnlStat.add(btnBamGenomeCorrelation);
185184

185+
// >CrossCorrelation
186+
JTextArea txtCrossCorrelation = new JTextArea();
187+
initializeTextArea(txtCrossCorrelation);
188+
txtCrossCorrelation.setText(ToolDescriptions.archtex_crosscorrelation_description);
189+
sl_pnlStat.putConstraint(SpringLayout.NORTH, txtCrossCorrelation, 10, SpringLayout.SOUTH, txtBamGenomeCorrelation);
190+
sl_pnlStat.putConstraint(SpringLayout.EAST, txtCrossCorrelation, -10, SpringLayout.EAST, pnlStat);
191+
pnlStat.add(txtCrossCorrelation);
192+
193+
JButton btnCrossCorrelation = new JButton("Cross Correlation");
194+
btnCrossCorrelation.setToolTipText("Calculate optimal tag shift based on ArchTEx implementation (PMID:22302569)");
195+
btnCrossCorrelation.addActionListener(new ActionListener() {
196+
public void actionPerformed(ActionEvent arg0) {
197+
EventQueue.invokeLater(new Runnable() {
198+
public void run() {
199+
try {
200+
CrossCorrelationWindow frame = new CrossCorrelationWindow();
201+
frame.setVisible(true);
202+
} catch (Exception e) {
203+
e.printStackTrace();
204+
}
205+
}
206+
});
207+
}
208+
});
209+
sl_pnlStat.putConstraint(SpringLayout.NORTH, btnCrossCorrelation, 0, SpringLayout.NORTH, txtCrossCorrelation);
210+
sl_pnlStat.putConstraint(SpringLayout.WEST, btnCrossCorrelation, 10, SpringLayout.WEST, pnlStat);
211+
sl_pnlStat.putConstraint(SpringLayout.WEST, txtCrossCorrelation, 10, SpringLayout.EAST, btnCrossCorrelation);
212+
pnlStat.add(btnCrossCorrelation);
213+
186214
// >>>>>>>> BAM_Manipulation <<<<<<<<
187215
JPanel pnlBamManip = new JPanel();
188216
SpringLayout sl_pnlBamManip = new SpringLayout();

0 commit comments

Comments
 (0)