Commit 04a00884 authored by Michael Menzel's avatar Michael Menzel

backend argparse added. Support for custom tracks only added

parent 798d7f9c
......@@ -133,6 +133,10 @@
<version>1.10.19</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sourceforge.argparse4j</groupId>
<artifactId>argparse4j</artifactId>
<version>0.8.1</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -27,6 +27,7 @@ import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
public class DBConnector {
private Connection conn;
......@@ -82,8 +83,10 @@ public class DBConnector {
public List<TrackEntry> getAllTracks(String whereClause) {
List<TrackEntry> entries = new ArrayList<>();
if(conn == null)
throw new RuntimeException("No connection to the database");
if(conn == null) {
logger.warn("No connection to the database");
return Collections.emptyList();
}
String sql = "SELECT * FROM enhort_view " + whereClause;
......@@ -123,8 +126,12 @@ public class DBConnector {
*/
public SortedMap<String, List<String>> getAllCellLines() {
SortedMap<String, List<String>> celllines = new TreeMap<>();
if(conn == null)
return celllines;
try {
// get all cellliens without children
String parents = "SELECT cell_line FROM cell_lines";
......
......@@ -51,8 +51,12 @@ class FileLoader implements Callable<Optional<Track>> {
private final TrackEntry trackEntry;
public FileLoader(TrackEntry entry) {
Path basePath;
Path basePath = BackendServer.basePath;
if(BackendServer.basePath != null)
basePath = BackendServer.basePath;
else
basePath = new File("").toPath();
this.path = basePath.resolve(new File(entry.getFilepath()).toPath());
this.assembly = Genome.Assembly.valueOf(entry.getAssembly());
......@@ -194,8 +198,11 @@ class FileLoader implements Callable<Optional<Track>> {
lines.close();
if (linecount != counter)
logger.error("File " + file.getName() + " has " + counter + " lines, but db says it has " + linecount + " lines.");
if (linecount != counter && BackendServer.customtrackpath == null)
logger.warn("File " + file.getName() + " has " + counter + " lines, but db says it has " + linecount + " lines.");
if (BackendServer.customtrackpath != null && linecount < counter)
logger.error("File " + file.getName() + " has " + counter + " lines, the current set limit is " + linecount + " lines.");
// Check read files //
......
......@@ -107,51 +107,48 @@ public final class TrackFactory {
List<TrackEntry> allTracks;
DBConnector connector = new DBConnector();
connector.connect();
if (System.getenv("HOME").contains("menzel")) {
allTracks = connector.getAllTracks("WHERE name like '%ontigs'");
allTracks = connector.getAllTracks(" WHERE directory like '%genetic%' and genome_assembly = 'hg19' ORDER BY lines ASC ");
/*
allTracks.addAll(connector.getAllTracks("WHERE genome_assembly = 'hg19' and directory like '%encode%HeLa%'"));
allTracks.addAll(connector.getAllTracks("WHERE genome_assembly = 'hg19' and directory like '%custom%'"));
//allTracks = connector.getAllTracks("WHERE bed_filename = 'SRX062365.05.bed'");
//allTracks = connector.getAllTracks(" WHERE genome_assembly = 'hg19' ORDER BY lines ASC LIMIT 3000");
*/
} else {
//allTracks = connector.getAllTracks("WHERE (cell_line NOT like '%GM%' or cell_line like '%GM12878' or name like '%POLR%')");
allTracks = connector.getAllTracks("WHERE (name not like '%POLR%' or name not like '%expression%')");
/*
allTracks = connector.getAllTracks(" WHERE directory like '%genetic%' and genome_assembly = 'hg19' ORDER BY lines ASC ");
allTracks.addAll(connector.getAllTracks("WHERE cell_line like 'HeLa%'"));
allTracks.addAll(connector.getAllTracks("WHERE cell_line like 'K-562'"));
//allTracks.addAll(connector.getAllTracks("WHERE cell_line like '%PS%'"));
allTracks.addAll(connector.getAllTracks("WHERE cell_line like '%CD%'"));
allTracks.addAll(connector.getAllTracks("WHERE cell_line like '%GM12878%'"));
allTracks.addAll(connector.getAllTracks("WHERE cell_line like '%Hep-G2%'"));
allTracks.addAll(connector.getAllTracks("WHERE cell_line like '%A-549%'"));
*/
}
if (BackendServer.dbfilepath != null){
DBConnector connector = new DBConnector();
connector.connect();
if (System.getenv("HOME").contains("menzel")) {
allTracks = connector.getAllTracks("WHERE name like '%ontigs'");
allTracks = connector.getAllTracks(" WHERE directory like '%genetic%' and genome_assembly = 'hg19' ORDER BY lines ASC ");
/*
allTracks.addAll(connector.getAllTracks("WHERE genome_assembly = 'hg19' and directory like '%encode%HeLa%'"));
allTracks.addAll(connector.getAllTracks("WHERE genome_assembly = 'hg19' and directory like '%custom%'"));
//allTracks = connector.getAllTracks("WHERE bed_filename = 'SRX062365.05.bed'");
//allTracks = connector.getAllTracks(" WHERE genome_assembly = 'hg19' ORDER BY lines ASC LIMIT 3000");
*/
} else {
//allTracks = connector.getAllTracks("WHERE (cell_line NOT like '%GM%' or cell_line like '%GM12878' or name like '%POLR%')");
allTracks = connector.getAllTracks("WHERE (name not like '%POLR%' or name not like '%expression%')");
/*
allTracks = connector.getAllTracks(" WHERE directory like '%genetic%' and genome_assembly = 'hg19' ORDER BY lines ASC ");
allTracks.addAll(connector.getAllTracks("WHERE cell_line like 'HeLa%'"));
allTracks.addAll(connector.getAllTracks("WHERE cell_line like 'K-562'"));
//allTracks.addAll(connector.getAllTracks("WHERE cell_line like '%PS%'"));
allTracks.addAll(connector.getAllTracks("WHERE cell_line like '%CD%'"));
allTracks.addAll(connector.getAllTracks("WHERE cell_line like '%GM12878%'"));
allTracks.addAll(connector.getAllTracks("WHERE cell_line like '%Hep-G2%'"));
allTracks.addAll(connector.getAllTracks("WHERE cell_line like '%A-549%'"));
*/
}
logger.info("Trying to load " + allTracks.size() + " tracks");
this.tracks.addAll(loadByEntries(allTracks));
logger.info("Trying to load " + allTracks.size() + " tracks");
this.tracks.addAll(loadByEntries(allTracks));
}
List<TrackEntry> customTracks = new ArrayList<>();
// Add custom tracks
if (System.getenv("HOME").contains("menzel")) {
if (BackendServer.customtrackpath != null) {
try {
String customtrackpath;
if (System.getenv("HOME").contains("menzel")) {
customtrackpath = "/home/menzel/Desktop/THM/promotion/enhort/dat/stefan/custom";
} else {
customtrackpath = BackendServer.customtrackpath;
}
String customtrackpath = BackendServer.customtrackpath;
Files.walk(Paths.get(customtrackpath))
.filter(Files::isRegularFile)
......
......@@ -145,12 +145,15 @@ class AnalysisHelper {
private ResultCollector runAnalysisWithBg(Sites sites, Sites sitesBg, List<Track> tracks, boolean createLogo) throws NoTracksLeftException {
if(tracks.size() == 0){
throw new NoTracksLeftException("There are no tracks loaded for analysis.");
}
CalcCaller multi = new CalcCaller();
ResultCollector collector = multi.execute(tracks, sites, sitesBg, createLogo);
if (collector.getResults().size() == 0) {
throw new NoTracksLeftException("There are no tracks left as results.");
}
return collector;
......@@ -167,7 +170,7 @@ class AnalysisHelper {
*/
private ResultCollector runAnalysisWithBg(Sites sites, Sites sitesBg, BackendCommand cmd) throws NoTracksLeftException {
List<Track> runTracks;
List<Track> runTracks = new ArrayList<>();
TrackFactory trackFactory = TrackFactory.getInstance();
if (cmd.getTracks().isEmpty()) { // when using /sample on frontend
......@@ -176,8 +179,7 @@ class AnalysisHelper {
runTracks = runTracks.stream().filter(t -> !t.getName().contains("Repeat")).collect(Collectors.toList());
//runTracks.addAll(trackFactory.getTracksByCellline("", cmd.getAssembly())); // TODO get some cell line specific tracks for sample run
} catch (RuntimeException e) {
logger.warn("Error getting tracks {}", e);
runTracks = trackFactory.getTracks(Genome.Assembly.hg19);
logger.warn("Error getting tracks from database. Ignore if you are only using custom tracks.", e);
}
} else { // if there is a list of track ids given by command
......@@ -192,6 +194,7 @@ class AnalysisHelper {
// always add custom tracks to run
runTracks.addAll(cmd.getCustomTracks());
System.out.println("cstom trks: " + runTracks.size());
return runAnalysisWithBg(sites, sitesBg, runTracks, cmd.isCreateLogo());
}
......
......@@ -20,12 +20,18 @@ import de.thm.genomeData.tracks.TrackFactory;
import de.thm.genomeData.tracks.Tracks;
import de.thm.misc.Genome;
import de.thm.precalc.SiteFactoryFactory;
import net.sourceforge.argparse4j.ArgumentParsers;
import net.sourceforge.argparse4j.inf.ArgumentParser;
import net.sourceforge.argparse4j.inf.ArgumentParserException;
import net.sourceforge.argparse4j.inf.Namespace;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.nio.file.Path;
import static net.sourceforge.argparse4j.impl.Arguments.store;
/**
* Startes the backend server for Enhort and loads the annotation tracks
......@@ -35,29 +41,53 @@ import java.nio.file.Path;
*/
public final class BackendServer {
private static final int port = 42412;
private static int port;
private static final Logger logger = LoggerFactory.getLogger(BackendServer.class);
public static Path basePath;
public static String dbfilepath;
public static String customtrackpath;
public static void main(String[] args) {
logger.info("Starting Enhort backend server");
if (args.length != 2) {
logger.error("Wrong arguments. Example call: /usr/bin/java -jar -Xmx60g -XX:StringTableSize=1000003 " +
Namespace input = null;
ArgumentParser parser = ArgumentParsers.newFor("Enhort backend").build()
.defaultHelp(true)
.description("Enhort backend server");
parser.addArgument("--data-path").help("Path to data directory").action(store());
parser.addArgument("--db").help("Path to sqlite metadata database").action(store());
parser.addArgument("--custom").help("Path to custom files").action(store());
parser.addArgument("-p", "--port").help("Port to listen on").setDefault(42412).action(store());
try {
input = parser.parseArgs(args);
} catch (ArgumentParserException e) {
parser.handleError(e);
}
if (input == null) {
logger.error("Example call: /usr/bin/java -jar -Xmx60g -XX:StringTableSize=1000003 " +
"/home/mmnz21/enhort/enhort.jar " +
"/permData/gogol/sgls22/enhort " +
"/home/mmnz21/enhort/stefan.db \n" +
"/home/mmnz21/enhort/sqlitedatabase.db \n" +
"where the first param is the path to the data directory and" +
"the second path is the .db file");
System.exit(1);
}
basePath = new File(args[0]).toPath();
dbfilepath = args[1];
port = input.getInt("port");
if(input.getString("data_path") != null && input.getString("db") != null) {
basePath = new File(input.getString("data_path")).toPath();
dbfilepath = input.getString("db");
} else {
if (input.getString("custom") != null)
customtrackpath = input.getString("custom") + "/";
}
new Thread(() -> {
TrackFactory tf = TrackFactory.getInstance();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment