Skip to content

Commit fe92e4f

Browse files
authored
Merge pull request #100 from CEGRcode/dev
final development push before v0.14
2 parents ea80229 + 9b71103 commit fe92e4f

28 files changed

Lines changed: 1670 additions & 239 deletions

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Scripts are generically categorized within semi-descriptive tabs and are designe
1111
Open **ScriptManager-Tutorial.docx** available in root directory
1212

1313
## Build Instructions
14+
### From source
1415
(after cloning this repo):
1516
```
1617
$ cd scriptmanager
@@ -19,8 +20,15 @@ $ ./gradlew build
1920

2021
The compiled JAR file will be output into the `build/libs` directory.
2122

23+
### Singularity
24+
```
25+
$ cd scriptmanager
26+
$ singularity build --fakeroot scriptmanager.sif scriptmanager.def
27+
```
28+
2229
## Running ScriptManager
2330

31+
### .jar file
2432
To run the GUI verson of ScriptManager, you can double click the compiled JAR file or run the followinug command in the terminal
2533
```
2634
$ java -jar /path/to/jarfile
@@ -36,6 +44,16 @@ $ java -jar /path/to/jarfile -h
3644
$ java -jar /path/to/jarfile coordinate-manipulation bed-to-gff BEDFILE.bed -o OUTPUT.gff
3745
```
3846

47+
### Singularity
48+
```
49+
$ singularity exec scriptmanager.sif scriptmanager ${command}
50+
```
51+
52+
**Example:**
53+
```
54+
$ singularity exec scriptmanager.sif scriptmanager coordinate-manipulation bed-to-gff BEDFILE.bed -o OUTPUT.gff
55+
```
56+
3957
## Current scripts available (210106):
4058

4159
**BAM Statistics:**

scriptmanager.def

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Bootstrap: docker
2+
From: bitnami/minideb:latest
3+
4+
%post
5+
apt-get -y update
6+
apt-get -y install default-jre git
7+
git clone https://github.com/CEGRcode/scriptmanager.git
8+
cd scriptmanager
9+
./gradlew build
10+
apt-get -y remove git
11+
echo '#!/bin/bash\njava -jar /scriptmanager/build/libs/'$(ls /scriptmanager/build/libs) '"$@"' > /usr/bin/scriptmanager
12+
chmod +x /usr/bin/scriptmanager
13+
cd /

src/cli/Coordinate_Manipulation/BED_Manipulation/ExpandBEDCLI.java

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public class ExpandBEDCLI implements Callable<Integer> {
3232
private File output = null;
3333
@Option(names = {"-s", "--stdout"}, description = "output bed to STDOUT")
3434
private boolean stdout = false;
35+
@Option(names = {"-z", "--gzip"}, description = "gzip output (default=false)")
36+
private boolean gzOutput = false;
3537

3638
@ArgGroup(validate = false, heading = "%nType of Expansion%n")
3739
ExpandType expandType = new ExpandType();
@@ -55,25 +57,22 @@ public Integer call() throws Exception {
5557
System.exit(1);
5658
}
5759

58-
ExpandBED.expandBEDBorders(output, bedFile, SIZE, byCenter);
60+
ExpandBED.expandBEDBorders(output, bedFile, SIZE, byCenter, gzOutput);
5961

6062
System.err.println("Expansion Complete");
6163
return(0);
6264
}
6365

6466
private String validateInput() throws IOException {
6567
String r = "";
66-
68+
6769
//check inputs exist
6870
if(!bedFile.exists()){
6971
r += "(!)BED file does not exist: " + bedFile.getName() + "\n";
7072
return(r);
7173
}
72-
//check input extensions
73-
if(!"bed".equals(ExtensionFileFilter.getExtension(bedFile))){
74-
r += "(!)Is this a BED file? Check extension: " + bedFile.getName() + "\n";
75-
}
76-
74+
if(!"".equals(r)){ return(r); }
75+
7776
// Define default behavior
7877
if(expandType.center==-999 && expandType.border==-999){
7978
SIZE = 250;
@@ -91,27 +90,28 @@ private String validateInput() throws IOException {
9190
if(SIZE<=0){
9291
r += "(!) Invalid size input. Must be a positive integer greater than 0.";
9392
}
94-
93+
94+
//check stdout and gzip not both selected
95+
if (stdout && gzOutput) {
96+
r += "(!) Cannot use -s flag with -z.\n";
97+
}
9598
//set default output filename
96-
if(output==null && !stdout){
97-
if(byCenter){ output = new File(ExtensionFileFilter.stripExtension(bedFile) + "_" + Integer.toString(SIZE) + "bp.bed"); }
98-
else{ output = new File(ExtensionFileFilter.stripExtension(bedFile) + "_border_" + Integer.toString(SIZE) + "bp.bed"); }
99-
//check stdout and output not both selected
100-
}else if(stdout){
101-
if(output!=null){ r += "(!)Cannot use -s flag with -o.\n"; }
102-
//check output filename is valid
103-
}else{
104-
//check ext
105-
try{
106-
if(!"bed".equals(ExtensionFileFilter.getExtension(output))){
107-
r += "(!)Use BED extension for output filename. Try: " + ExtensionFileFilter.stripExtension(output) + ".bed\n";
108-
}
109-
} catch( NullPointerException e){ r += "(!)Output filename must have extension: use BED extension for output filename. Try: " + output + ".bed\n"; }
99+
if (output == null) {
100+
if (!stdout) {
101+
String NAME = ExtensionFileFilter.stripExtension(bedFile);
102+
NAME += byCenter ? "_" + Integer.toString(SIZE) + "bp.bed" : "_border_" + Integer.toString(SIZE) + "bp.bed";
103+
NAME += gzOutput ? ".gz" : "";
104+
output = new File(NAME);
105+
//check stdout and output not both selected
106+
} else {
107+
r += "(!) Cannot use -s flag with -o.\n";
108+
}
109+
} else {
110110
//check directory
111-
if(output.getParent()==null){
112-
// System.err.println("default to current directory");
113-
} else if(!new File(output.getParent()).exists()){
114-
r += "(!)Check output directory exists: " + output.getParent() + "\n";
111+
if (output.getParent() != null) {
112+
if (!new File(output.getParent()).exists()) {
113+
r += "(!) Check output directory exists: " + output.getParent() + "\n";
114+
}
115115
}
116116
}
117117

src/cli/Coordinate_Manipulation/BED_Manipulation/SortBEDCLI.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public class SortBEDCLI implements Callable<Integer> {
3535
private String outputBasename = null;
3636
@Option(names = {"-c", "--center"}, description = "sort by center on the input size of expansion in bins (default=100)")
3737
private int center = -999;
38+
@Option(names = {"-z", "--gzip"}, description = "gzip output (default=false)")
39+
private boolean gzOutput = false;
3840
@Option(names = {"-x", "--index"}, description = "sort by index from the specified start to the specified stop (0-indexed and half-open interval)",
3941
arity = "2")
4042
private int[] index = {-999, -999};
@@ -57,7 +59,7 @@ public Integer call() throws Exception {
5759
index[1] = (CDT_SIZE / 2) + (center / 2);
5860
}
5961

60-
SortBED.sortBEDbyCDT(outputBasename, bedFile, cdtFile, index[0], index[1]);
62+
SortBED.sortBEDbyCDT(outputBasename, bedFile, cdtFile, index[0], index[1], gzOutput);
6163

6264
System.err.println("Sort Complete");
6365
return(0);
@@ -74,13 +76,6 @@ private String validateInput() throws IOException {
7476
r += "(!)CDT file does not exist: " + cdtFile.getName() + "\n";
7577
}
7678
if(!"".equals(r)){ return(r); }
77-
//check input extensions
78-
if(!"bed".equals(ExtensionFileFilter.getExtension(bedFile))){
79-
r += "(!)Is this a BED file? Check extension: " + bedFile.getName() + "\n";
80-
}
81-
if(!"cdt".equals(ExtensionFileFilter.getExtension(cdtFile))){
82-
r += "(!)Is this a CDT file? Check extension: " + cdtFile.getName() + "\n";
83-
}
8479
// validate CDT as file, with consistent row size, and save row_size value
8580
try {
8681
CDTUtilities cdt_obj = new CDTUtilities();
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package cli.Coordinate_Manipulation;
2+
3+
import picocli.CommandLine.Command;
4+
import picocli.CommandLine.Option;
5+
import picocli.CommandLine.Parameters;
6+
7+
import java.util.concurrent.Callable;
8+
9+
import java.io.File;
10+
import java.io.IOException;
11+
import java.io.FileNotFoundException;
12+
13+
import objects.ToolDescriptions;
14+
import util.CDTUtilities;
15+
import util.ExtensionFileFilter;
16+
import scripts.Coordinate_Manipulation.ShiftCoord;
17+
18+
/**
19+
Coordinate_ManipulationCLI/ShiftCoordCLI
20+
*/
21+
@Command(name = "shift-coord", mixinStandardHelpOptions = true,
22+
description = ToolDescriptions.shift_coordinate_description,
23+
version = "ScriptManager "+ ToolDescriptions.VERSION,
24+
sortOptions = false,
25+
exitCodeOnInvalidInput = 1,
26+
exitCodeOnExecutionException = 1)
27+
public class ShiftCoordCLI implements Callable<Integer> {
28+
29+
@Parameters( index = "0", description = "the coordinate file (BED/GFF format) to shift")
30+
private File input;
31+
32+
@Option(names = {"-o", "--output"}, description = "specify output filepath (default input filename with _shiftXXXbp.bed/gff)")
33+
private String outputFilepath = null;
34+
@Option(names = {"-t", "--shift"}, description = "shift distance in bp, upstream < 0 and downstream > 0 (default=0)")
35+
private int shift = 0;
36+
@Option(names = {"-u", "--unstranded"}, description = "don't force strandedness (default=forced)")
37+
private boolean stranded = true;
38+
@Option(names = {"-z", "--gzip"}, description = "gzip output (default=false)")
39+
private boolean gzOutput = false;
40+
@Option(names = {"--gff"}, description = "input is GFF format (default=BED format)")
41+
private boolean isGFF = false;
42+
43+
@Override
44+
public Integer call() throws Exception {
45+
System.err.println( ">ShiftCoord.call()" );
46+
String validate = validateInput();
47+
if(!validate.equals("")){
48+
System.err.println( validate );
49+
System.err.println("Invalid input. Check usage using '-h' or '--help'");
50+
System.exit(1);
51+
}
52+
53+
if(isGFF) {
54+
ShiftCoord.shiftGFFInterval(new File(outputFilepath), input, shift, stranded, gzOutput);
55+
} else {
56+
ShiftCoord.shiftBEDInterval(new File(outputFilepath), input, shift, stranded, gzOutput);
57+
}
58+
59+
System.err.println("Shift Complete");
60+
return(0);
61+
}
62+
63+
private String validateInput() throws IOException {
64+
String r = "";
65+
66+
//check inputs exist
67+
if(!input.exists()){
68+
r += "(!)BED/GFF file does not exist: " + input.getName() + "\n";
69+
}
70+
if(!"".equals(r)){ return(r); }
71+
72+
//set default output filename
73+
if(outputFilepath==null){
74+
String SUFFIX = shift < 0 ? "_shift" + shift + "bp." : "_shift+" + shift + "bp.";
75+
SUFFIX += isGFF ? "gff" : "bed";
76+
SUFFIX += gzOutput ? ".gz" : "";
77+
outputFilepath = ExtensionFileFilter.stripExtension(input) + SUFFIX;
78+
//check output filename is valid
79+
}else{
80+
//no extension check
81+
//check directory
82+
File BASEFILE = new File(outputFilepath);
83+
if(BASEFILE.getParent()==null){
84+
// System.err.println("default to current directory");
85+
} else if(!new File(BASEFILE.getParent()).exists()){
86+
r += "(!)Check output directory exists: " + BASEFILE.getParent() + "\n";
87+
}
88+
}
89+
return(r);
90+
}
91+
}

src/cli/Figure_Generation/CompositePlotCLI.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public Integer call() throws Exception {
6262
}
6363

6464
// Generate Composite Plot
65-
PlotComposite.plotCompositeFile(inputComposite, output, true, title, COLORS, legend, pixelWidth, pixelHeight);
65+
PlotComposite.plotCompositeFile(inputComposite, output, true, title, COLORS, legend, pixelHeight, pixelWidth);
6666

6767
System.err.println("Image Generated.");
6868
return (0);

src/cli/Peak_Analysis/RandomCoordinateCLI.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
exitCodeOnExecutionException = 1)
2525
public class RandomCoordinateCLI implements Callable<Integer> {
2626

27-
@Parameters( index = "0", description = "reference genome [sacCer3|sacCer3_cegr|hg19|hg19_contigs|mm10]")
27+
@Parameters( index = "0", description = "reference genome [sacCer3|sacCer3_cegr|hg38|hg38_contigs|hg19|hg19_contigs|mm10]")
2828
private String genomeName;
2929

3030
@Option(names = {"-o", "--output"}, description = "Specify output directory (default = current working directory), file name will be random_coordinates_<genomeName>_<window>bp.<ext>")
@@ -46,8 +46,7 @@ public Integer call() throws Exception {
4646
System.exit(1);
4747
}
4848

49-
RandomCoordinate script_obj = new RandomCoordinate(genomeName, numSites, window, formatIsBed, output);
50-
script_obj.execute();
49+
RandomCoordinate.execute(genomeName, numSites, window, formatIsBed, output);
5150

5251
System.err.println( "Random Coordinate Generation Complete." );
5352
return(0);

src/cli/Peak_Analysis/TileGenomeCLI.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
exitCodeOnExecutionException = 1)
2525
public class TileGenomeCLI implements Callable<Integer> {
2626

27-
@Parameters( index = "0", description = "reference genome [sacCer3|sacCer3_cegr|hg19|hg19_contigs|mm10]")
27+
@Parameters( index = "0", description = "reference genome [sacCer3|sacCer3_cegr|hg38|hg38_contigs|hg19|hg19_contigs|mm10]")
2828
private String genomeName;
2929

3030
@Option(names = {"-o", "--output"}, description = "Specify output directory (default = current working directory), file name will be genome_tiles_<genomeName>_<window>bp.<ext>")
@@ -44,8 +44,7 @@ public Integer call() throws Exception {
4444
System.exit(1);
4545
}
4646

47-
TileGenome script_obj = new TileGenome(genomeName, window, formatIsBed, output);
48-
script_obj.execute();
47+
TileGenome.execute(genomeName, window, formatIsBed, output);
4948

5049
System.err.println( "Genomic Tiling Complete." );
5150
return(0);

src/cli/Read_Analysis/TagPileupCLI.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,21 +167,14 @@ private String validateInput() throws IOException {
167167
else if(readType.read2){ p.setRead(1); }
168168
else if(readType.allreads){ p.setRead(2); }
169169

170-
//check input extensions
171-
if(!"bed".equals(ExtensionFileFilter.getExtension(bedFile))){
172-
r += "(!)Is this a BED file? Check extension: " + bedFile.getName() + "\n";
173-
}
174-
if(!"bam".equals(ExtensionFileFilter.getExtension(bamFile))){
175-
r += "(!)Is this a BAM file? Check extension: " + bamFile.getName() + "\n";
176-
}
177-
if(!r.equals("")){ return(r); }
178170
//check inputs exist
179171
if(!bedFile.exists()){
180172
r += "(!)BED file does not exist: " + bedFile.getCanonicalPath() + "\n";
181173
}
182174
if(!bamFile.exists()){
183175
r += "(!)BAM file does not exist: " + bamFile.getCanonicalPath() + "\n";
184176
}
177+
if(!r.equals("")){ return(r); }
185178
//check BAI exists
186179
File f = new File(bamFile+".bai");
187180
if(!f.exists() || f.isDirectory()){

src/main/ScriptManager.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import cli.BAM_Statistics.PEStatsCLI;
2323
import cli.BAM_Statistics.SEStatsCLI;
2424

25+
import cli.Coordinate_Manipulation.ShiftCoordCLI;
26+
2527
import cli.Coordinate_Manipulation.BED_Manipulation.BEDtoGFFCLI;
2628
import cli.Coordinate_Manipulation.BED_Manipulation.ExpandBEDCLI;
2729
import cli.Coordinate_Manipulation.BED_Manipulation.SortBEDCLI;
@@ -149,6 +151,7 @@ class BAM_StatisticsCLI extends SubcommandCLI {}
149151

150152
@Command(name = "coordinate-manipulation",
151153
subcommands = {
154+
ShiftCoordCLI.class,
152155
BEDtoGFFCLI.class,
153156
ExpandBEDCLI.class,
154157
SortBEDCLI.class,

0 commit comments

Comments
 (0)