Commit f29c8634 authored by Michael Menzel's avatar Michael Menzel

paths with cmd args

parent 02e3ca77
...@@ -2,6 +2,7 @@ package de.thm.genomeData.sql; ...@@ -2,6 +2,7 @@ package de.thm.genomeData.sql;
import de.thm.genomeData.tracks.TrackEntry; import de.thm.genomeData.tracks.TrackEntry;
import de.thm.misc.Genome; import de.thm.misc.Genome;
import de.thm.run.BackendServer;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -17,18 +18,8 @@ public class DBConnector { ...@@ -17,18 +18,8 @@ public class DBConnector {
private final Logger logger = LoggerFactory.getLogger(DBConnector.class); private final Logger logger = LoggerFactory.getLogger(DBConnector.class);
public void connect(){ public void connect(){
final String path;
conn = null; conn = null;
String link; String link = "jdbc:sqlite:" + BackendServer.dbfilepath;
if (System.getenv("HOME").contains("menzel")) {
path = "/home/menzel/Desktop/THM/lfba/enhort/";
link = "jdbc:sqlite:" + path + "stefan.db";
} else {
path = "/home/mmnz21/enhort/";
link = "jdbc:sqlite:" + path + "stefan.db";
}
try { try {
...@@ -65,9 +56,7 @@ public class DBConnector { ...@@ -65,9 +56,7 @@ public class DBConnector {
logger.error("Exception {}", e.getMessage(), e); logger.error("Exception {}", e.getMessage(), e);
} }
return sizes; return sizes;
} }
public List<TrackEntry> getAllTracks() { public List<TrackEntry> getAllTracks() {
...@@ -91,7 +80,7 @@ public class DBConnector { ...@@ -91,7 +80,7 @@ public class DBConnector {
TrackEntry entry = new TrackEntry(rs.getString("name"), TrackEntry entry = new TrackEntry(rs.getString("name"),
rs.getString("description"), rs.getString("description"),
rs.getString("directory") + "/" + rs.getString("bed_filename"), rs.getString("directory") + "/" + rs.getString("bed_filename"),
"inout", //TODO get from db (rs.getString("bed_format").contains("SCORE") ? "scored" : "inout"),
rs.getString("genome_assembly"), rs.getString("genome_assembly"),
rs.getString("cell_line"), rs.getString("cell_line"),
rs.getInt("lines"), rs.getInt("lines"),
...@@ -107,64 +96,10 @@ public class DBConnector { ...@@ -107,64 +96,10 @@ public class DBConnector {
logger.error("Exception {}", e.getMessage(), e); logger.error("Exception {}", e.getMessage(), e);
} }
return entries; return entries;
} }
/**
* Returns all cell lines from the db
*
* @return cell lines as Sorted map, with parents/childrens
*/
public SortedMap<String, List<String>> getAllCellLinesOLD() {
SortedMap<String, List<String>> celllines = new TreeMap<>();
try {
// get all cellliens without children
String parents = "SELECT cell_line FROM cell_lines WHERE parent_id = ''";
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(parents);
while(rs.next()){
celllines.put(rs.getString("cell_line"), null);
}
// get celllines with children
String children = "SELECT cell_line, parent_id FROM cell_lines WHERE parent_id != '' ORDER BY parent_id";
stmt = conn.createStatement();
rs = stmt.executeQuery(children);
String oldParent = "";
List<String> tmpNames = new ArrayList<>();
while(rs.next()) {
String currentParent = rs.getString("parent_id");
if(oldParent.equals(currentParent)){
tmpNames.add(rs.getString("cell_line"));
} else {
if(tmpNames.size() > 0)
celllines.put(oldParent, tmpNames);
tmpNames = new ArrayList<>();
oldParent = currentParent;
}
}
} catch (SQLException e) {
logger.error("Exception {}", e.getMessage(), e);
}
return celllines;
}
/** /**
* Returns all cell lines from the db * Returns all cell lines from the db
* *
...@@ -174,9 +109,7 @@ public class DBConnector { ...@@ -174,9 +109,7 @@ public class DBConnector {
SortedMap<String, List<String>> celllines = new TreeMap<>(); SortedMap<String, List<String>> celllines = new TreeMap<>();
try { try {
// get all cellliens without children // get all cellliens without children
String parents = "SELECT cell_line FROM cell_lines"; String parents = "SELECT cell_line FROM cell_lines";
Statement stmt = conn.createStatement(); Statement stmt = conn.createStatement();
...@@ -194,7 +127,6 @@ public class DBConnector { ...@@ -194,7 +127,6 @@ public class DBConnector {
} }
public static <T> Predicate<T> distinctByKey(Function<? super T, Object> keyExtractor) { public static <T> Predicate<T> distinctByKey(Function<? super T, Object> keyExtractor) {
Map<Object, String> seen = new ConcurrentHashMap<>(); Map<Object, String> seen = new ConcurrentHashMap<>();
return t -> seen.put(keyExtractor.apply(t), "") == null; return t -> seen.put(keyExtractor.apply(t), "") == null;
......
...@@ -3,15 +3,13 @@ package de.thm.genomeData.tracks; ...@@ -3,15 +3,13 @@ package de.thm.genomeData.tracks;
import de.thm.misc.ChromosomSizes; import de.thm.misc.ChromosomSizes;
import de.thm.misc.Genome; import de.thm.misc.Genome;
import de.thm.misc.PositionPreprocessor; import de.thm.misc.PositionPreprocessor;
import de.thm.run.BackendServer;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.math3.util.Precision; import org.apache.commons.math3.util.Precision;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
...@@ -38,19 +36,7 @@ class FileLoader implements Callable<Optional<Track>> { ...@@ -38,19 +36,7 @@ class FileLoader implements Callable<Optional<Track>> {
public FileLoader(TrackEntry entry) { public FileLoader(TrackEntry entry) {
/* Path basePath = BackendServer.basePath;
basePath = new File("/home/menzel/Desktop/THM/lfba/enhort/dat/stefan").toPath();
} else {
basePath = new File("/permData/gogol/mmnz21/enhort/").toPath();
}
*/
Path basePath;
if (System.getenv("HOME").contains("menzel")) {
basePath = new File("/home/menzel/Desktop/THM/lfba/enhort/dat/stefan/").toPath();
} else {
basePath = new File("/permData/gogol/sgls22/enhort/").toPath();
}
this.path = basePath.resolve(new File(entry.getFilepath()).toPath()); this.path = basePath.resolve(new File(entry.getFilepath()).toPath());
this.assembly = Genome.Assembly.valueOf(entry.getAssembly()); this.assembly = Genome.Assembly.valueOf(entry.getAssembly());
...@@ -78,45 +64,6 @@ class FileLoader implements Callable<Optional<Track>> { ...@@ -78,45 +64,6 @@ class FileLoader implements Callable<Optional<Track>> {
return readBedFile(path.toFile()); return readBedFile(path.toFile());
} }
/**
* Overwrites the bed file with new (preprocessed) positions
*
* @param track - track to write
* @param path - path to file to overwrite
* @param type - type of track, does not work for scored or named tracks.
*/
public void saveTrack(Track track, Path path, TrackFactory.Type type) {
String header = "";
ChromosomSizes chr = ChromosomSizes.getInstance();
if (type == TrackFactory.Type.inout) {
long[] starts = track.getStarts();
long[] ends = track.getEnds();
try (BufferedReader reader = Files.newBufferedReader(path)) {
header = reader.readLine();
} catch (IOException e) {
logger.error("Exception {}", e.getMessage(), e);
}
try (BufferedWriter writer = Files.newBufferedWriter(path)) {
if (header.contains("track"))
writer.write(header + "\n");
for (int i = 0; i < starts.length; i++) {
Pair<String, Long> start = chr.mapToChr(assembly, starts[i]);
Pair<String, Long> end = chr.mapToChr(assembly, ends[i]);
writer.write(start.getKey() + "\t" + start.getValue() + "\t" + end.getValue() + "\n");
}
} catch (IOException e) {
logger.error("Exception {}", e.getMessage(), e);
}
}
}
/** /**
...@@ -179,7 +126,6 @@ class FileLoader implements Callable<Optional<Track>> { ...@@ -179,7 +126,6 @@ class FileLoader implements Callable<Optional<Track>> {
logger.warn("Start or End out of chromosome bounds (" + file.getName() + "): " + line); logger.warn("Start or End out of chromosome bounds (" + file.getName() + "): " + line);
} }
} }
start = Long.parseLong(parts[1]) + offset; start = Long.parseLong(parts[1]) + offset;
...@@ -198,8 +144,8 @@ class FileLoader implements Callable<Optional<Track>> { ...@@ -198,8 +144,8 @@ class FileLoader implements Callable<Optional<Track>> {
starts.add(start); starts.add(start);
ends.add(end); ends.add(end);
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled() && type != TrackFactory.Type.scored) {
if(starts.size() > 2 && start < starts.get(starts.size()-2)){ if (starts.size() > 2 && start < starts.get(starts.size() - 2)) {
logger.warn("Illegal position at " + line + " file " + file.getName()); logger.warn("Illegal position at " + line + " file " + file.getName());
} }
} }
...@@ -281,7 +227,6 @@ class FileLoader implements Callable<Optional<Track>> { ...@@ -281,7 +227,6 @@ class FileLoader implements Callable<Optional<Track>> {
case strand: case strand:
return Optional.of(new StrandTrack(starts, ends, strands, trackEntry)); return Optional.of(new StrandTrack(starts, ends, strands, trackEntry));
case inout: case inout:
//return PositionPreprocessor.preprocessData(new InOutTrack(starts, ends, name, description));
return Optional.of(new InOutTrack(starts, ends, trackEntry)); return Optional.of(new InOutTrack(starts, ends, trackEntry));
case scored: case scored:
return Optional.of(PositionPreprocessor.preprocessData(new ScoredTrack(starts, ends, names, scores, trackEntry))); return Optional.of(PositionPreprocessor.preprocessData(new ScoredTrack(starts, ends, names, scores, trackEntry)));
......
...@@ -7,6 +7,9 @@ import de.thm.precalc.SiteFactoryFactory; ...@@ -7,6 +7,9 @@ import de.thm.precalc.SiteFactoryFactory;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.File;
import java.nio.file.Path;
/** /**
* Startes the backend server for Enhort and loads the annotation tracks * Startes the backend server for Enhort and loads the annotation tracks
...@@ -18,12 +21,28 @@ public final class BackendServer { ...@@ -18,12 +21,28 @@ public final class BackendServer {
private static final int port = 42412; private static final int port = 42412;
private static final Logger logger = LoggerFactory.getLogger(BackendServer.class); private static final Logger logger = LoggerFactory.getLogger(BackendServer.class);
public static Path basePath;
public static String dbfilepath;
public static void main(String[] args) { public static void main(String[] args) {
logger.info("Starting Enhort backend server"); logger.info("Starting Enhort backend server");
if (args.length != 2) {
logger.error("Wrong arguments. 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" +
"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];
new Thread(() -> { new Thread(() -> {
TrackFactory tf = TrackFactory.getInstance(); TrackFactory tf = TrackFactory.getInstance();
tf.loadAllTracks(); tf.loadAllTracks();
......
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