Skip to content
115 changes: 50 additions & 65 deletions src/cli/Read_Analysis/TagPileupCLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ static class OutputOptions{
private boolean tab = false;
}

//Aspect
@ArgGroup(exclusive = true, multiplicity = "0..1", heading = "%nSelect Aspect of Read to output:%n\t@|fg(red) (select no more than one of these options)|@%n")
AspectType aspectType = new AspectType();
static class AspectType {
@Option(names = {"-5", "--five-prime"}, description = "pileup of 5' end of read(default)")
boolean fiveprime = false;
@Option(names = {"-3", "--three-prime"}, description = "pileup of 3' end of read")
boolean threeprime = false;
@Option(names = {"-m", "--midpoint"}, description = "pileup fragment midpoints (require PE, combined)")
boolean midpoint = false;
}

//Read
@ArgGroup(exclusive = true, multiplicity = "0..1", heading = "%nSelect Read to output:%n\t@|fg(red) (select no more than one of these options)|@%n")
ReadType readType = new ReadType();
Expand All @@ -68,9 +80,6 @@ static class ReadType {
boolean read2 = false;
@Option(names = {"-a", "--all-reads"}, description = "pileup all reads")
boolean allreads = false;
@Option(names = {"-m", "--midpoint"}, description = "pile midpoint (require PE and combined, -p --combined)")
boolean midpoint = false;
int finalRead = 0;
}

//Strand
Expand Down Expand Up @@ -148,15 +157,15 @@ public Integer call() throws Exception {
private String validateInput() throws IOException {
String r = "";

//check ReadType, interpret booleans for int value
if(readType.read1){ readType.finalRead = 0; }
else if(readType.read2){ readType.finalRead = 1; }
else if(readType.allreads){ readType.finalRead = 2; }
else if(readType.midpoint){
readType.finalRead = 3;
filterOptions.requirePE = true;
combStatus = true;
}
// Set ASPECT
if(aspectType.fiveprime) { p.setAspect(0); }
else if(aspectType.threeprime) { p.setAspect(1); }
else if(aspectType.midpoint) { p.setAspect(2); }

// Set READ
if(readType.read1){ p.setRead(0); }
else if(readType.read2){ p.setRead(1); }
else if(readType.allreads){ p.setRead(2); }

//check input extensions
if(!"bed".equals(ExtensionFileFilter.getExtension(bedFile))){
Expand Down Expand Up @@ -192,38 +201,14 @@ else if(readType.midpoint){
}
}

//set default output MATRIX (if output MATRIX not to be output)
if(outputOptions.outputMatrix.size()>1){
outputOptions.outputMatrix.set(0,null);
//set default output MATRIX basename (allow scripts/*/TagPileup to generate ret of filename)
} else if(outputOptions.outputMatrix.size()==0){ //generate default basename
String readString = "read1";
if(readType.finalRead == 1) { readString = "read2"; }
else if(readType.finalRead == 2) { readString = "allreads"; }
else if(readType.finalRead == 3) { readString = "midpoint"; }
outputOptions.outputMatrix.add(
ExtensionFileFilter.stripExtension(new File(bedFile.getName())) + "_" +
ExtensionFileFilter.stripExtension(new File(bamFile.getName())) + "_" + readString);
//check output filename is valid
}else{ //check basename
File output = new File(outputOptions.outputMatrix.get(0));
//no extension check b/c basename should have no extension
//check directory
if(output.getParent()==null){
// System.err.println("default to current directory");
} else if(!new File(output.getParent()).exists()){
r += "(!)Check output.MATRIX directory exists: " + output.getParent() + "\n";
}
}

//validate smooth params
if(smoothType.winVals!=-9999 && smoothType.winVals<1){ r += "(!)Invalid Smoothing Window Size. Must be larger than 0 bins, winSize=" + smoothType.winVals + "\n"; }
if(smoothType.gaussVals[0]!=-9999 && smoothType.gaussVals[0]<1){ r += "(!)Invalid Standard Deviation Size. Must be larger than 0 bins, stdSize=" + smoothType.gaussVals[0] + "\n"; }
if(smoothType.gaussVals[1]!=-9999 && smoothType.gaussVals[1]<1){ r += "(!)Invalid Number of Standard Deviations. Must be larger than 0 standard deviations, stdNum=" + smoothType.gaussVals[1] + "\n"; }

//set require PE for appropriate flags
if( filterOptions.MIN_INSERT!=-9999 || filterOptions.MAX_INSERT!=-9999){ filterOptions.requirePE = true; }
if( readType.midpoint ){ filterOptions.requirePE = true; }
p.setPErequire(filterOptions.requirePE);
if( filterOptions.MIN_INSERT!=-9999 || filterOptions.MAX_INSERT!=-9999 || p.getAspect()==2) { p.setPErequire(true); }

//validate shift, binSize, and CPUs
if(calcOptions.shift<0){ r += "(!)Invalid shift! Must be non-negative, shift=" + calcOptions.shift + "\n"; }
Expand All @@ -237,38 +222,41 @@ else if(readType.midpoint){
r += "(!)MAX_INSERT must be larger/equal to MIN_INSERT: " + filterOptions.MIN_INSERT + "," + filterOptions.MAX_INSERT + "\n";
}

// LOAD UP PileupParameters OBJECT!

//Set OUTPUT
if(outputOptions.outputMatrix.size()<=1){
p.setOutputType(2); //default behavior
//check output type
if(outputOptions.cdt && outputOptions.tab) { //both set? write error
r += "(!)Cannot flag both --cdt and --tab. Please choose one.";
} else if(outputOptions.tab){ //set tab
p.setOutputType(1);
}
}else{
outputOptions.outputMatrix.set(0,null);
p.setOutputType(0); //no matrix output
if(outputOptions.cdt){
p.setOutputType(2);
outputOptions.outputMatrix.set(0,null);
} else if(outputOptions.tab) {
p.setOutputType(1);
outputOptions.outputMatrix.set(0,null);
// No Matrix Output
if(outputOptions.outputMatrix.size() > 1){
p.setOutputType(0);
if(outputOptions.cdt || outputOptions.tab) { r += "(!)Cannot flag --cdt or --tab without -M."; }
// Output Matrix
} else {
// Determine output type
p.setOutputType(2);
if(outputOptions.cdt && outputOptions.tab) { r += "(!)Cannot flag both --cdt and --tab. Please choose one."; }
else if(outputOptions.tab) { p.setOutputType(1); }
// No matrix basename specified
if(outputOptions.outputMatrix.size() == 0) {
outputOptions.outputMatrix.add(null);
if(p.getOutputDirectory() == null) {
p.setOutputDirectory(new File(System.getProperty("user.dir")));
}
// Validate matrix specified basename
} else if(outputOptions.outputMatrix.size() == 1) {
File output = new File(outputOptions.outputMatrix.get(0));
// Check parent directory is non-null and exists
if(output.getParent()!=null){
if(!new File(output.getParent()).exists()) {
r += "(!)Check output.MATRIX directory exists: " + output.getParent() + "\n";
}
}
}
}
p.setOutputCompositeStatus(true);

//Set COMPOSITE file
p.setOutputCompositeStatus(true);
p.setCompositePrintStream(new PrintStream(outputOptions.outputComposite));

//Set READ
p.setRead(readType.finalRead);
//Set STRAND
p.setStrand(0);
if(combStatus) { p.setStrand(1); }
if(combStatus || p.getAspect() == 2) { p.setStrand(1); }

//Set smooth type and parameters
if(smoothType.noSmooth){ //default behavior
Expand Down Expand Up @@ -298,9 +286,6 @@ else if(readType.midpoint){
p.setBlacklist(filterOptions.blacklistFilter);
p.setStandard(calcOptions.tagsEqual);

//Set PE requirement
p.setPErequire(filterOptions.requirePE);

//Set output statuses
p.setGZIPstatus(outputOptions.zip);

Expand Down
68 changes: 52 additions & 16 deletions src/objects/PileupParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,46 @@
import java.io.File;
import java.io.PrintStream;

/**
* Object for storing pileup-related parameter information and constants.
* @see scripts.Read_Analysis.PileupScripts.PileupExtract
* @author William KM Lai
*/

public class PileupParameters {
//Directory to save matrix and composite into
private File OUTPUT = null;
//Composite values file if output
private PrintStream COMPOSITE = null;
//Read aspect
final static int FIVE = 0;
final static int THREE = 1;
final static int MIDPOINT = 2;
final static int FRAGMENT = 3;
private int ASPECT = PileupParameters.FIVE;

//Read type:
// 0=read1, 1=read2, 2=allreads, 3=midpoint
private int READ = 0;
//Read type
final static int READ1 = 0;
final static int READ2 = 1;
final static int ALLREADS = 2;
private int READ = PileupParameters.READ1;

//Strand type:
// 0=separate, 1=combined
private int STRAND = 0;
//Strand type
final static int COMBINED = 1;
final static int SEPARATE = 0;
private int STRAND = PileupParameters.SEPARATE;

//Transformation/smoothing type
final static int NO_SMOOTH = 0;
final static int WINDOW = 1;
final static int GAUSSIAN = 2;
private int TRANS = PileupParameters.NO_SMOOTH;

//Transformation/smoothing type:
// 0=no_smooth, 1=window, 2=gaussian
private int TRANS = 0;
//TRANS=1 parameters: window size (#bins)
private int SMOOTH = 0;
//TRANS=2 parameters: stdev window size (#bins) and number of standard devations
//TRANS=2 parameters: stdev window size (#bins) and number of standard deviations
private int STDSIZE = 0;
private int STDNUM = 0;
private int STDNUM = 0;

private int SHIFT = 0;
private int BIN = 1;
private int TAGEXTEND = 0;
private int CPU = 1;
private int OUTTYPE = 0; //0=no output, 1=TAB, 2=CDT
private File BLACKLIST = null;
Expand All @@ -39,16 +54,23 @@ public class PileupParameters {

private int MIN_INSERT = -9999;
private int MAX_INSERT = -9999;


//Directory to save matrix and composite into
private File OUTPUT = null;
//Composite values file if output
private PrintStream COMPOSITE = null;

public void printAll(){
System.out.println( "<><><><><><><><><><><><><><><><><><><><>" );
System.out.println( "private File OUTPUT = " + OUTPUT );
System.out.println( "private String COMPOSITE = " + COMPOSITE );
System.out.println( "private int READ = " + READ );
System.out.println( "private int ASPECT = " + ASPECT );
System.out.println( "private int STRAND = " + STRAND );
System.out.println( "private int TRANS = " + TRANS );
System.out.println( "private int SHIFT = " + SHIFT );
System.out.println( "private int BIN = " + BIN );
System.out.println( "private int TAGEXTEND = " + TAGEXTEND );
System.out.println( "private int SMOOTH = " + SMOOTH );
System.out.println( "private int STDSIZE = " + STDSIZE );
System.out.println( "private int STDNUM = " + STDNUM );
Expand Down Expand Up @@ -144,6 +166,13 @@ public void setOutputDirectory(File oUTPUT) {
OUTPUT = oUTPUT;
}

public int getAspect() {
return ASPECT;
}
public void setAspect(int aSPECT) {
ASPECT = aSPECT;
}

public int getRead() {
return READ;
}
Expand Down Expand Up @@ -179,6 +208,13 @@ public void setBin(int bIN) {
BIN = bIN;
}

public int getTagExtend() {
return TAGEXTEND;
}
public void setTagExtend(int tAGEXTEND) {
TAGEXTEND = tAGEXTEND;
}

public int getSmooth() {
return SMOOTH;
}
Expand Down
Loading