Skip to content

Commit

Permalink
validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Genet Abay committed Feb 26, 2018
1 parent 717aa17 commit d5fcd22
Show file tree
Hide file tree
Showing 11 changed files with 570 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
public class MainFrameController implements UpdateListener {

private static final Logger LOG = Logger.getLogger(MainFrameController.class);
private SwingWorkerThread workerThread;

/**
* Objects of the views
Expand All @@ -66,6 +65,7 @@ public class MainFrameController implements UpdateListener {
// private ConfigHolder config = new ConfigHolder();
Matching matching;
private static List<ArrayList<ComparisonResult>> res;
int cutoff_index;
ConfigData configData;
public boolean cencelled = false;
public boolean isBussy = false;
Expand All @@ -76,6 +76,7 @@ public class MainFrameController implements UpdateListener {
public DefaultComboBoxModel cmbModel;

private int targSpectrumNum, resultNumber;
private boolean isValidation;

/**
* Initialize objects, variables and components.
Expand Down Expand Up @@ -143,9 +144,13 @@ public void showMainFrame() {
*/
public void stopSearch() {

this.cencelled = true;
matching.stopMatching();
if (matching != null) {
this.cencelled = true;
matching.stopMatching();

} else {
LOG.info("Nothing to cancel! Matching process is not running");
}
}

/**
Expand All @@ -166,11 +171,11 @@ public void startSearch() {
readSpectra();
this.cencelled = false;
this.isBussy = true;
matching = new UseMsRoben(this, configData.getExperimentalSpecFile(), configData.getSpecLibraryFile());
// matching = new Cascade(this);

isValidation=false;
matching = new UseMsRoben(this, configData.getExpSpecReader(), configData.getExpSpectraIndex(), configData.getLibSpecReader(), "target");
mainView.prgProgress.setValue(0);
workerThread = new SwingWorkerThread();
SwingWorkerThread workerThread = new SwingWorkerThread();
workerThread.execute();

}
Expand All @@ -183,6 +188,44 @@ public void startSearch() {

}

/**
* start search against decoy database
*/
private void validateResult(File decoydbFile) {

SpectrumReader rdDecoy=null;
List<IndexKey> decoyindxList=null;
try {
Indexer giExp = new Indexer(decoydbFile);
decoyindxList = giExp.generate();
Collections.sort(decoyindxList);

//reader for decoy spectrum file

if (decoydbFile.getName().endsWith("mgf")) {
rdDecoy = new MgfReader(decoydbFile, decoyindxList);


} else if (decoydbFile.getName().endsWith("msp")) {
rdDecoy = new MspReader(decoydbFile, decoyindxList);

}

} catch (IOException ex) {
LOG.info(ex);
}



isValidation = true;
matching = new UseMsRoben(this, configData.getExpSpecReader(), configData.getExpSpectraIndex(), rdDecoy, "decoy");
mainView.prgProgress.setValue(0);
SwingWorkerThread workerThread = new SwingWorkerThread();
workerThread.execute();


}

/**
* Read user input from GUI
*
Expand Down Expand Up @@ -214,7 +257,7 @@ private void readSpectra() {
// List<Spectrum> experimentalSpectra;
Indexer giExp = new Indexer(configData.getExperimentalSpecFile());
List<IndexKey> indxList = giExp.generate();
Collections.sort(indxList);
//Collections.sort(indxList);
configData.setExpSpectraIndex(indxList);

//Read spectra library
Expand Down Expand Up @@ -689,17 +732,24 @@ public void spectrumDisplay(int specIndex) {

}



/**
* swing thread to start the search and it runs on background
*/
private class SwingWorkerThread extends SwingWorker<Void, Void> {

List<ArrayList<ComparisonResult>> tempRes;


@Override
protected Void doInBackground() throws Exception {

matching.InpArgs(Integer.toString(configData.getMsRobinOption()), Integer.toString(configData.getIntensityOption()), Double.toString(configData.getfragTol()));
res = new ArrayList<>();
res = matching.compare(configData.getExpSpecReader(), configData.getExpSpectraIndex(), configData.getLibSpecReader(), configData.getSpectraLibraryIndex(), LOG);
tempRes = new ArrayList<>();
tempRes = matching.compare(LOG);


return null;
}

Expand All @@ -718,14 +768,25 @@ protected void done() {
mainView.prgProgress.setValue(100);
mainView.prgProgress.setString(Integer.toString(100) + "%");

if (res != null && res.size() > 0) {
if (tempRes != null && tempRes.size() > 0) {

if(!isValidation){
res=tempRes;
cutoff_index=res.size()-1;
}
else{
Validation validation=new Validation();
validation.compareNmerge(res, tempRes);
cutoff_index=validation.validate(res, 0.01);
isValidation=false;
}

fillTargetTable();
fillBestmatchTable(0);
displayResult();

} else {
// Log.info("No comparison result.");
LOG.info("No comparison result.");
}

}
Expand Down
79 changes: 79 additions & 0 deletions src/main/java/com/compomics/coss/Controller/Validation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.compomics.coss.Controller;

import com.compomics.coss.Model.ComparisonResult;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
*
* @author Genet
*/
public class Validation {

public Validation() {

}

public void compareNmerge(List<ArrayList<ComparisonResult>> targetResult, List<ArrayList<ComparisonResult>> decoyResult) {

List<ArrayList<ComparisonResult>> validatedResult = null;
//calculate FDR=Ndecoy/Ntargethits

int c = 0;
int decoySSM = 0;

for (ArrayList<ComparisonResult> rTarget : targetResult) {
ArrayList<ComparisonResult> rDecoy = decoyResult.get(c++);
if (rTarget.get(0).compareTo(rDecoy.get(0)) < 0) {

rTarget.clear();
rTarget.addAll(rDecoy);
decoySSM++;

}

}
Collections.sort(targetResult, (ArrayList<ComparisonResult> o1, ArrayList<ComparisonResult> o2) -> Double.valueOf(o1.get(0).getScore()).compareTo(o2.get(0).getScore()));

}

public int validate(List<ArrayList<ComparisonResult>> result, double threshold) {

int cutoff_index = 0;
int numDecoy = 0;
int numTarget = 0;
double fdr = 0;
//double threshold = 0.01;

for (ArrayList<ComparisonResult> r : result) {
// ArrayList<ComparisonResult> rDecoy=decoyResult.get(c++);
if (r.get(0).getResultType().equals("target")) {

numTarget++;

} else {
numDecoy++;
}

fdr = numDecoy / (double) numTarget;

if (fdr >= threshold) {
break;
}
cutoff_index++;

}
if(cutoff_index==0)
cutoff_index=result.size();
return cutoff_index;

}

}
10 changes: 10 additions & 0 deletions src/main/java/com/compomics/coss/Model/ComparisonResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class ComparisonResult implements Comparable<ComparisonResult> {
private String charge;
private double score;
private long spec_pos;
private String result_type;//either decoy or target

public long getSpecPosition(){
return this.spec_pos;
Expand Down Expand Up @@ -62,6 +63,15 @@ public double getScore(){
}


public String getResultType(){
return this.result_type;
}

public void setResultType(String resType){
this.result_type=resType;
}



@Override
public int compareTo(ComparisonResult t) {
Expand Down
18 changes: 17 additions & 1 deletion src/main/java/com/compomics/coss/View/MainGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.WindowConstants;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;


/**
Expand Down Expand Up @@ -129,6 +131,9 @@ private void initComponents() {
innerControlPanel.add(btnStartSearch);
innerControlPanel.add(btnCancel);

JPanel pnlValidationControl = new JPanel(new FlowLayout());


pnlCommands.add(innerControlPanel, BorderLayout.NORTH);
pnlCommands.add(prgProgress, BorderLayout.SOUTH);

Expand Down Expand Up @@ -269,7 +274,12 @@ public void actionPerformed(ActionEvent e) {
}
);


tab.addChangeListener((ChangeEvent e) -> {
if (e.getSource() instanceof JTabbedPane) {
JTabbedPane pane = (JTabbedPane) e.getSource();
changeControlView(pane.getSelectedIndex());
}
});

setJMenuBar(menuBar);
BorderLayout layout=new BorderLayout();
Expand Down Expand Up @@ -306,6 +316,12 @@ public void actionPerformed(ActionEvent e) {
public JTextArea txtlog;
private JScrollPane scrLogArea;
public JProgressBar prgProgress;

private void changeControlView(int selectedIndex) {



}



Expand Down
6 changes: 1 addition & 5 deletions src/main/java/com/compomics/coss/View/TargetDB_View.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

package com.compomics.coss.View;

import com.compomics.coss.Controller.MainFrameController;
Expand Down
Loading

0 comments on commit d5fcd22

Please sign in to comment.