Skip to content

Commit

Permalink
Clean code more
Browse files Browse the repository at this point in the history
  • Loading branch information
ypriverol committed May 18, 2020
1 parent 2586780 commit 15d1a3a
Show file tree
Hide file tree
Showing 16 changed files with 403 additions and 487 deletions.
4 changes: 2 additions & 2 deletions src/lucxor/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class Constants {
public static final String MZML_TYPE = "MZML";
public static final String MZXML_TYPE = "MZXML";

public static Map<String, Double> AA_MASS_MAP = Stream.of(
public static final Map<String, Double> AA_MASS_MAP = Stream.of(
new AbstractMap.SimpleEntry<>("A", 71.03711),
new AbstractMap.SimpleEntry<>("R", 156.10111),
new AbstractMap.SimpleEntry<>("N", 114.04293),
Expand All @@ -74,7 +74,7 @@ public class Constants {
new AbstractMap.SimpleEntry<>("V", 99.06841)
).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));

public static Map<String, String> DECOY_AA_MAP = Stream.of(
public static final Map<String, String> DECOY_AA_MAP = Stream.of(
new AbstractMap.SimpleEntry<>("2", "A"),
new AbstractMap.SimpleEntry<>("3", "R"),
new AbstractMap.SimpleEntry<>("4", "N"),
Expand Down
99 changes: 56 additions & 43 deletions src/lucxor/FLR.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,42 @@
*
* @author dfermin
*/
public class FLR {
class FLR {

List<PSM> realPSMs, decoyPSMs;
TMap<Integer, double[]> minorMapG, minorMapL;
final List<PSM> realPSMs;
final List<PSM> decoyPSMs;
private TMap<Integer, double[]> minorMapG;
private TMap<Integer, double[]> minorMapL;

// f0 = decoy
// f1 = real

double[] pos, neg;
double[] tickMarks, f0, f1;
double[] globalFDR, localFDR, globalFDR2, localFDR2;
private double[] pos;
private double[] neg;
private double[] tickMarks;
private double[] f0;
private double[] f1;
private double[] globalFDR;
private double[] localFDR;
private double[] globalFDR2;
private double[] localFDR2;
double maxDeltaScore;

// variance of delta score for both distributions
double deltaScoreVar_pos, deltaScoreVar_neg;
private double deltaScoreVar_pos;
private double deltaScoreVar_neg;

// mean of delta score for both distributions
double deltaScoreMu_pos, deltaScoreMu_neg;
private double deltaScoreMu_pos;
private double deltaScoreMu_neg;

// bandwidth for histograms
double bw_real, bw_decoy;
int Nreal, Ndecoy;
private double bw_real;
private double bw_decoy;
private int Nreal;
private int Ndecoy;

static final int NMARKS = 10001; // we want N+1 bins for the FLR
private static final int NMARKS = 10001; // we want N+1 bins for the FLR


FLR() {
Expand Down Expand Up @@ -105,10 +117,10 @@ public void initializeTickMarks() {


private void getBandWidth(int dataType) {
double sigma = 0d;
double N = 0d;
double result = 0d;
double x = 0d;
double sigma;
double N;
double result;
double x;

if(dataType == Constants.REAL) { // real
sigma = Math.sqrt(deltaScoreVar_pos);
Expand All @@ -134,7 +146,7 @@ private void getBandWidth(int dataType) {
// Compute the mean of the delta score for each data type
private void calcDeltaScoreMean() {
double sum = 0d;
double N = 0;
double N;

// for the forwards
for(double d : pos) sum += d;
Expand All @@ -154,8 +166,8 @@ private void calcDeltaScoreMean() {
private void calcDeltaScoreVar() {

double v = 0;
double N = 0;
double x = 0;
double N;
double x;

// for the forwards
for(double d : pos) {
Expand All @@ -176,12 +188,17 @@ private void calcDeltaScoreVar() {
deltaScoreVar_neg = v / N;
}


// Function evaluates each deltaScore at each tick mark storing the result in
// either f0 (decoys) or f1 (real)

/**
* Function evaluates each deltaScore at each tick mark storing the result in
* either f0 (decoys) or f1 (real)
* @param dataType
* @throws InterruptedException
* @throws ExecutionException
*/
void evalTickMarks(int dataType) throws InterruptedException, ExecutionException {

double kernelResult = 0;
double kernelResult;
double[] dataAry = null;
double[] res = null;
double bw = 0;
Expand Down Expand Up @@ -228,7 +245,6 @@ void evalTickMarks(int dataType) throws InterruptedException, ExecutionException
Callable<Double> C = new NormalDensityWorkerThread(subAry, tic, bw);
Future<Double> task = pool.submit(C);
taskList.add(task); // put the "task" to be executed into the queue
subAry = null;
}

// Launch each task
Expand All @@ -253,9 +269,9 @@ void evalTickMarks(int dataType) throws InterruptedException, ExecutionException

// Function computes the local and global FDRs (FLR here)
void calcBothFDRs() {
double AUC_rev_0 = 0d; // Area-Under Curve from end of tick marks working backwards (f0 data)
double AUC_rev_1 = 0d; // Area-Under Curve from end of tick marks working backwards (f1 data)
double ratio = 0d;
double AUC_rev_0; // Area-Under Curve from end of tick marks working backwards (f0 data)
double AUC_rev_1; // Area-Under Curve from end of tick marks working backwards (f1 data)
double ratio;

double Nreal2 = (double) Nreal;
double Ndecoy2 = (double) Ndecoy;
Expand All @@ -267,15 +283,13 @@ void calcBothFDRs() {


// GlobalFLR
ratio = 0d;
AUC_rev_0 = getGlobalAUC(tmp_score, Constants.DECOY);
AUC_rev_1 = getGlobalAUC(tmp_score, Constants.REAL);

ratio = (Ndecoy2/Nreal2) * (AUC_rev_0 / AUC_rev_1);
globalFDR[i] = ratio;

// localFDR
ratio = 0d;
AUC_rev_0 = getLocalAUC(tmp_score, Constants.DECOY);
AUC_rev_1 = getLocalAUC(tmp_score, Constants.REAL);

Expand All @@ -292,14 +306,14 @@ void calcBothFDRs() {
private double getLocalAUC(double x, int whichF) {
double result = 0d;

double a = 0, b = 0;
double a, b;
double sum = 0d;
double tmp1 = 0, tmp2 = 0;
double fx = 0;
double tmp1, tmp2;
double fx;

double start_tick = tickMarks[0];
double end_tick = tickMarks[ (NMARKS-1) ];
double start_val = 0, end_val = 0;
double start_val, end_val;


// For f0
Expand Down Expand Up @@ -367,10 +381,10 @@ private double getLocalAUC(double x, int whichF) {
// computes the area before and after the bin containing x
private double getGlobalAUC(double x, int whichF) {

double a = 0, b = 0;
double a, b;
double sum = 0d;
double tmp1 = 0, tmp2 = 0;
double fx = 0;
double tmp1, tmp2;
double fx;

// For f0
if(whichF == Constants.DECOY) { // decoy
Expand Down Expand Up @@ -426,10 +440,10 @@ public void setMinorMaps() {

ArrayList<Double> scoreList = new ArrayList<>();
HashMap<Double, double[]> localMap = new HashMap<>();
double[] FDRary = null;
double ds = 0d; // deltaScore
double FDR = 0d; // FDR
int i = 0;
double[] FDRary;
double ds; // deltaScore
double FDR; // FDR
int i;


// 0 = globalFDR, 1 = localFDR
Expand All @@ -446,9 +460,8 @@ public void setMinorMaps() {

localMap.clear();
scoreList.clear();
i = 0;

for(i = 0; i < Nreal; i++) {
for(i = 0; i < Nreal; i++) {
ds = pos[i]; // delta score
FDR = FDRary[i];
scoreList.add(ds);
Expand Down Expand Up @@ -488,8 +501,8 @@ public void performMinorization() {
double slope;
boolean cont;

double[] deqPtr = null;
TMap<Integer, double[]> mapPtr = null;
double[] deqPtr;
TMap<Integer, double[]> mapPtr;

// 0 = global FDR, 1 = localFDR
for(int iter = 0; iter < 2; iter++) {
Expand Down
Loading

0 comments on commit 15d1a3a

Please sign in to comment.