Skip to content

Commit

Permalink
Merge branch 'dev' into working-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
owlang committed Jun 29, 2023
2 parents f411d02 + 348835a commit 149cfcd
Show file tree
Hide file tree
Showing 29 changed files with 2,385 additions and 381 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/.gradle/
/build/
.metadata
.idea
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import picocli.CommandLine.Command;

import java.io.File;
import java.util.concurrent.Callable;

import scriptmanager.objects.ToolDescriptions;
Expand Down Expand Up @@ -29,4 +30,13 @@ public Integer call() throws Exception {
System.exit(1);
return(1);
}

public static String getCLIcommand(File BAM, boolean removeDuplicates, File OUTPUT, File METRICS) {
String command = "java -jar $PICARD MarkDuplicates";
command += " INPUT=" + BAM.getAbsolutePath();
command += " OUTPUT=" + OUTPUT.getAbsolutePath();
command += " METRICS_FILE=" + METRICS.getAbsolutePath();
command += removeDuplicates ? "REMOVE_DUPLICATES=true" : "REMOVE_DUPLICATES=false";
return(command);
}
}
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,12 @@ private String validateInput() throws IOException {

return(r);
}

public static String getCLIcommand(File OUTPUT, File BED, boolean gzOutput) {
String command = "java -jar $SCRIPTMANAGER coordinate-manipulation bed-to-gff";
command += " " + BED.getAbsolutePath();
command += gzOutput ? " -z" : "";
command += " -o " + OUTPUT;
return(command);
}
}
12 changes: 12 additions & 0 deletions src/main/java/scriptmanager/cli/Read_Analysis/TagPileupCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ static class CalcOptions{
private int shift = 0;
@Option(names = {"-b", "--bin-size"}, description = "set a bin size for the output (default=1bp)")
private int binSize = 1;
@Option(names = {"-e", "--tag-extend"}, description = "set a bp length to extend the tag (default=0)")
private int tagExtend = 0;
@Option(names = {"-t", "--standard"}, description = "set tags to be equal (default=false)")
private boolean tagsEqual;
@Option(names = {"--cpu"}, description = "set number of CPUs to use (default=1)")
Expand Down Expand Up @@ -275,6 +277,7 @@ private String validateInput() throws IOException {
//Set SHIFT, BIN, CPU
p.setShift(calcOptions.shift);
p.setBin(calcOptions.binSize);
p.setTagExtend(calcOptions.tagExtend);
p.setCPU(calcOptions.cpu);

//Set BLACKLIST & STANDARD
Expand All @@ -298,4 +301,13 @@ private String validateInput() throws IOException {
return(r);
}

public static String getCLIcommand(File BED, File BAM, PileupParameters PARAM) {
String command = "java -jar $SCRIPTMANAGER read-analysis tag-pileup";
command += " " + PARAM.getCLIOptions();
command += " " + BED.getAbsolutePath();
command += " " + BAM.getAbsolutePath();
String NAME = PARAM.getOutputDirectory() + File.separator + PARAM.generateFileBase(BED.getName(), BAM.getName());
command += " -M " + NAME + " -o " + NAME;
return(command);
}
}
Loading

0 comments on commit 149cfcd

Please sign in to comment.