Skip to content

Commit e5a07fc

Browse files
committed
add CLI to ShiftCoord
CLI for ShiftCoord script for #92
1 parent 7599454 commit e5a07fc

2 files changed

Lines changed: 94 additions & 0 deletions

File tree

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/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)