1 package fr.orsay.lri.varna.models.templates;
3 import java.awt.geom.Line2D;
4 import java.util.Arrays;
6 import fr.orsay.lri.varna.models.geom.LinesIntersect;
7 import fr.orsay.lri.varna.models.rna.RNA;
10 * @author Raphael Champeimont
13 public class Benchmark {
16 // number of backbone crossings
17 public int backboneCrossings;
18 // average distance between unpaired consecutive bases
19 public double averageUnpairedDistance;
20 // median distance between consecutive bases
21 public double medianConsecutiveBaseDistance;
22 // Number of consecutive bases that are too near from each other
23 public int tooNearConsecutiveBases;
24 // Number of consecutive bases that are too far from each other
25 public int tooFarConsecutiveBases;
30 public double targetConsecutiveBaseDistance = RNA.LOOP_DISTANCE;
31 // If consecutive bases are nearer that tooNearFactor * target distance, we call them too near.
32 public double tooNearFactor = 0.5;
33 // If consecutive bases are further that tooFarFactor * target distance, we call them too far.
34 public double tooFarFactor = 2;
38 public Benchmark(RNA rna) {
43 private void computeAll() {
44 // Compute number of backbone crossings
46 int n = rna.getSize();
47 Line2D.Double[] lines = new Line2D.Double[n-1];
48 for (int i=0; i<n-1; i++) {
49 lines[i] = new Line2D.Double(rna.getCoords(i), rna.getCoords(i+1));
51 int intersectLines = 0;
52 for (int i=0; i<n-1; i++) {
53 for (int j=i+2; j<n-1; j++) {
54 if (LinesIntersect.linesIntersect(lines[i], lines[j])) {
59 backboneCrossings = intersectLines;
62 // Stats about distances between consecutive bases not both part of an helix
64 int n = rna.getSize();
67 for (int i=0; i<n-1; i++) {
68 int indexOfAssociatedBase1 = rna.getBaseAt(i).getElementStructure();
69 int indexOfAssociatedBase2 = rna.getBaseAt(i+1).getElementStructure();
70 if (indexOfAssociatedBase1 != -1 || indexOfAssociatedBase2 != -1) {
71 // If they are not both associated (ie. not part of an helix)
72 sum += rna.getBaseAt(i).getCoords().distance(rna.getBaseAt(i+1).getCoords());
76 averageUnpairedDistance = sum / count;
79 // Stats about base distances
81 int n = rna.getSize();
82 double distances[] = new double[n-1];
83 for (int i=0; i<n-1; i++) {
84 // If they are not both associated (ie. not part of an helix)
85 distances[i] = rna.getBaseAt(i).getCoords().distance(rna.getBaseAt(i+1).getCoords());
87 Arrays.sort(distances);
88 double median = distances[distances.length/2];
89 medianConsecutiveBaseDistance = median;
91 // We take the median as target distance, and count
92 // the number of consecutive bases with a distance too different
93 tooNearConsecutiveBases = 0;
94 tooFarConsecutiveBases = 0;
95 for (int i=0; i<n-1; i++) {
96 if (distances[i] < tooNearFactor*targetConsecutiveBaseDistance) {
97 tooNearConsecutiveBases++;
99 if (distances[i] > tooFarFactor*targetConsecutiveBaseDistance) {
100 tooFarConsecutiveBases++;
106 @SuppressWarnings("unused")
107 private int percent(int a, int b) {
108 return (int) Math.round((double) a / (double) b * 100.0);
111 public void printAll() {
112 System.out.println("Benchmark:");
113 System.out.println("\tBackbone crossings = " + backboneCrossings);
114 System.out.println("\tAverage unpaired distance = " + averageUnpairedDistance);
115 System.out.println("\tMedian of consecutive base distance = " + medianConsecutiveBaseDistance);
116 System.out.println("\tNumber of too near consecutive bases = " + tooNearConsecutiveBases); // + " ie. " + percent(tooNearConsecutiveBases, rna.getSize()-1) + " %");
117 System.out.println("\tNumber of too far consecutive bases = " + tooFarConsecutiveBases); // + " ie. " + percent(tooFarConsecutiveBases, rna.getSize()-1) + " %");