Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
d87b9c1
write template for command line interface
owlang Sep 20, 2020
512142e
add stripExtension function for CLI validation
owlang Sep 20, 2020
81ae75b
create CustomOutputStream wrapper object
owlang Sep 20, 2020
9f36aca
create BAMtoBED command line version
owlang Sep 20, 2020
ebe78cc
create BAMtobedGraph command line version
owlang Sep 20, 2020
ce85e56
create BAMtoGFF command line version
owlang Sep 20, 2020
2be5691
create BAMtoscIDX command line version
owlang Sep 20, 2020
9172b9f
fix stripExtension method to avoid exception
owlang Sep 20, 2020
39cb277
create FilterforPIPseq command line version
owlang Sep 20, 2020
132d4bc
write up cli help message for BAIIndexer redirect
owlang Sep 20, 2020
a5521e4
write up cli help message for BAMDeDuplication redirect
owlang Sep 20, 2020
97bc6ff
write up cli help message for MergeSamFiles redirect
owlang Sep 20, 2020
f186bea
write up cli help message for BAMFileSort redirect
owlang Sep 20, 2020
6385bd7
create SEStats command line version
owlang Sep 20, 2020
9ff5d51
add createLineChart() method for that saves PNG
owlang Sep 20, 2020
2b6b414
update LineChart from 'build-cli' to bam-statistics
owlang Sep 20, 2020
7c1ec84
create PEStats command line version
owlang Sep 20, 2020
9a83079
create BAMGenomeCorrelation command line version
owlang Sep 20, 2020
8871a35
create DNAShapefromBED command line version
owlang Sep 20, 2020
93d10a2
create DNAShapefromFASTA command line version
owlang Sep 20, 2020
a64a37f
create FASTAExtract command line version
owlang Sep 20, 2020
5bc5208
create RandomizeFASTA command line version
owlang Sep 20, 2020
aa22756
create SearchMotif command line version
owlang Sep 20, 2020
2f31e9b
remove unused FASTARandomize object
owlang Sep 21, 2020
f8f1531
create AggregateData command line version
owlang Sep 21, 2020
8650b5d
create ScaleMatrix command line version
owlang Sep 21, 2020
9a100e2
create ScalingFactor command line version
owlang Sep 21, 2020
d3a35dd
write up cli help message for SimilarityMatrix
owlang Sep 21, 2020
662fef0
create TagPileup command line version
owlang Sep 21, 2020
0292fe1
create MD5Checksum command line version
owlang Sep 21, 2020
1fa1918
create FourColor command line version
owlang Sep 21, 2020
60f17cf
create HeatMap command line version
owlang Sep 21, 2020
1faa4fb
create MergeHeatMap command line version
owlang Sep 21, 2020
99a74c8
create CompositePlot command line tool
owlang Sep 21, 2020
d962307
create BEDPeakAligntoRef command line version
owlang Sep 21, 2020
b0a813f
create FilterBEDbyProximity command line version
owlang Sep 21, 2020
4e28799
create RandomCoordinate command line version
owlang Sep 21, 2020
932a3bf
create TileGenome command line version
owlang Sep 22, 2020
8776b45
create ExpandBED command line version
owlang Sep 22, 2020
dd3fea7
create ExpandGFF command line version
owlang Sep 25, 2020
dbb3200
create BEDtoGFF command line version
owlang Sep 25, 2020
23fdab0
create GFFtoBED command line version
owlang Sep 25, 2020
a09b9a0
Merge branch 'master' of https://github.com/CEGRcode/scriptmanager in…
owlang Sep 29, 2020
2562bc6
create SortGFF command line version
owlang Sep 29, 2020
3ab7ea0
create SortBED command line version
owlang Sep 29, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ apply plugin: 'eclipse'

sourceSets.main.java.srcDirs = ['src']
mainClassName = "main.ScriptManager"
version = 'v0.12-dev'
version = 'v0.12-devCLI'
sourceCompatibility = 1.8
targetCompatibility = 1.8

Expand Down Expand Up @@ -48,8 +48,12 @@ repositories {

// Declare the dependencies for your production and test code
dependencies {
compile 'org.slf4j:slf4j-api:1.7.13'
testCompile 'junit:junit:4.12'
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.13'
// https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api
compile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.1'
// https://mvnrepository.com/artifact/info.picocli/picocli #CommandLineInterface Parsing Args
compile group: 'info.picocli', name: 'picocli', version: '4.2.0'
testCompile group: 'junit', name: 'junit', version: '4.12'
compile fileTree(dir: 'lib', include: ['*.jar'])
}

Expand Down
25 changes: 10 additions & 15 deletions src/charts/CompositePlot.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,29 +55,23 @@ public static Component createCompositePlot(double[] x, double[] y1, String name
}

public static Component createCompositePlot(double[] x, double[] y1, String name){
final XYSeriesCollection dataset = new XYSeriesCollection();
final XYSeries seriesC = new XYSeries("Data");
for(int i = 0; i < x.length; i++) {
seriesC.add(x[i], y1[i]);
}
dataset.addSeries(seriesC);

ArrayList<Color> COLORS = new ArrayList<Color>();
COLORS.add(Color.BLACK);
final JFreeChart chart = createChart(dataset, name, COLORS);
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
return chartPanel;
return(createCompositePlot(x, y1, name, COLORS));
}

private static JFreeChart createChart(final XYDataset dataset, String TITLE, ArrayList<Color> COLORS) {
public static JFreeChart createChart(final XYDataset dataset, String TITLE, ArrayList<Color> COLORS) {
return(createChart(dataset, TITLE, COLORS, true));
}

public static JFreeChart createChart(final XYDataset dataset, String TITLE, ArrayList<Color> COLORS, boolean legend) {
//Call Chart
final JFreeChart chart = ChartFactory.createXYLineChart(
TITLE, // chart title
"Distance from Feature (bp)", // x axis label
"Score", // y axis label
dataset, // data
PlotOrientation.VERTICAL, true, // include legend
PlotOrientation.VERTICAL, legend, // include legend
true, // tooltips
false // urls
);
Expand All @@ -93,9 +87,10 @@ private static JFreeChart createChart(final XYDataset dataset, String TITLE, Arr
renderer.setSeriesLinesVisible(x, true); //Spline visibility
renderer.setSeriesShapesVisible(x, false); //Data point dot visibility
renderer.setSeriesStroke(x, new BasicStroke(3));
renderer.setSeriesPaint(x, COLORS.get(x));
}
renderer.setSeriesPaint(0, COLORS.get(0));
if(COLORS.size() == 2) { renderer.setSeriesPaint(1, COLORS.get(1)); }
// renderer.setSeriesPaint(0, COLORS.get(0));
// if(COLORS.size() == 2) { renderer.setSeriesPaint(1, COLORS.get(1)); }

plot.setRenderer(renderer);
// change the auto tick unit selection to integer units only...
Expand Down
13 changes: 12 additions & 1 deletion src/charts/HeatMap.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package charts;

import java.awt.Color;
import java.io.File;
import java.io.IOException;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.AxisLocation;
import org.jfree.chart.axis.NumberAxis;
Expand All @@ -21,7 +24,7 @@ public HeatMap() {

}

public static ChartPanel createCorrelationHeatmap(String[] labels, double[][] MATRIX) {
public static ChartPanel createCorrelationHeatmap(String[] labels, double[][] MATRIX, File output) {
// create a paint-scale and a legend showing it
LookupPaintScale paintScale = new LookupPaintScale(0, 1, Color.black);
paintScale.add(0.0, new Color(0, 0, 255));
Expand Down Expand Up @@ -60,6 +63,14 @@ public static ChartPanel createCorrelationHeatmap(String[] labels, double[][] MA

chart.addSubtitle(legend);
chart.setBackgroundPaint(Color.white);

if(output!=null){
int width = 640;
int height = 480;
try{ ChartUtilities.saveChartAsPNG(output, chart, width, height); }
catch( IOException e ){ e.printStackTrace(); }
}

return new ChartPanel(chart);
}

Expand Down
20 changes: 20 additions & 0 deletions src/charts/LineChart.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package charts;

import java.awt.Color;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
Expand Down Expand Up @@ -45,6 +47,24 @@ public static ChartPanel createLineChart(ArrayList<Double> y1, ArrayList<Double>
return chartPanel;
}

public static ChartPanel createLineChart(ArrayList<Double> y, String[] x, File output) throws IOException {
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
for(int i = 0; i < x.length; i++) {
dataset.addValue(y.get(i).doubleValue(), "Duplication Rate", x[i]);
}

JFreeChart chart = createChart(dataset);
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));

if(output != null) {
int width = 640;
int height = 480;
ChartUtilities.saveChartAsPNG(output, chart, width, height);
}
return chartPanel;
}

private static JFreeChart createChart(CategoryDataset dataset) throws IOException {
final JFreeChart chart = ChartFactory.createLineChart(
"Paired-End Duplication Rate", // chart title
Expand Down
140 changes: 140 additions & 0 deletions src/cli/BAM_Format_Converter/BAMtoBEDCLI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
package cli.BAM_Format_Converter;

import picocli.CommandLine;
import picocli.CommandLine.ArgGroup;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;
import picocli.CommandLine.Parameters;

import java.util.concurrent.Callable;

import java.io.File;
import java.io.IOException;

import objects.ToolDescriptions;
import util.ExtensionFileFilter;
import scripts.BAM_Format_Converter.BAMtoBED;

/**
BAM_Format_ConverterCLI/SEStatsCLI
*/
@Command(name = "bam-to-bed", mixinStandardHelpOptions = true,
description = ToolDescriptions.bam_to_bed_description,
sortOptions = false,
exitCodeOnInvalidInput = 1,
exitCodeOnExecutionException = 1)
public class BAMtoBEDCLI implements Callable<Integer> {

@Parameters( index = "0", description = "The BAM file from which we generate a new file.")
private File bamFile;

@Option(names = {"-o", "--output"}, description = "specify output directory (name will be same as original with .bed ext)" )
private File output = null;
@Option(names = {"-s", "--stdout"}, description = "stream output file to STDOUT (cannot be used with \"-o\" flag)" )
private boolean stdout = 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();
static class ReadType {
@Option(names = {"-1", "--read1"}, description = "output read 1 (default)")
boolean read1 = false;
@Option(names = {"-2", "--read2"}, description = "output read 2")
boolean read2 = false;
@Option(names = {"-a", "--all-reads"}, description = "output combined")
boolean combined = false;
@Option(names = {"-m", "--midpoint"}, description = "output midpoint (require PE)")
boolean midpoint = false;
@Option(names = {"-f", "--fragment"}, description = "output fragment (requires PE)")
private boolean fragment = false;
}

@Option(names = {"-p", "--mate-pair"}, description = "require proper mate pair (default not required)")
private boolean matePair = false;
@Option(names = {"-n", "--min-insert"}, description = "filter by min insert size in bp")
private int MIN_INSERT = -9999;
@Option(names = {"-x", "--max-insert"}, description = "filter by max insert size in bp")
private int MAX_INSERT = -9999;

private int STRAND = -9999;
private int PAIR;

@Override
public Integer call() throws Exception {
System.err.println( ">BAMtoBEDCLI.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);
}

BAMtoBED script_obj = new BAMtoBED(bamFile, output, STRAND, PAIR, MIN_INSERT, MAX_INSERT, null);
script_obj.run();

System.err.println("Conversion Complete");
return(0);
}

private String validateInput() throws IOException {
String r = "";

// set strand method
if(readType.read1) { STRAND=0; }
else if(readType.read2) { STRAND=1; }
else if(readType.combined) { STRAND=2; }
else if(readType.midpoint) { STRAND=3; }
else if(readType.fragment) { STRAND=4; }
else { STRAND=0; }

//check inputs exist
if(!bamFile.exists()){
r += "(!)BAM file does not exist: " + bamFile.getName() + "\n";
return(r);
}
//check input extensions
if(!"bam".equals(ExtensionFileFilter.getExtension(bamFile))){
r += "(!)Is this a BAM file? Check extension: " + bamFile.getName() + "\n";
}
//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(output==null && !stdout){
if(STRAND==0){ output = new File( bamFile.getName().split("\\.")[0] + "_READ1.bed" ); }
else if(STRAND==1){ output = new File( bamFile.getName().split("\\.")[0] + "_READ2.bed" ); }
else if(STRAND==2){ output = new File( bamFile.getName().split("\\.")[0] + "_COMBINED.bed" ); }
else if(STRAND==3){ output = new File( bamFile.getName().split("\\.")[0] + "_MIDPOINT.bed" ); }
else if(STRAND==4){ output = new File( bamFile.getName().split("\\.")[0] + "_FRAGMENT.bed" ); }
else { r += "(!)Somehow invalid STRAND!This error should never print. Check code if it does.\n"; }
//check stdout and output not both selected
}else if(stdout){
if(output!=null){ r += "(!)Cannot use -s flag with -o.\n"; }
//check output filename is valid
}else{
//check ext
try{
if(!"bed".equals(ExtensionFileFilter.getExtension(output))){
r += "(!)Use BED extension for output filename. Try: " + ExtensionFileFilter.stripExtension(output) + ".bed\n";
}
} catch( NullPointerException e){ r += "(!)Output filename must have extension: use BED extension for output filename. Try: " + output + ".bed\n"; }
//check directory
if(output.getParent()==null){
// System.err.println("default to current directory");
} else if(!new File(output.getParent()).exists()){
r += "(!)Check output directory exists: " + output.getParent() + "\n";
}
}

// validate insert sizes
if( MIN_INSERT<0 && MIN_INSERT!=-9999 ){ r += "MIN_INSERT must be a positive integer value: " + MIN_INSERT + "\n"; }
if( MAX_INSERT<0 && MAX_INSERT!=-9999 ){ r += "MAX_INSERT must be a positive integer value: " + MAX_INSERT + "\n"; }
if( MAX_INSERT<MIN_INSERT ){ r += "MAX_INSERT must be larger/equal to MIN_INSERT: " + MIN_INSERT + "," + MAX_INSERT + "\n"; }
// turn pair status boolean into int
PAIR = matePair ? 1 : 0;

return(r);
}
}
Loading