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 68372976 authored by Davide Lagoa's avatar Davide Lagoa
Browse files

user GUI features improved

parent 12f640a5
......@@ -79,7 +79,7 @@
<dependency>
<groupId>pt.uminho.ceb.biosystems.merlin</groupId>
<artifactId>merlin</artifactId>
<version>3.9.3</version>
<version>3.9.4</version>
</dependency>
</dependencies>
</project>
......@@ -119,7 +119,7 @@ public class BestAlpha {
String score = (String) mainTableData.getValueAt(key, ecScoreColumnNumber);
matrix[row][column] = Arrays.asList(ecNumber).get(1);
matrix[row][column+1] = Double.parseDouble(score);
matrix[row][column+1] = Double.parseDouble(score.replace("<", ""));
row++;
}
......
package pt.uminho.ceb.biosystems.merlin.merlin_sampler;
import java.io.IOException;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Arrays;
......@@ -25,6 +26,7 @@ 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.Project;
import pt.uminho.ceb.biosystems.merlin.core.datatypes.annotation.EnzymesAnnotationDataInterface;
import pt.uminho.ceb.biosystems.merlin.core.gui.CustomGUI;
import pt.uminho.ceb.biosystems.merlin.core.utilities.AIBenchUtils;
import pt.uminho.ceb.biosystems.merlin.database.connector.databaseAPI.HomologyAPI;
import pt.uminho.ceb.biosystems.merlin.database.connector.datatypes.Connection;
......@@ -36,15 +38,12 @@ import pt.uminho.ceb.biosystems.merlin.utilities.io.FileUtils;
@Operation(name="perform annotation using SamPler", description="generate random sample for enzyme's annotation")
public class EnzymesAnnotationParametersSetting {
private static final int STARTCOLUMN = 0, FINISHCOLUMN = 1;
private static final int LOCUS_TAG_COLUMN_NUMBER = 1, EC_NUMBERS_COLUMN_NUMBER = 6, EC_SCORE_COLUMN_NUMBER = 7;
public static final int DEFAULT_RATIO = 5;
private EnzymesAnnotationDataInterface homologyDataContainer;
private int sampleSize;
private int sampleSize = 50;
private Map<Integer, String> itemsList;
private Map<Integer,String> ecTable = new TreeMap<Integer,String>();
private DataTable mainTableData;
private Project workspace;
private boolean searchFile = true;
private String blastDatabase;
private long startTime;
private String message;
......@@ -52,30 +51,15 @@ public class EnzymesAnnotationParametersSetting {
private AtomicBoolean cancel = new AtomicBoolean(false);
private AtomicInteger querySize;
private AtomicInteger counter = new AtomicInteger(0);
private boolean newSample;
@Port(direction=Direction.INPUT, name="workspace", description="select workspace",validateMethod="checkWorkspace",order=1)
public void setNewProject(Project workspace) {
}
@Port(direction=Direction.INPUT, name="generate new sample", description="generates a new sample if selected, discarding the previous one" ,order=2)
public void setNewProject(boolean newSample) {
this.newSample = newSample;
}
@Port(direction=Direction.INPUT, name="sample Size", description="size of the new sample, ", defaultValue = "50", order=3 //, advanced = true
)
public void setSampleSize(int sampleSize){
this.sampleSize = sampleSize;
this.startTime = GregorianCalendar.getInstance().getTimeInMillis();
this.progress.setTime(GregorianCalendar.getInstance().getTimeInMillis() - this.startTime, 0, 2, "generating sample...");
this.progress.setTime(GregorianCalendar.getInstance().getTimeInMillis() - this.startTime, 0, 2, "");
try {
this.itemsList = this.homologyDataContainer.getItemsList().get(1);
DatabaseAccess dbAcess = this.workspace.getDatabase().getDatabaseAccess();
Connection conn = new Connection(dbAcess);
......@@ -83,67 +67,45 @@ public class EnzymesAnnotationParametersSetting {
this.blastDatabase = HomologyAPI.getLastestUsedBlastDatabase(stmt);
if(resetScorer(blastDatabase)) {
this.progress.setTime(GregorianCalendar.getInstance().getTimeInMillis() - this.startTime, 0, 2, "deleting previous annotations...");
HomologyAPI.deleteHomologyData(blastDatabase, stmt);
this.progress.setTime(GregorianCalendar.getInstance().getTimeInMillis() - this.startTime, 0, 2, "reseting parameters...");
updateSettings(true);
// updateTableUI();
AIBenchUtils.updateView(this.workspace.getName(), EnzymesAnnotationDataInterface.class);
// Workbench.getInstance().info("parameters successfully reset!");
}
else {
stmt.close();
conn.closeConnection();
throw new Exception("cannot continue without reseting parameters...");
}
Integer total = HomologyAPI.countInitialMetabolicGenes(stmt);
stmt.close();
conn.closeConnection();
Map <Integer, String> data = this.openFile();
Map<Integer,String> ecMap = new TreeMap<Integer,String>();
Map<Integer, String> values = new HashMap<>();
double userThreshold = homologyDataContainer.getThreshold();
double userAlpha = homologyDataContainer.getAlpha();
DataTable randomTable;
//put the container with the correct settings for selection
if(!this.cancel.get()){
if(userThreshold != 0.0)
homologyDataContainer.setThreshold(0.0);
if(userAlpha != 0.5)
homologyDataContainer.setAlpha(0.5);
}
this.mainTableData = homologyDataContainer.getAllGenes(this.blastDatabase, false);
if(!newSample && data!=null && searchFile == true && !this.cancel.get()){
randomTable = this.buildTable(data);
ecMap = this.getEcMap();
for (int i: data.keySet())
values.put(Integer.parseInt(ecMap.get(i)), data.get(i));
}
else{
if(!this.cancel.get())
this.generateRandomSample(sampleSize);
ecMap = this.getEcMap();
randomTable = this.buildTable(ecMap);
for(int i : ecMap.keySet())
values.put(Integer.parseInt(ecMap.get(i)), itemsList.get(i));
}
//restore user's settings
if(!this.cancel.get()){
if(userThreshold != 0.0)
homologyDataContainer.setThreshold(userThreshold);
if(userAlpha != 0.5)
homologyDataContainer.setAlpha(userAlpha);
}
if(total != null)
sampleSize = (int) (total * (DEFAULT_RATIO/100.0));
// System.out.println(sampleSize);
// System.out.println(total);
// System.out.println(DEFAULT_RATIO);
if(!this.cancel.get())
new EnzymesAnnotationGUI(this.blastDatabase, sampleSize, EC_NUMBERS_COLUMN_NUMBER, EC_SCORE_COLUMN_NUMBER, values,
itemsList, LOCUS_TAG_COLUMN_NUMBER, randomTable, homologyDataContainer, ecMap);
new EnzymesAnnotationGUI(this.blastDatabase, sampleSize,
homologyDataContainer, true, total);
}
catch (Exception e) {
Workbench.getInstance().error("an error occurred while perfoming the operation");
......@@ -153,168 +115,153 @@ public class EnzymesAnnotationParametersSetting {
}
/**
* Method to generate the random sample with a given size.
*
* @param newtablesize
*/
public void generateRandomSample(int newtablesize) {
// /**
// *
// * Method to decide when the buttons alpha, threshold and auto select should be available
// * @throws SQLException
// */
// private boolean areParametersAlreadySet(Statement statement){
//
//
// ArrayList<String> databases = new ArrayList<>();
//
// try {
//
// if(statement == null) {
// Connection connection = homologyDataContainer.getConnection();
// statement = connection.createStatement();
// }
//
// databases = HomologyAPI.bestAlphasFound(statement);
//
// }
// catch (SQLException e) {
// e.printStackTrace();
// }
//
// if(!databases.contains("") && this.blastDatabase.equalsIgnoreCase("") && databases.size() > 0) {
//
// return true;
//
// }
// else if(!databases.contains("") && this.blastDatabase.equalsIgnoreCase("") && databases.size() == 0) {
//
// return true;
//
// }
// else if(databases.contains("") && !this.blastDatabase.equalsIgnoreCase("")) {
//
// return true;
//
// }
// else if(databases.contains(this.blastDatabase)) {
//
// return true;
//
// }
// else {
//
// return false;
//
// }
//
// }
List<Integer> count = IntervalRange(newtablesize);
List<Integer> tablerows = new ArrayList<Integer>();
for (int i=0; i<mainTableData.getRowCount(); i++){
String score = (String) mainTableData.getValueAt(i, EC_SCORE_COLUMN_NUMBER);
if (!score.isEmpty() && !score.equals("manual")){
tablerows.add(i);
}
}
Collections.shuffle(tablerows);
int i=0;
int j=0;
while (sum(count)!=0 && i<tablerows.size() && !this.cancel.get()) {
String score = (String) mainTableData.getValueAt(tablerows.get(i), EC_SCORE_COLUMN_NUMBER);
double value = Double.parseDouble(score.replace("<", ""));
boolean flag = false;
if (value >= 0 && value <0.1 && count.get(0) != 0){ count.set(0, count.get(0)-1); flag = true;}
else if (value >= 0.1 && value <0.2 && count.get(1) != 0){ count.set(1, count.get(1)-1); flag = true;}
else if (value >= 0.2 && value <0.3 && count.get(2) != 0){ count.set(2, count.get(2)-1); flag = true;}
else if (value >= 0.3 && value <0.4 && count.get(3) != 0){ count.set(3, count.get(3)-1); flag = true;}
else if (value >= 0.4 && value <0.5 && count.get(4) != 0){ count.set(4, count.get(4)-1); flag = true;}
else if (value >= 0.5 && value <0.6 && count.get(5) != 0){ count.set(5, count.get(5)-1); flag = true;}
else if (value >= 0.6 && value <0.7 && count.get(6) != 0){ count.set(6, count.get(6)-1); flag = true;}
else if (value >= 0.7 && value <0.8 && count.get(7) != 0){ count.set(7, count.get(7)-1); flag = true;}
else if (value >= 0.8 && value <0.9 && count.get(8) != 0){ count.set(8, count.get(8)-1); flag = true;}
else if (value >= 0.9 && value <=1 && count.get(9) != 0){ count.set(9, count.get(9)-1); flag = true;}
if (flag == true){
ecTable.put(tablerows.get(i), j+"");
j++;
}
i++;
}
}
//////////////////////////ValidateMethods/////////////////////////////
/**
* Constructs the table with the random sample generated before.
*
* @param ecKey
* @return DataTable with two columns containing "gene" and "ec number"
* @param project
*/
public DataTable buildTable(Map<Integer, String> ecKey){
List<String> columnsNames = Arrays.asList("gene", "EC number");
DataTable data = new GenericDataTable(columnsNames, "", "");
int i=0;
for (Integer key: ecKey.keySet()){
ArrayList<Object> line = new ArrayList<>();
String name = (String) mainTableData.getValueAt(key, LOCUS_TAG_COLUMN_NUMBER);
String[] ecNumber = (String[]) ArrayUtils.addAll(new String[]{"other ec number"},(String[]) mainTableData.getValueAt(key, EC_NUMBERS_COLUMN_NUMBER));
line.add(name);
line.add(ecNumber);
public void checkWorkspace(Project workspace) {
if(workspace == null) {
throw new IllegalArgumentException("no workspace selected!");
}
else {
this.workspace = workspace;
this.homologyDataContainer = (EnzymesAnnotationDataInterface) AIBenchUtils.getEntity(this.workspace.getName(), EnzymesAnnotationDataInterface.class);
data.addLine(line);
this.ecTable.put(key, i+"");
i++;
if(homologyDataContainer == null)
throw new IllegalArgumentException("please open the enzymes annotation view before generating a new sample!");
}
return data;
}
/**
* Read file with previous selection.
*
* @return
* Method to upate the user commited settings for a specific database
*/
private Map<Integer, String> openFile() {
String databaseName = homologyDataContainer.getProject().getDatabase().getDatabaseName();
Long taxonomyID = homologyDataContainer.getProject().getTaxonomyID();
String fileName = "AutoGeneSelection_" + this.blastDatabase + ".txt";
private void updateSettings(boolean restore) {
if(blastDatabase.isEmpty())
fileName = "AutoGeneSelection.txt";
String path = FileUtils.getWorkspaceTaxonomyFolderPath(databaseName, taxonomyID) + fileName;
Map<Integer, String> data = null;
try {
data = MapUtils.readFile(path, STARTCOLUMN, FINISHCOLUMN, "\t");
if (restore) {
this.homologyDataContainer.setThreshold(EnzymesAnnotationDataInterface.THRESHOLD);
this.homologyDataContainer.setUpperThreshold(EnzymesAnnotationDataInterface.UPPER_THRESHOLD);
// this.homologyDataContainer.setBlastHmmerWeight(EnzymesAnnotationDataInterface.BLAST_HMMER_WEIGHT);
this.homologyDataContainer.setBeta(EnzymesAnnotationDataInterface.BETA);
this.homologyDataContainer.setAlpha(EnzymesAnnotationDataInterface.ALPHA);
this.homologyDataContainer
.setMinimumNumberofHits(EnzymesAnnotationDataInterface.MINIMUM_NUMBER_OF_HITS);
}
catch (IOException e) {
}
catch (Exception e) {
e.printStackTrace();
}
return data;
}
/**
* Get the random sample.
*
* @return
*/
public Map<Integer,String> getEcMap(){
return ecTable;
}
private List<Integer> IntervalRange(int tableSize){
int n_intervals = 10;
List<Integer> intervals = new ArrayList<Integer>();
int n = tableSize/n_intervals;
for (int i = 0; i < n_intervals; i++){
intervals.add(i, n);
else {
this.homologyDataContainer.setThreshold(this.homologyDataContainer.getCommittedThreshold());
this.homologyDataContainer.setUpperThreshold(this.homologyDataContainer.getCommittedUpperThreshold());
// this.homologyDataContainer.setBlastHmmerWeight(this.homologyDataContainer.getCommittedBalanceBH());
this.homologyDataContainer.setBeta(this.homologyDataContainer.getCommittedBeta());
this.homologyDataContainer.setAlpha(this.homologyDataContainer.getCommittedAlpha());
this.homologyDataContainer
.setMinimumNumberofHits(this.homologyDataContainer.getCommittedMinHomologies());
}
return intervals;
}
private int sum(List<Integer> list){
int total = 0;
for (int i=0; i<list.size();i++){
total = total + list.get(i);
}
return total;
}
//////////////////////////ValidateMethods/////////////////////////////
/**
* @param project
* @return
*/
public void checkWorkspace(Project workspace) {
private boolean resetScorer(String blastDatabase) {
if(workspace == null) {
int i;
if(blastDatabase.equals("")) {
i =CustomGUI.stopQuestion("Continue",
"This operation will discard any previously set parameters and annotations for all blast databases. Continue?",
new String[]{"Yes", "No"});
throw new IllegalArgumentException("no workspace selected!");
}
else {
this.workspace = workspace;
this.homologyDataContainer = (EnzymesAnnotationDataInterface) AIBenchUtils.getEntity(this.workspace.getName(), EnzymesAnnotationDataInterface.class);
i =CustomGUI.stopQuestion("Continue",
"This operation will discard any previously set parameters and annotations for blast database " + blastDatabase + ". Continue?",
new String[]{"Yes", "No"});
}
try {
Connection connection = homologyDataContainer.getConnection();
Statement statement = connection.createStatement();
if(homologyDataContainer == null)
throw new IllegalArgumentException("please open the enzymes annotation view before generating a new sample!");
switch (i)
{
case 0:
{
if(blastDatabase.equals(""))
HomologyAPI.resetAllScorers(statement);
else
HomologyAPI.resetDatabaseScorer(statement, blastDatabase);
return true;
}
default:
{
return false;
}
}
}
catch (SQLException e) {
e.printStackTrace();
}
return false;
}
......
#Generated by Maven Integration for Eclipse
#Tue Jul 02 10:39:11 BST 2019
#Wed Jul 03 15:04:58 BST 2019
version=0.0.1-SNAPSHOT
groupId=pt.uminho.ceb.biosystems.merlin
m2e.projectName=merlin-sampler
......
......@@ -79,7 +79,7 @@
<dependency>
<groupId>pt.uminho.ceb.biosystems.merlin</groupId>
<artifactId>merlin</artifactId>
<version>3.9.3</version>
<version>3.9.4</version>
</dependency>
</dependencies>
</project>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment