Git Lab CI for docker build enabled! You can enable it using .gitlab-ci.yml in your project. Check file template at https://gitlab.bio.di.uminho.pt/snippets/5

Commit fb9f8315 authored by Davide Lagoa's avatar Davide Lagoa
Browse files

conflicts solved

parents fe3555ff ef45840b
Pipeline #109 canceled with stages
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="/merlin-core/lib/aibench-optflux-1.1.0.jar"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
<<<<<<< HEAD
=======
/releases
/merlin-win
/reports
/temp
/workspaces
/ws
/plugins_bin
/cache
/.classpath
/.project
/cache.ccf
/merlin
/merlin/*
/h2Database
/conf/database_settings.conf
/conf/mysql_settings.conf
/conf/h2_settings.conf
/conf/email.conf
h2*.db
java_pid*.*
*.log
*.old
*.bak
Workbench_databases/*.bak
#eclipse
.settings
#build folders
/target
/test-bin
/test_bin/
#temp
GetMerlinInfo.jar
out.txt
plugins_src/pt/uminho/sysbio/merlin/core/GetMerlinInfo.java
gff_error_report.txt
>>>>>>> ef45840bcab43134de4b90bbf8961ec997fd52b3
/bin/
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>merlin-sampler</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.hibernate.eclipse.console.hibernateBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.hibernate.eclipse.console.hibernateNature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding/<project>=UTF-8
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>pt.uminho.ceb.biosystems.merlin</groupId>
<artifactId>merlin-sampler</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>merlin-sampler</name>
<url>http://maven.apache.org</url>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.build.timestamp.format>yyyy</maven.build.timestamp.format>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>merlin-reconstruction</id>
<phase>compile</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<!-- <outputDirectory>../merlin-core/plugins_bin/merlin-draft-reconstruction</outputDirectory> -->
<outputDirectory>../merlin-core/resources/merlin-sampler</outputDirectory>
<resources>
<resource>
<directory>target/classes</directory>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<inherited>false</inherited>
<configuration>
<stripVersion>true</stripVersion>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>pt.uminho.ceb.biosystems.merlin</groupId>
<artifactId>merlin</artifactId>
<version>3.9.3</version>
</dependency>
</dependencies>
</project>
package pt.uminho.ceb.biosystems.merlin.merlin_sampler;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.IntStream;
import es.uvigo.ei.aibench.core.operation.annotation.Cancel;
import es.uvigo.ei.aibench.core.operation.annotation.Direction;
import es.uvigo.ei.aibench.core.operation.annotation.Operation;
import es.uvigo.ei.aibench.core.operation.annotation.Port;
import es.uvigo.ei.aibench.core.operation.annotation.Progress;
import es.uvigo.ei.aibench.workbench.Workbench;
import pt.uminho.ceb.biosystems.merlin.core.datatypes.DataTable;
import pt.uminho.ceb.biosystems.merlin.core.datatypes.GenericDataTable;
import pt.uminho.ceb.biosystems.merlin.core.datatypes.annotation.EnzymesAnnotationDataInterface;
import pt.uminho.ceb.biosystems.merlin.core.utilities.BestAlphaStatsCalculator;
import pt.uminho.ceb.biosystems.merlin.utilities.TimeLeftProgress;
@Operation(name="find best alpha", description="find best alpha for enzymes annotation")
public class BestAlpha {
private EnzymesAnnotationDataInterface homologyDataContainer;
private GenericDataTable mainTableData;
private int ecnumbersColumnNumber, ecScoreColumnNumber, bestAlpha=1;
private Map<Integer,String> ecMap = new HashMap<>();
private Map<Integer, String> ecCurated;
private Map<Integer, Map<Integer, Integer>> counts;
private Object[][] matrix, confusionMat;
private double[] accuracy = new double[11];
private int[] array = IntStream.range(0, 11).toArray();
private int[] below = new int[11], above = new int[11], total = new int[11];
private double[] upper = new double[11], lower = new double[11];
private double[] threshold = {0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9};
private double[] alpha = {0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0};
private AtomicBoolean cancel = new AtomicBoolean();
private TimeLeftProgress progress = new TimeLeftProgress();
private String blastDatabase;
@Port(direction=Direction.INPUT, name="ecCurated", order=1)
public void setEcCurated(Map<Integer, String> ecCurated){
this.ecCurated = ecCurated;
};
@Port(direction=Direction.INPUT, name="ecMap", order=2)
public void setEcMap(Map<Integer, String> ecMap){
this.ecMap = ecMap;
};
@Port(direction=Direction.INPUT, name="homologyDataContainer", order=3)
public void setEnzymesAnnotationDataInterface(EnzymesAnnotationDataInterface homologyDataContainer){
this.homologyDataContainer = homologyDataContainer;
};
@Port(direction=Direction.INPUT, name="ecnumbersColumnNumber", order=4)
public void setEcnumbersColumnNumber(int ecnumbersColumnNumber){
this.ecnumbersColumnNumber = ecnumbersColumnNumber;
};
@Port(direction=Direction.INPUT, name="itemsList", order=5)
public void setBlastDatabase(String blastDatabase){
this.blastDatabase = blastDatabase;
}
@Port(direction=Direction.INPUT, name="ecScoreColumnNumber", order=6)
public void setEcScoreColumnNumber(int ecScoreColumnNumber){
this.ecScoreColumnNumber = ecScoreColumnNumber;
if(!this.cancel.get())
this.bestAlpha();
DataTable data = null;
Object[] xAndY = BestAlphaStatsCalculator.getXAndY(below, above, total, accuracy);
double[] x = (double[]) xAndY[0];
double[] y = (double[]) xAndY[1];
if(!this.cancel.get())
data = BestAlphaStatsCalculator.resultsTable(array, lower, upper, y, x, threshold, accuracy, below, above, total);
bestAlpha = BestAlphaStatsCalculator.getBestAlphaIndex(y, accuracy);
if(!this.cancel.get())
new BestParametersGUI(blastDatabase, bestAlpha, threshold, confusionMat, counts, data, homologyDataContainer);
};
public void scorer(){
int matrixColumnSize = 23;
Object[][] matrix = new Object[ecMap.size()][matrixColumnSize];
int column = 1;
try {
for (int i = 0; i < alpha.length; i++){
if(!this.cancel.get()){
homologyDataContainer.setAlpha(alpha[i]);
mainTableData = homologyDataContainer.getAllGenes(blastDatabase, true); //compor
int row = 0;
for (Integer key: ecMap.keySet()){
if (alpha[i]<0.1)
matrix[row][0] = key;
String[] ecNumber = (String[]) mainTableData.getValueAt(key, ecnumbersColumnNumber);
String score = (String) mainTableData.getValueAt(key, ecScoreColumnNumber);
matrix[row][column] = Arrays.asList(ecNumber).get(1);
matrix[row][column+1] = Double.parseDouble(score);
row++;
}
}
column=column+2;
}
if(!this.cancel.get())
homologyDataContainer.setAlpha(0.5);
}
catch (Exception e) {
e.printStackTrace();
}
this.matrix = matrix;
}
public void confusionMatrix (){
int key, newKey, confRow = 0;
int confMatColumnSize = 11, confMatRowSize = 9;
Object[][] confMat = new Object[confMatRowSize][confMatColumnSize];
try {
for (int i = 0; i < threshold.length ; i++ ){
if(!this.cancel.get()){
int confCol = 0;
for (int column=1; column<23; column=column+2){
int tP = 0, tN = 0, fP = 0, fN = 0;
for (int row=0; row<matrix.length; row++){
key = (int) matrix[row][0];
newKey = Integer.parseInt(ecMap.get(key));
String[] ecN = ((String) matrix[row][column]).split(", ");
String[] ecCur = ecCurated.get(newKey).split(", ");
Set<String> ecNumber = new HashSet<>();
Set<String> ecNumberCurated = new HashSet<>();
for(int z = 0; z < ecN.length; z++)
ecNumber.add(ecN[z]);
for(int z = 0; z < ecCur.length; z++)
ecNumberCurated.add(ecCur[z]);
boolean equals = false;
if(ecNumber.equals(ecNumberCurated))
equals = true;
if (equals && (double)matrix[row][column+1]>=threshold[i]){tP++;
// if(column == 9 && i==7)
// System.out.println(matrix[row][0]);
}
else if (ecCurated.get(newKey).equalsIgnoreCase("") && (double)matrix[row][column+1]>=threshold[i]){fP++;}
else if (ecCurated.get(newKey).equalsIgnoreCase("") && (double)matrix[row][column+1]<threshold[i]){tN++;}
else if (matrix[row][column].toString().equalsIgnoreCase(ecCurated.get(newKey)) && (double)matrix[row][column+1]<threshold[i]){fN++;}
else if (!equals && (double)matrix[row][column+1]>=threshold[i]){fP++;}
else if (!equals && (double)matrix[row][column+1]<threshold[i]){fN++;}
}
int values[] = {tP, fN, fP, tN};
confMat[confRow][confCol] = values;
confCol++;
}
confRow++;
}
}
}
catch (Exception e) {
e.printStackTrace();
}
// System.out.println("CONFUSION MATRIX");
//
// for (int i=0; i<confMat.length; i++){
// for (int j=0; j<confMat[0].length; j++){
// int[] conf = (int[]) confMat[i][j];
// System.out.print(conf[0] + "(tP) " +conf[1]+ "(fN) " +conf[2]+ "(fP) "+conf[3] + "(tN) | ");}
// System.out.println();
// }
// //////////////
this.confusionMat = confMat;
}
public void bestAlpha(){
double userThreshold = 0.0;
if(!this.cancel.get()){
userThreshold = homologyDataContainer.getThreshold();
homologyDataContainer.setThreshold(0.0);
}
if(!this.cancel.get())
this.scorer();
if(!this.cancel.get())
this.confusionMatrix();
// for (int col=0; col<confusionMat[0].length; col++){
// double total = 0;
//
// for (int row=0; row<confusionMat.length;row++){
// int res[] = (int[]) confusionMat[row][col];
//
// total = total + (double) (res[0] + res[3]) / (res[0]+res[1]+res[2]+res[3]);
// }
// accuracy[col] = total / 9.0;
// }
accuracy = BestAlphaStatsCalculator.getAccuracy(confusionMat);
// int index=0;
if(!this.cancel.get()){
upper = BestAlphaStatsCalculator.getUpperThreshold(confusionMat, threshold, 1.0);
lower = BestAlphaStatsCalculator.getLowerThreshold(confusionMat, upper, threshold, 1.0);
}
counts = new HashMap<>();
for (int i = 0; i < alpha.length; i++){
if(!this.cancel.get()){
// int upperCounter=0, lowerCounter=0, totalCounter=0;
homologyDataContainer.setAlpha(alpha[i]);
mainTableData = homologyDataContainer.getAllGenes(blastDatabase, true); //compor
Map<Integer, Integer> countPerAlpha = new HashMap<>();
for (int j=0; j<mainTableData.getRowCount(); j++){
String ecScore = (String) mainTableData.getValueAt(j, ecScoreColumnNumber);
if (ecScore != ""){
double score = Double.parseDouble(ecScore);
int key = (int) (score * 10);
if(key == 10) //1.0 is the limit
key = 9;
int value = 0;
if(countPerAlpha.containsKey(key))
value = countPerAlpha.get(key);
value++;
countPerAlpha.put(key, value);
// if (score>=upper[index]){
// upperCounter = upperCounter + 1;
// }
// else if (score<lower[index]){
// lowerCounter = lowerCounter + 1;
// }
// totalCounter++;
}
}
double key = alpha[i] * 10;
counts.put((int) key, countPerAlpha);
// below[index] = lowerCounter;
// above[index] = upperCounter;
// total[index] = totalCounter;
// index++;
}
}
if(!this.cancel.get()){
homologyDataContainer.setAlpha(0.5);
homologyDataContainer.setThreshold(userThreshold);
}
above = BestAlphaStatsCalculator.getCountAbove(upper, counts);
below = BestAlphaStatsCalculator.getCountBelow(lower, counts);
total = BestAlphaStatsCalculator.getTotal(counts);
}
// public DataTable resultsTable (){
// List<String> alphaColNames = new ArrayList<>();
// alphaColNames.add("alpha");
// for (int i=1; i<array.length-1; i++){
// alphaColNames.add(""+(i/10.0));
// }
//
// DataTable data = new GenericDataTable(alphaColNames, "", "");
//
// ArrayList<Object> line = new ArrayList<>();
//
// line.add("accuracy");
//
// for (int i=1; i<accuracy.length-1;i++){
// line.add(Math.round(accuracy[i]*1000.0)/1000.0);
// }
//
// data.addLine(line);
// line.clear();
// line.add("upper threshold");
//
// for (int i=1; i<upper.length-1;i++){
// line.add(Math.round(upper[i]*1000.0)/1000.0);
// }
//
// data.addLine(line);
// line.clear();
// line.add("above UT");
//
// for (int i=1; i<above.length-1;i++){
// line.add(above[i]);
// }
//
// data.addLine(line);
// line.clear();
// line.add("lower threshold");
//
// for (int i=1; i<lower.length-1;i++){
// line.add(Math.round(lower[i]*1000.0)/1000.0);
// }
//
// data.addLine(line);
// line.clear();
// line.add("below LT");
//
// for (int i=1; i<below.length-1;i++){
// line.add(below[i]);
// }
//
// data.addLine(line);
// line.clear();
// line.add("total for curation");
//
// for (int i=1; i<below.length-1;i++){
// line.add(total[i]-below[i]-above[i]);
// }
//
// data.addLine(line);
// line.clear();
// line.add("% for curation");
//
// for (int i=1; i<x.length-1;i++){
// line.add(Math.round(x[i]*100.0)+" %");
// }
//
// data.addLine(line);
// line.clear();
// line.add("ratio");
//
// for (int i=1; i<y.length-1;i++){
// if (y[i]>0)
// line.add(Math.round(y[i]*100.0)/100.0);