-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
2,385 additions
and
381 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
/.gradle/ | ||
/build/ | ||
.metadata | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
src/main/java/scriptmanager/cli/BAM_Statistics/CrossCorrelationCLI.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
package scriptmanager.cli.BAM_Statistics; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.concurrent.Callable; | ||
|
||
import picocli.CommandLine.ArgGroup; | ||
import picocli.CommandLine.Command; | ||
import picocli.CommandLine.Option; | ||
import picocli.CommandLine.Parameters; | ||
import scriptmanager.objects.ToolDescriptions; | ||
import scriptmanager.objects.ArchTEx.CorrParameter; | ||
import scriptmanager.scripts.BAM_Statistics.CrossCorrelation; | ||
import scriptmanager.util.ExtensionFileFilter; | ||
|
||
/** | ||
* Command line interface class for performing the ArchTEX cross correlation | ||
* analysis by calling a method implemented in the scripts package. | ||
* | ||
* @author Olivia Lang | ||
* @see scriptmanager.objects.ArchTEx.CorrParameter | ||
* @see scriptmanager.scripts.BAM_Statistics.CrossCorrelation | ||
*/ | ||
@Command(name = "cross-corr", mixinStandardHelpOptions = true, | ||
description = ToolDescriptions.archtex_crosscorrelation_description, | ||
version = "ScriptManager "+ ToolDescriptions.VERSION, | ||
sortOptions = false, | ||
exitCodeOnInvalidInput = 1, | ||
exitCodeOnExecutionException = 1) | ||
public class CrossCorrelationCLI implements Callable<Integer> { | ||
|
||
@Parameters( index = "0", description = "The BAM file to perform the cross-correlation on") | ||
private File bamFile; | ||
|
||
@Option(names = {"-o", "--output"}, description = "specify output basename, default is the BAM input filename without extension") | ||
private File outputBasename = null; | ||
|
||
@ArgGroup(exclusive = true, multiplicity = "0..1", heading = "%nSelect correlation strategy:%n\t@|fg(red) (select no more than one of these options)|@%n") | ||
CorrType corrType = new CorrType(); | ||
static class CorrType { | ||
@Option(names = {"-g", "--genome"}, description = "Use the full genome correlation method") | ||
private boolean corrGenome = false; | ||
@Option(names = {"-r", "--random"}, description = "Use the random sampling correlation method (default)") | ||
private boolean corrRandom = false; | ||
} | ||
|
||
@Option(names = {"-t", "--cpu"}, description = "set number of threads for performance tuning (default=1)") | ||
private int cpu = 1; | ||
|
||
@ArgGroup(exclusive = true, multiplicity = "0..1", heading = "%nRandom Sampling Options:%n\t@|fg(red) (ignored if full genome correlation method selected)|@%n") | ||
SamplingParams samplingParams = new SamplingParams(); | ||
static class SamplingParams { | ||
@Option(names = {"-w", "--window"}, description = "set window frame size for each extraction (default=50kb)") | ||
private int windowSize = 50000; | ||
@Option(names = {"-i", "--iterations"}, description = "set number of random iterations per chromosome (default=10)") | ||
private int iterations = 10; | ||
} | ||
|
||
CorrParameter param = new CorrParameter(); | ||
|
||
@Override | ||
public Integer call() throws Exception { | ||
System.err.println( ">CrossCorrelationCLI.call()" ); | ||
String validate = validateInput(); | ||
if(!validate.equals("")){ | ||
System.err.println( validate ); | ||
System.err.println("Invalid input. Check usage using '-h' or '--help'"); | ||
System.exit(1); | ||
} | ||
|
||
CrossCorrelation.correlate( outputBasename, bamFile, param, null); | ||
|
||
System.err.println("Calculations Complete"); | ||
return(0); | ||
} | ||
|
||
/** | ||
* Validate the input values before executing the script. | ||
* | ||
* @return a multi-line string describing input validation issues | ||
* @throws IOException | ||
*/ | ||
private String validateInput() throws IOException { | ||
String r = ""; | ||
|
||
//check inputs exist | ||
if(!bamFile.exists()){ | ||
r += "(!)BAM file does not exist: " + bamFile.getName() + "\n"; | ||
return(r); | ||
} | ||
//check BAI exists | ||
File f = new File(bamFile+".bai"); | ||
if(!f.exists() || f.isDirectory()){ | ||
r += "(!)BAI Index File does not exist for: " + bamFile.getName() + "\n"; | ||
} | ||
//set default output filename | ||
if(outputBasename==null){ | ||
// output = new File("output_bam_stats.txt"); //this default name mimics the gui | ||
outputBasename = new File(ExtensionFileFilter.stripExtension(bamFile) + "_CrossCorrelation.txt"); | ||
//check output filename is valid | ||
}else{ | ||
//no check ext | ||
//check directory | ||
if(outputBasename.getParent()==null){ | ||
// System.err.println("default to current directory"); | ||
} else if(!new File(outputBasename.getParent()).exists()){ | ||
r += "(!)Check output directory exists: " + outputBasename.getParent() + "\n"; | ||
} | ||
} | ||
|
||
//validate random sampling params | ||
if (corrType.corrGenome) { | ||
param.setCorrType(true); | ||
} else { | ||
param.setCorrType(false); | ||
if (samplingParams.windowSize<1) { r += "(!)Window size must be at least 1\n"; } | ||
if (samplingParams.iterations<1) { r += "(!)Num iterations must be at least 1\n"; } | ||
param.setWindow(samplingParams.windowSize); | ||
} | ||
// valiate CPU | ||
if (cpu<1) { r += "(!)CPU count must be at least 1\n"; } | ||
param.setThreads(cpu); | ||
|
||
return(r); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.