Skip to content

Commit

Permalink
Merge branch 'backupplan'
Browse files Browse the repository at this point in the history
  • Loading branch information
DvdBerg committed Jun 10, 2016
2 parents f148796 + fc269e3 commit ebc68b4
Show file tree
Hide file tree
Showing 30 changed files with 1,448 additions and 577 deletions.
Binary file removed db/TB10.mv.db
Binary file not shown.
Empty file added db/TB100.mv.db
Empty file.
7 changes: 6 additions & 1 deletion src/main/java/coordinates/CoordinateDetermination.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,15 @@ public Coordinate[] calcCoords() {
int alreadyDrawn = 0;
int leftToDraw = countGenomesInSeg(i);
Coordinate coords = coordinates[i - 1];

ArrayList<Integer> outgoingedges = links.get(i - 1);

for (int j = 0; j < outgoingedges.size(); j++) {

if (outgoingedges.get(j) < 5) {
System.out.println(i);
System.out.println(j);
System.out.println(outgoingedges.get(j));
}
leftToDraw = leftToDraw - countGenomesInLink(i, outgoingedges.get(j));
int xc = coords.getX() + 100;
int yc = coords.getY() - 50 * leftToDraw + 50 * alreadyDrawn;
Expand Down
66 changes: 42 additions & 24 deletions src/main/java/db/DatabaseProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
public class DatabaseProcessor {
private Statement db;
private DatabaseReader dbr;
private int noOfSegments;

public DatabaseProcessor(Statement db, DatabaseReader dbr) {
this.db = db;
Expand All @@ -34,6 +33,8 @@ public void updateCoordinates() {
Coordinate[] coordinates = coorddet.calcCoords();
SplashController.progressString.set("Saving segment coordinates");
for (int i = 1; i <= coordinates.length; i++) {
System.out.println(i);
System.out.println(coordinates[i - 1]);
if ( (i % coordinates.length) / 10 == 0) {
SplashController.progressString
.set((i * 100 / coordinates.length) + "% Stored");
Expand All @@ -58,17 +59,23 @@ public void locateBubbles() {

ArrayList<ArrayList<Integer>> links = dbr.getLinks();
for (int segmentId = 1; segmentId <= links.size(); segmentId++) {
System.out.println(segmentId);
ArrayList<Integer> outgoingEdges = links.get(segmentId - 1);

System.out.println("a");
if (outgoingEdges.size() > 1) {
System.out.println("b");
int firstChildId = outgoingEdges.get(0);
System.out.println("c");
int secondChildId = outgoingEdges.get(1);
System.out.println("d");
ArrayList<Integer> firstChildEdges = links.get(firstChildId - 1);
System.out.println("e");
ArrayList<Integer> secondChildEdges = links.get(secondChildId - 1);

System.out.println("f");
int firstChildEdge;
int secondChildEdge;
try {
System.out.println("g");
firstChildEdge = firstChildEdges.get(0);
secondChildEdge = secondChildEdges.get(0);
} catch (IndexOutOfBoundsException e) {
Expand All @@ -77,8 +84,16 @@ public void locateBubbles() {
}
if (secondChildEdge == firstChildEdge) {
try {
this.db.executeUpdate(new BubbleTuple(segmentId, firstChildEdge)
.getInsertQuery());
System.out.println("h");
ArrayList<Integer> genomeIds = dbr.getGenomesInBubble(segmentId,
firstChildEdge, firstChildId, secondChildId);
System.out.println("i");
for (int i = 0; i < genomeIds.size(); i++) {
System.out.println("i: " + i);
this.db.executeUpdate(new BubbleTuple(segmentId,
firstChildEdge, genomeIds.get(i))
.getInsertQuery());
}
} catch (SQLException e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -112,35 +127,34 @@ public void updateDblinkcount(int fromId, int toId, int count ) {
*/

public void calculateLinkCounts() {
HashMap<Integer, Integer> hashmap = new HashMap<Integer, Integer>();
ArrayList<Integer> from = dbr.getAllFromId();
ArrayList<Integer> to = dbr.getAllToId();
noOfSegments = to.get(to.size() - 1);
SplashController.progressString.set("Retrieving link data");
for (int i = 0; i < from.size(); i++) {
if ( ((i + 1) % from.size()) / 10 == 0) {
SplashController.progressString
.set((i * 100 / from.size() + 1) + "% Retrieved");
}
hashmap.put(noOfSegments * (from.get(i) - 1) + to.get(i) - 1, 0);
}
int noOfSegments = to.get(to.size() - 1);

ArrayList<ArrayList<Integer>> allLinks = new ArrayList<ArrayList<Integer>>();

SplashController.progressString.set("Starting to analyze genomes");

for (int i = 1; i <= dbr.countGenomes(); i++) {
hashmap = analyzeGenome(hashmap, i);
ArrayList<ArrayList<Integer>> links = analyzeGenome(i);
allLinks.addAll(links);
SplashController.progressString.set(i + "genome(s) analyzed");
}

SplashController.progressString.set("Storing link data");

try {
this.db.executeUpdate("DELETE FROM LINKS");
} catch (SQLException e) {
e.printStackTrace();
}
for (int i = 0; i < from.size(); i++) {

for (int i = 0; i < allLinks.size(); i++) {
if ( ((i + 1) % from.size()) / 10 == 0) {
SplashController.progressString.set((i * 100 / from.size() + 1) + "% Stored");
}
updateDblinkcount(from.get(i), to.get(i),
hashmap.get(noOfSegments * (from.get(i) - 1) + to.get(i) - 1));
ArrayList<Integer> link = allLinks.get(i);
updateDblinkcount(link.get(0), link.get(1), link.get(2));
}
}

Expand All @@ -151,25 +165,29 @@ public void calculateLinkCounts() {
* @param genomeID The ID of the genome we're analyzing
* @return An updated HashMap where data about the genome we analyzed is also stored
*/
public HashMap<Integer, Integer> analyzeGenome(HashMap<Integer, Integer> map, int genomeId) {
public ArrayList<ArrayList<Integer>> analyzeGenome(int genomeId) {
String query = "SELECT * "
+ "FROM GENOMESEGMENTLINK WHERE GENOMEID = " + genomeId;
ArrayList<ArrayList<Integer>> links = new ArrayList<ArrayList<Integer>>();
try (ResultSet rs = this.db.executeQuery(query)) {
if (rs.next()) {
int first = rs.getInt(1);
int second;
while (rs.next()) {
ArrayList<Integer> link = new ArrayList<Integer>();
second = rs.getInt(1);
int currentcount = map.remove(noOfSegments * (first - 1) + second - 1);
map.put(noOfSegments * (first - 1) + second - 1, currentcount + 1);
link.add(first);
link.add(second);
link.add(genomeId);
links.add(link);
first = second;
}
return map;
return links;
}
return null;
} catch (SQLException e) {
e.printStackTrace();
return map;
return null;
}
}

Expand Down
Loading

0 comments on commit ebc68b4

Please sign in to comment.