<commit_before>package controller;

import datatree.DataNode;
import datatree.DataTree;
import genome.Strand;
import genome.StrandEdge;
import genome.Genome;
import ribbonnodes.RibbonEdge;
import ribbonnodes.RibbonNode;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;

/**
 * Created by Matthijs on 18-5-2016.
 */
public final class RibbonController {

    /**
     * Create ribbonController object.
     * This should not be possible, throw an exception.
     */
    private RibbonController() {
        throw new UnsupportedOperationException();
    }

    /**
     * Get the ribbon nodes with edges for a certain view in the GUI.
     *
     * @param minX        the minx of the view.
     * @param maxX        the maxx of the view.
     * @param zoomLevel   the zoomlevel of the view.
     * @param genomeGraph the genome graph
     * @return The list of ribbonNodes.
     */
    @SuppressWarnings("checkstyle:methodlength")
    public static ArrayList<RibbonNode> getRibbonNodes(int minX, int maxX, int zoomLevel,
                                                       GenomeGraph genomeGraph, DataTree dataTree) {

        System.out.println(minX + ", " + maxX);
        ArrayList<String> activeGenomes = genomeGraph.getActiveGenomes();

        if (activeGenomes.size() < 8) {
            activeGenomes.add("TKK_02_0010.fasta");
            activeGenomes.add("TKK_02_0006.fasta");
            activeGenomes.add("TKK_02_0007.fasta");
            activeGenomes.add("TKK_02_0001.fasta");
            activeGenomes.add("TKK_02_0008.fasta");
            activeGenomes.add("TKK_02_0010.fasta");
            activeGenomes.add("TKK_02_0018.fasta");
            activeGenomes.add("TKK_02_0025.fasta");

        }


        ArrayList<RibbonNode> result = new ArrayList<>();
        ArrayList<Strand> filteredNodes = dataTree.getStrands(minX, maxX, activeGenomes, zoomLevel);

        int id = 0;
        for (Strand strand : filteredNodes) {
            RibbonNode ribbon = new RibbonNode(id, strand.getGenomes());
            ribbon.setX(strand.getX());

            id++;
            result.add(ribbon);

        }

        calcYcoordinates(result);
        addEdges(result,activeGenomes);
        result.sort((RibbonNode o1, RibbonNode o2) -> new Integer(o1.getX()).compareTo(new Integer(o1.getX())));


        return result;

    }

    public static void calcYcoordinates(ArrayList<RibbonNode> nodes) {
        int currentX = 0;
        ArrayList<RibbonNode> currentXNodes = new ArrayList<>();
        for (int i = 0; i < nodes.size(); i++) {
            RibbonNode node = nodes.get(i);
            if (node.getX() == currentX) {
                currentXNodes.add(node);
            } else {
                if (currentXNodes.size() > 1) {
                    for (int j = 0; j < currentXNodes.size(); j++) {
                        int minY = (currentXNodes.size() / 2) * -10;
                        currentXNodes.get(j).setY(minY + 10 * j);
                    }
                }
                currentXNodes = new ArrayList<>();
                currentXNodes.add(node);
                currentX = node.getX();
            }


        }

    }


    public static void addEdges(ArrayList<RibbonNode> nodes, ArrayList<String> activeGenomes) {
        for (String genome : activeGenomes) {
            int currentIndex = 0;

            while (findNextNodeWithGenome(nodes, genome, currentIndex) != null) {
                RibbonNode currentNode = findNextNodeWithGenome(nodes, genome, currentIndex);
                currentIndex = nodes.indexOf(currentNode);
                RibbonNode nextNode = findNextNodeWithGenome(nodes, genome, currentIndex);
                if (nextNode != null) {
                    if (currentNode.getOutEdge(currentNode.getId(), nextNode.getId()) == null) {
                        RibbonEdge edge = new RibbonEdge(currentNode.getId(), nextNode.getId());
                        currentNode.addEdge(edge);
                        nextNode.addEdge(edge);
                    } else {
                        currentNode.getOutEdge(currentNode.getId(), nextNode.getId()).incrementWeight();
                    }
                }<commit_msg>fixed sorting<commit_after>package controller;

import datatree.DataNode;
import datatree.DataTree;
import genome.Strand;
import genome.StrandEdge;
import genome.Genome;
import ribbonnodes.RibbonEdge;
import ribbonnodes.RibbonNode;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;

/**
 * Created by Matthijs on 18-5-2016.
 */
public final class RibbonController {

    /**
     * Create ribbonController object.
     * This should not be possible, throw an exception.
     */
    private RibbonController() {
        throw new UnsupportedOperationException();
    }

    /**
     * Get the ribbon nodes with edges for a certain view in the GUI.
     *
     * @param minX        the minx of the view.
     * @param maxX        the maxx of the view.
     * @param zoomLevel   the zoomlevel of the view.
     * @param genomeGraph the genome graph
     * @return The list of ribbonNodes.
     */
    @SuppressWarnings("checkstyle:methodlength")
    public static ArrayList<RibbonNode> getRibbonNodes(int minX, int maxX, int zoomLevel,
                                                       GenomeGraph genomeGraph, DataTree dataTree) {

        System.out.println(minX + ", " + maxX);
        ArrayList<String> activeGenomes = genomeGraph.getActiveGenomes();

        if (activeGenomes.size() < 8) {
            activeGenomes.add("TKK_02_0010.fasta");
            activeGenomes.add("TKK_02_0006.fasta");
            activeGenomes.add("TKK_02_0007.fasta");
            activeGenomes.add("TKK_02_0001.fasta");
            activeGenomes.add("TKK_02_0008.fasta");
            activeGenomes.add("TKK_02_0010.fasta");
            activeGenomes.add("TKK_02_0018.fasta");
            activeGenomes.add("TKK_02_0025.fasta");

        }


        ArrayList<RibbonNode> result = new ArrayList<>();
        ArrayList<Strand> filteredNodes = dataTree.getStrands(minX, maxX, activeGenomes, 1);

        int id = 0;
        for (Strand strand : filteredNodes) {
            RibbonNode ribbon = new RibbonNode(id, strand.getGenomes());
            ribbon.setX(strand.getX());

            id++;
            result.add(ribbon);

        }
        result.sort((RibbonNode o1, RibbonNode o2) -> new Integer(o1.getX()).compareTo(new Integer(o2.getX())));
        calcYcoordinates(result);
        addEdges(result,activeGenomes);


        return result;

    }

    public static void calcYcoordinates(ArrayList<RibbonNode> nodes) {
        int currentX = 0;
        ArrayList<RibbonNode> currentXNodes = new ArrayList<>();
        for (int i = 0; i < nodes.size(); i++) {
            RibbonNode node = nodes.get(i);
            if (node.getX() == currentX) {
                currentXNodes.add(node);
            } else {
                if (currentXNodes.size() > 1) {
                    for (int j = 0; j < currentXNodes.size(); j++) {
                        int minY = (currentXNodes.size() / 2) * -10;
                        currentXNodes.get(j).setY(minY + 10 * j);
                    }
                }
                currentXNodes = new ArrayList<>();
                currentXNodes.add(node);
                currentX = node.getX();
            }


        }

    }


    public static void addEdges(ArrayList<RibbonNode> nodes, ArrayList<String> activeGenomes) {
        for (String genome : activeGenomes) {
            int currentIndex = 0;

            while (findNextNodeWithGenome(nodes, genome, currentIndex) != null) {
                RibbonNode currentNode = findNextNodeWithGenome(nodes, genome, currentIndex);
                currentIndex = nodes.indexOf(currentNode);
                RibbonNode nextNode = findNextNodeWithGenome(nodes, genome, currentIndex);
                if (nextNode != null) {
                    if (currentNode.getOutEdge(currentNode.getId(), nextNode.getId()) == null) {
                        RibbonEdge edge = new RibbonEdge(currentNode.getId(), nextNode.getId());
                        currentNode.addEdge(edge);
                    } else {
                        currentNode.getOutEdge(currentNode.getId(), nextNode.getId()).incrementWeight();
                    }
                }
{'fraction_non_alphanumeric': 0.10735206216377764, 'fraction_numerical': 0.01709503885236103, 'mean_word_length': 2.010435408420295, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1367036', 'n_tokens_mistral': 2545, 'n_tokens_neox': 2327, 'n_words': 512}