package io.github.programminglife2016.pl1_2016.collapser;

import io.github.programminglife2016.pl1_2016.parser.nodes.Node;
import io.github.programminglife2016.pl1_2016.parser.nodes.NodeCollection;
import io.github.programminglife2016.pl1_2016.parser.nodes.SegmentParser;
import io.github.programminglife2016.pl1_2016.server.Server;
import io.github.programminglife2016.pl1_2016.server.api.RestServer;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;


public class BubbleMain {
    private static final double NANOSECONDS_PER_SECOND = 1000000000;

    public static void main(String[] args) throws IOException {
        System.out.println("Started loading.");
        long startTime = System.nanoTime();
        InputStream is = BubbleMain.class.getClass().getResourceAsStream("/genomes/TB10.gfa");
        NodeCollection nodeCollection = new SegmentParser().parse(is);
        long endTime = System.nanoTime();
        System.out.println(String.format("Loading time: %f s.", (endTime - startTime)
                / NANOSECONDS_PER_SECOND));
        BubbleDispatcher dispatcher = new BubbleDispatcher(nodeCollection);
        Node firstNode = dispatcher.getLevelBubbles(1).get(8729);
        firstNode.getLinks().clear();
        firstNode.getLinks().add(dispatcher.getLevelBubbles(1).get(8730));
        Coordinate coord = new Coordinate(0, 0);
        for (int i = 8729; i <= 11800; i++) {
            Node node = dispatcher.getLevelBubbles(1).get(i);
            coord = node.position(coord, dispatcher.bubbleCollection, null, 1);

        }
        for (Node node : nodeCollection.values()) {
            Iterator<Node> linkIterator = node.getLinks().iterator();
            while (linkIterator.hasNext()) {
                Node nodeLink = linkIterator.next();
                if (nodeLink.getX() < node.getX()) {
                    linkIterator.remove();
                }
            }
        }
        Server server = new RestServer(nodeCollection);
        server.startServer();
    }
}

@@ -1419,154 +1419,339 @@
     
-Coordinate coord = new Coordinate(0, 0);%0A        for (int i = 8729; i %3C= 11800; i++) %7B%0A            Node node = dispatcher.getLevelBubbles(1)
+for (int i = 0; i %3C dispatcher.bubbleCollection.size(); i++) %7B%0A            Node bubble = dispatcher.bubbleCollection.get(i);%0A            if (bubble.getLinks().contains(bubble)) %7B%0A                bubble.getLinks().remove(bubble);%0A                try %7B%0A                    bubble.getLinks().add(dispatcher.bubbleCollection
 .get(i
+ + 1)
 );%0A 
@@ -1765,20 +1765,219 @@
     
+  
-coord = node
+  %7D catch (IndexOutOfBoundsException e) %7B%0A                    %0A                %7D%0A            %7D%0A        %7D%0A        Coordinate coord = new Coordinate(0, 0);%0A        coord = dispatcher.getLevelBubbles(1).get(8730)
 .pos
@@ -2031,19 +2031,8 @@
  1);
-%0A%0A        %7D
 %0A   

Use TB10.gfa to visualize