Skip to content

Commit

Permalink
Change all float to double. Delete unnecessary String format.
Browse files Browse the repository at this point in the history
  • Loading branch information
fcyu committed Feb 1, 2018
1 parent 418d314 commit e764efe
Show file tree
Hide file tree
Showing 19 changed files with 204 additions and 205 deletions.
2 changes: 1 addition & 1 deletion src/main/java/proteomics/ECL2.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private ECL2(String parameter_path, String spectra_path) throws IOException, MzX
cal_evalue = false;
}

float delta_c_t = Float.valueOf(parameter_map.get("delta_c_t"));
double delta_c_t = Double.valueOf(parameter_map.get("delta_c_t"));

boolean flankingPeaks = true;
if (parameter_map.get("flanking_peaks").contentEquals("0")) {
Expand Down
116 changes: 58 additions & 58 deletions src/main/java/proteomics/Index/BuildIndex.java

Large diffs are not rendered by default.

19 changes: 9 additions & 10 deletions src/main/java/proteomics/Search/CalEValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@
public class CalEValue {

private static final Logger logger = LoggerFactory.getLogger(CalEValue.class);
private static final float maxTolerance = 20;
private static final float toleranceStep = 1;
private static final double maxTolerance = 20;
private static final double toleranceStep = 1;

static void calEValue(int scan_num, ResultEntry result_entry, BuildIndex buildIndexObj, TreeMap<Integer, List<Double>> binScoresMap, float linker_mass, float originalTolerance, SparseVector xcorrPL, double singleChainT) throws IOException {
int gap_num = ECL2.score_point_t - result_entry.getScoreCount();
float tolerance = originalTolerance;
float massWithoutLinker = result_entry.spectrum_mass - linker_mass;
int maxBinIdx = buildIndexObj.massToBin(massWithoutLinker * 0.5f);
double tolerance = originalTolerance;
int maxBinIdx = buildIndexObj.massToBin(massWithoutLinker * 0.5);
while (gap_num > 0 && tolerance <= maxTolerance) {
gap_num = generateRandomRandomScores(gap_num, tolerance, toleranceStep, binScoresMap, result_entry.spectrum_mass, massWithoutLinker, result_entry.charge, xcorrPL, buildIndexObj, buildIndexObj.getMassBinSeqMap(), buildIndexObj.getSeqEntryMap(), buildIndexObj.returnMassTool(), result_entry, maxBinIdx, singleChainT);
tolerance += toleranceStep;
Expand Down Expand Up @@ -172,15 +171,15 @@ static void calEValue(int scan_num, ResultEntry result_entry, BuildIndex buildIn
logger.debug("Estimating E-value failed. Scan: {}, mass: {}, slope: {}, intercept: {}, R square: {}, point num: {}.",scan_num, result_entry.spectrum_mass, optimal_slope, optimal_intercept, max_r_square, result_entry.getScoreCount());
} else {
result_entry.setEValue(Math.exp((optimal_slope * Math.round(result_entry.getScore() * inverseHistogramBinSize) + optimal_intercept) + Math.log((double) result_entry.getCandidateNum() / (double) result_entry.getScoreCount()))); // double point precision limitation.
result_entry.setEValueDetails((float) max_r_square, (float) optimal_slope, (float) optimal_intercept, optimal_start_idx, null_end_idx);
result_entry.setEValueDetails(max_r_square, optimal_slope, optimal_intercept, optimal_start_idx, null_end_idx);
}

if (ECL2.debug) {
BufferedWriter writer = new BufferedWriter(new FileWriter(scan_num + ".evalue.csv"));
writer.write(String.format(Locale.US, "histogram,survival,ln(survival),slope=%.4f,intercept=%.4f,rsquare=%.4f,start=%d,end=%d\n", optimal_slope, optimal_intercept, max_r_square, optimal_start_idx, null_end_idx));
writer.write(String.format(Locale.US, "histogram,survival,ln(survival),slope=%f,intercept=%f,rsquare=%f,start=%d,end=%d\n", optimal_slope, optimal_intercept, max_r_square, optimal_start_idx, null_end_idx));
for (int i = 0; i <= max_nonzero_idx; ++i) {
if (i < ln_survival_count_array.length) {
writer.write(String.format(Locale.US, "%d,%d,%.4f\n", score_histogram[i], survival_count_array[i], ln_survival_count_array[i]));
writer.write(String.format(Locale.US, "%d,%d,%f\n", score_histogram[i], survival_count_array[i], ln_survival_count_array[i]));
} else {
writer.write(String.format(Locale.US, "%d,%d\n", score_histogram[i], survival_count_array[i]));
}
Expand All @@ -189,7 +188,7 @@ static void calEValue(int scan_num, ResultEntry result_entry, BuildIndex buildIn
}
}

private static int generateRandomRandomScores(int gap_num, float tolerance, float toleranceStep, TreeMap<Integer, List<Double>> binScoresMap, float precursorMass, float massWithoutLinker, int precursorCharge, SparseVector xcorrPL, BuildIndex buildIndex, TreeMap<Integer, Set<String>> binSequencesMap, Map<String, ChainEntry> seqEntryMap, MassTool massTool, ResultEntry resultEntry, int maxBinIdx, double singleChainT) {
private static int generateRandomRandomScores(int gap_num, double tolerance, double toleranceStep, TreeMap<Integer, List<Double>> binScoresMap, double precursorMass, double massWithoutLinker, int precursorCharge, SparseVector xcorrPL, BuildIndex buildIndex, TreeMap<Integer, Set<String>> binSequencesMap, Map<String, ChainEntry> seqEntryMap, MassTool massTool, ResultEntry resultEntry, int maxBinIdx, double singleChainT) {
for (int binIdx1 : binSequencesMap.keySet()) {
if (binIdx1 < maxBinIdx) {
int leftBinIdx1 = buildIndex.massToBin(massWithoutLinker - tolerance - toleranceStep) - binIdx1;
Expand Down Expand Up @@ -217,7 +216,7 @@ private static int generateRandomRandomScores(int gap_num, float tolerance, floa
return gap_num;
}

private static List<Double> subFunction(int binIdx, TreeMap<Integer, List<Double>> binScoresMap, TreeMap<Integer, Set<String>> binSequencesMap, Map<String, ChainEntry> seqEntryMap, MassTool massTool, float precursorMass, int precursorCharge, SparseVector xcorrPL, double singleChainT) {
private static List<Double> subFunction(int binIdx, TreeMap<Integer, List<Double>> binScoresMap, TreeMap<Integer, Set<String>> binSequencesMap, Map<String, ChainEntry> seqEntryMap, MassTool massTool, double precursorMass, int precursorCharge, SparseVector xcorrPL, double singleChainT) {
List<Double> scoreList = new ArrayList<>();
if (binScoresMap.containsKey(binIdx)) {
scoreList = binScoresMap.get(binIdx);
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/proteomics/Search/Search.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@

public class Search {

public final float ms1_tolerance;
public final double ms1_tolerance;
public final int ms1_tolerance_unit;
private final Map<String, ChainEntry> chain_entry_map;
private final Map<Character, Float> fix_mod_map;
private final MassTool mass_tool_obj;
private final TreeMap<Integer, Set<String>> bin_seq_map;
private final BuildIndex build_index_obj;
private final int[] C13_correction_range;
final float single_chain_t;
final double single_chain_t;
private final boolean cal_evalue;

/////////////////////////////////////////public methods////////////////////////////////////////////////////////////
Expand All @@ -30,9 +30,9 @@ public Search(BuildIndex build_index_obj, Map<String, String> parameter_map) {
fix_mod_map = build_index_obj.getFixModMap();
mass_tool_obj = build_index_obj.returnMassTool();
ms1_tolerance_unit = Integer.valueOf(parameter_map.get("ms1_tolerance_unit"));
ms1_tolerance = Float.valueOf(parameter_map.get("ms1_tolerance"));
ms1_tolerance = Double.valueOf(parameter_map.get("ms1_tolerance"));
bin_seq_map = build_index_obj.getMassBinSeqMap();
single_chain_t = Float.valueOf(parameter_map.get("single_chain_t"));
single_chain_t = Double.valueOf(parameter_map.get("single_chain_t"));
if (parameter_map.get("cal_evalue").contentEquals("0")) {
cal_evalue = false;
} else {
Expand All @@ -56,8 +56,8 @@ ResultEntry doSearch(SpectrumEntry spectrumEntry, SparseVector xcorrPL, TreeMap<
}

// set MS1 tolerance for further usage.
float leftMs1Tol = ms1_tolerance;
float rightMs1Tol = ms1_tolerance;
double leftMs1Tol = ms1_tolerance;
double rightMs1Tol = ms1_tolerance;
if (ms1_tolerance_unit == 1) {
leftMs1Tol = spectrumEntry.precursor_mass - (spectrumEntry.precursor_mass / (1 + ms1_tolerance * 1e-6f));
rightMs1Tol = (spectrumEntry.precursor_mass / (1 - ms1_tolerance * 1e-6f)) - spectrumEntry.precursor_mass;
Expand All @@ -78,8 +78,8 @@ ResultEntry doSearch(SpectrumEntry spectrumEntry, SparseVector xcorrPL, TreeMap<
break;
}

float left_mass_2;
float right_mass_2;
double left_mass_2;
double right_mass_2;
int left_idx_2;
int right_idx_2;
NavigableMap<Integer, Set<String>> sub_map = new TreeMap<>();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/proteomics/Search/SearchWrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class SearchWrap implements Callable<FinalResultEntry> {
private final PreSpectrum preSpectrumObj;
private final Map<String, Set<String>> seqProMap;
private final boolean cal_evalue;
private final float delta_c_t;
private final double delta_c_t;

public SearchWrap(Search search_obj, SpectrumEntry spectrumEntry, BuildIndex build_index_obj, MassTool mass_tool_obj, Map<String, Set<String>> seqProMap, boolean cal_evalue, float delta_c_t, boolean flankingPeaks) {
this.search_obj = search_obj;
Expand Down Expand Up @@ -51,7 +51,7 @@ public FinalResultEntry call() throws IOException {
if (resultEntry != null) {
if (1 - (resultEntry.getSecondScore() / resultEntry.getScore()) >= delta_c_t) {
if (cal_evalue) {
float originalTolerance;
double originalTolerance;
if (search_obj.ms1_tolerance_unit == 1) {
originalTolerance = resultEntry.spectrum_mass * search_obj.ms1_tolerance * 1e-6f;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/proteomics/Spectrum/PreSpectra.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public PreSpectra(JMzReader spectra_parser, BuildIndex build_index_obj, Map<Stri
}
int precursor_charge = spectrum.getPrecursorCharge();
double precursor_mz = spectrum.getPrecursorMZ();
float precursor_mass = (float) (precursor_mz * precursor_charge - precursor_charge * 1.00727646688);
double precursor_mass = (precursor_mz * precursor_charge - precursor_charge * 1.00727646688);

Map<Double, Double> raw_mz_intensity_map = spectrum.getPeakList();

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/proteomics/Spectrum/PreSpectrum.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private SparseVector prepareXcorr(double[] pl_array) {
}
}
if (Math.abs(temp) > 1e-6) {
xcorr_pl.put(i, (float) temp);
xcorr_pl.put(i, temp);
}
}

Expand Down Expand Up @@ -109,7 +109,7 @@ private double[] normalizeSpec(double[] plArray) {

if (maxWindowIntensity > 0) {
double temp1 = 50 / maxWindowIntensity;
double temp2 = 0.05f * maxIntensity;
double temp2 = 0.05 * maxIntensity;
for (int j = 0; j < windowSize; ++j) {
int idx = i * windowSize + j;
if (idx < plArray.length) {
Expand Down
64 changes: 32 additions & 32 deletions src/main/java/proteomics/TheoSeq/MassTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,41 @@ public class MassTool {

public static final double H2O = 18.010564684;

private final Map<Character, Float> mass_table = new HashMap<>(25, 1);
private final Map<Character, Double> mass_table = new HashMap<>(25, 1);
private final int missed_cleavage;
private final String cut_site;
private final String protect_site;
private final double inverseMzBinSize;
private final double one_minus_bin_offset;

public MassTool(int missed_cleavage, Map<Character, Float> fix_mod_map, String cut_site, String protect_site, float mz_bin_size, float one_minus_bin_offset) {
public MassTool(int missed_cleavage, Map<Character, Double> fix_mod_map, String cut_site, String protect_site, double mz_bin_size, double one_minus_bin_offset) {
inverseMzBinSize = 1 / mz_bin_size;
this.missed_cleavage = missed_cleavage;
this.cut_site = cut_site;
this.protect_site = protect_site;
this.one_minus_bin_offset = one_minus_bin_offset;
mass_table.put('G', 57.021464f + fix_mod_map.get('G'));
mass_table.put('A', 71.037114f + fix_mod_map.get('A'));
mass_table.put('S', 87.032028f + fix_mod_map.get('S'));
mass_table.put('P', 97.052764f + fix_mod_map.get('P'));
mass_table.put('V', 99.068414f + fix_mod_map.get('V'));
mass_table.put('T', 101.047678f + fix_mod_map.get('I'));
mass_table.put('C', 103.009184f + fix_mod_map.get('C'));
mass_table.put('I', 113.084064f + fix_mod_map.get('I'));
mass_table.put('L', 113.084064f + fix_mod_map.get('L'));
mass_table.put('N', 114.042927f + fix_mod_map.get('N'));
mass_table.put('D', 115.026943f + fix_mod_map.get('D'));
mass_table.put('Q', 128.058578f + fix_mod_map.get('Q'));
mass_table.put('K', 128.094963f + fix_mod_map.get('K'));
mass_table.put('E', 129.042593f + fix_mod_map.get('E'));
mass_table.put('M', 131.040485f + fix_mod_map.get('M'));
mass_table.put('H', 137.058912f + fix_mod_map.get('H'));
mass_table.put('F', 147.068414f + fix_mod_map.get('F'));
mass_table.put('R', 156.101111f + fix_mod_map.get('R'));
mass_table.put('Y', 163.063329f + fix_mod_map.get('Y'));
mass_table.put('W', 186.079313f + fix_mod_map.get('W'));
mass_table.put('U', 150.953636f + fix_mod_map.get('U'));
mass_table.put('O', 132.08988f + fix_mod_map.get('O'));
mass_table.put('G', 57.021464 + fix_mod_map.get('G'));
mass_table.put('A', 71.037114 + fix_mod_map.get('A'));
mass_table.put('S', 87.032028 + fix_mod_map.get('S'));
mass_table.put('P', 97.052764 + fix_mod_map.get('P'));
mass_table.put('V', 99.068414 + fix_mod_map.get('V'));
mass_table.put('T', 101.047678 + fix_mod_map.get('I'));
mass_table.put('C', 103.009184 + fix_mod_map.get('C'));
mass_table.put('I', 113.084064 + fix_mod_map.get('I'));
mass_table.put('L', 113.084064 + fix_mod_map.get('L'));
mass_table.put('N', 114.042927 + fix_mod_map.get('N'));
mass_table.put('D', 115.026943 + fix_mod_map.get('D'));
mass_table.put('Q', 128.058578 + fix_mod_map.get('Q'));
mass_table.put('K', 128.094963 + fix_mod_map.get('K'));
mass_table.put('E', 129.042593 + fix_mod_map.get('E'));
mass_table.put('M', 131.040485 + fix_mod_map.get('M'));
mass_table.put('H', 137.058912 + fix_mod_map.get('H'));
mass_table.put('F', 147.068414 + fix_mod_map.get('F'));
mass_table.put('R', 156.101111 + fix_mod_map.get('R'));
mass_table.put('Y', 163.063329 + fix_mod_map.get('Y'));
mass_table.put('W', 186.079313 + fix_mod_map.get('W'));
mass_table.put('U', 150.953636 + fix_mod_map.get('U'));
mass_table.put('O', 132.08988 + fix_mod_map.get('O'));
mass_table.put('n', fix_mod_map.get('n'));
mass_table.put('c', fix_mod_map.get('c'));
}
Expand All @@ -57,19 +57,19 @@ public int mzToBin(double mz) {
return (int) (mz * inverseMzBinSize + one_minus_bin_offset);
}

public float calResidueMass(String seq) { // n and c are also AA.
public double calResidueMass(String seq) { // n and c are also AA.
double total_mass = 0;
Matcher matcher = mod_aa_pattern.matcher(seq);
while (matcher.find()) {
char aa = matcher.group(1).charAt(0);
float delta_mass = 0;
double delta_mass = 0;
if (matcher.group(3) != null) {
delta_mass = Float.valueOf(matcher.group(3));
delta_mass = Double.valueOf(matcher.group(3));
}
total_mass += mass_table.get(aa) + delta_mass;
}

return (float) total_mass;
return total_mass;
}

public Set<String> buildChainSet(String pro_seq, short linker_type) {
Expand Down Expand Up @@ -106,11 +106,11 @@ public Set<String> buildChainSet(String pro_seq, short linker_type) {
return chain_seq_set;
}

public Map<Character, Float> getMassTable() {
public Map<Character, Double> getMassTable() {
return mass_table;
}

public double generateTheoFragmentAndCalXCorr(String seq, short linkSite, float additional_mass, int precursor_charge, SparseVector xcorrPL) {
public double generateTheoFragmentAndCalXCorr(String seq, short linkSite, double additional_mass, int precursor_charge, SparseVector xcorrPL) {
linkSite = (short) Math.max(1, linkSite);

int localMaxCharge = Math.min(max_charge, Math.max(precursor_charge - 1, 1));
Expand Down Expand Up @@ -182,9 +182,9 @@ public static AA[] seqToAAList(String seq) {
List<AA> temp = new LinkedList<>();
while (matcher.find()) {
char aa = matcher.group(1).charAt(0);
float delta_mass = 0;
double delta_mass = 0;
if (matcher.group(3) != null) {
delta_mass = Float.valueOf(matcher.group(3));
delta_mass = Double.valueOf(matcher.group(3));
}
temp.add(new AA(aa, delta_mass));
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/proteomics/Types/AA.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
public class AA {

public final char aa;
public final float delta_mass;
public final double delta_mass;
private final int hashCode;

public AA(char aa, float delta_mass) {
public AA(char aa, double delta_mass) {
this.aa = aa;
this.delta_mass = delta_mass;
String toString;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/proteomics/Types/BinaryModParam.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@


public class BinaryModParam {
public final float modMass;
public final double modMass;
public final String aas;

private final int hashCode;

public BinaryModParam(float modMass, String aas) {
public BinaryModParam(double modMass, String aas) {
this.modMass = modMass;
this.aas = aas;
String toString = modMass + "@" + aas + "(binary)";
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/proteomics/Types/ChainEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
public class ChainEntry {

public final String seq;
public final float chain_mass;
public final double chain_mass;
public final Set<Short> link_site_set;
public final boolean n_term;
public final boolean c_term;
public final int binaryModType;

public ChainEntry(String seq, float chain_mass, Set<Short> link_site_set, boolean n_term, boolean c_term, int binaryModType) {
public ChainEntry(String seq, double chain_mass, Set<Short> link_site_set, boolean n_term, boolean c_term, int binaryModType) {
this.seq = seq;
this.chain_mass = chain_mass;
this.link_site_set = link_site_set;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/proteomics/Types/DebugEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ public class DebugEntry implements Comparable<DebugEntry> {

public final String chain;
public final int link_site;
public final float mass;
public final double mass;
public final double score;

public DebugEntry(String chain, int link_site, float mass, double score) {
public DebugEntry(String chain, int link_site, double mass, double score) {
this.chain = chain;
this.link_site = link_site;
this.mass = mass;
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/proteomics/Types/ResultEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public class ResultEntry{
private long candidate_num;
private int score_count = 0;
private double e_value = 9999;
private float r_square;
private float slope;
private float intercept;
private double r_square;
private double slope;
private double intercept;
private int start_idx;
private int end_idx;

Expand Down Expand Up @@ -97,7 +97,7 @@ public void addToScoreHistogram(double score) {
}
}

public void setEValueDetails(float r_square, float slope, float intercept, int start_idx, int end_idx) {
public void setEValueDetails(double r_square, double slope, double intercept, int start_idx, int end_idx) {
this.r_square = r_square;
this.slope = slope;
this.intercept = intercept;
Expand Down Expand Up @@ -152,15 +152,15 @@ public int getScoreCount() {
return score_count;
}

public float getRSquare() {
public double getRSquare() {
return r_square;
}

public float getSlope() {
public double getSlope() {
return slope;
}

public float getIntercept() {
public double getIntercept() {
return intercept;
}

Expand Down
Loading

0 comments on commit e764efe

Please sign in to comment.