Skip to content

Commit

Permalink
Fix a bug due to different locale format.
Browse files Browse the repository at this point in the history
  • Loading branch information
fcyu committed Aug 22, 2017
1 parent 145eb70 commit 50fd06f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/main/java/proteomics/ECL2.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,9 @@ private static void saveTargetResult(List<FinalResultEntry> result, Map<String,
String annotate_2 = pro_annotate_map.get(pro_2).replace(",", ";");

if (dev) {
writer.write(re.scan_num + "," + re.spectrum_id + "," + re.spectrum_mz + "," + re.spectrum_mass + "," + re.peptide_mass + "," + re.rt + "," + re.C13_correction + "," + re.charge + "," + String.format("%.4f", re.score) + "," + re.delta_c + "," + String.format("%.2f", re.ppm) + "," + re.seq_1 + "-" + link_site_1 + "-" + re.seq_2 + "-" + link_site_2 + "," + re.pro_id_1 + "-" + re.pro_id_2 + ',' + annotate_1 + "," + annotate_2 + "," + (cal_evalue ? String.format("%E", re.e_value) : "-") + "," + String.format("%.4f", re.qvalue) + ",\"" + re.mgfTitle + "\",," + re.candidate_num + "," + re.point_count + "," + String.format("%.4f", re.r_square) + "," + String.format("%.4f", re.slope) + "," + String.format("%.4f", re.intercept) + "," + re.start_idx + "," + re.end_idx + "," + String.format("%.4f", re.chain_score_1) + "," + re.chain_rank_1 + "," + String.format("%.4f", re.chain_score_2) + "," + re.chain_rank_2 + "\n");
writer.write(re.scan_num + "," + re.spectrum_id + "," + re.spectrum_mz + "," + re.spectrum_mass + "," + re.peptide_mass + "," + re.rt + "," + re.C13_correction + "," + re.charge + "," + String.format(Locale.US, "%.4f", re.score) + "," + re.delta_c + "," + String.format(Locale.US, "%.2f", re.ppm) + "," + re.seq_1 + "-" + link_site_1 + "-" + re.seq_2 + "-" + link_site_2 + "," + re.pro_id_1 + "-" + re.pro_id_2 + ",\"" + annotate_1 + "\",\"" + annotate_2 + "\"," + (cal_evalue ? String.format(Locale.US, "%E", re.e_value) : "-") + "," + String.format(Locale.US, "%.4f", re.qvalue) + ",\"" + re.mgfTitle + "\",," + re.candidate_num + "," + re.point_count + "," + String.format(Locale.US, "%.4f", re.r_square) + "," + String.format(Locale.US, "%.4f", re.slope) + "," + String.format(Locale.US, "%.4f", re.intercept) + "," + re.start_idx + "," + re.end_idx + "," + String.format(Locale.US, "%.4f", re.chain_score_1) + "," + re.chain_rank_1 + "," + String.format(Locale.US, "%.4f", re.chain_score_2) + "," + re.chain_rank_2 + "\n");
} else {
writer.write(re.scan_num + "," + re.spectrum_id + "," + re.spectrum_mz + "," + re.spectrum_mass + "," + re.peptide_mass + "," + re.rt + "," + re.C13_correction + "," + re.charge + "," + String.format("%.4f", re.score) + "," + re.delta_c + "," + String.format("%.2f", re.ppm) + "," + re.seq_1 + "-" + link_site_1 + "-" + re.seq_2 + "-" + link_site_2 + "," + re.pro_id_1 + "-" + re.pro_id_2 + ',' + annotate_1 + "," + annotate_2 + "," + (cal_evalue ? String.format("%E", re.e_value) : "-") + "," + String.format("%.4f", re.qvalue) + ",\"" + re.mgfTitle + "\"\n");
writer.write(re.scan_num + "," + re.spectrum_id + "," + re.spectrum_mz + "," + re.spectrum_mass + "," + re.peptide_mass + "," + re.rt + "," + re.C13_correction + "," + re.charge + "," + String.format(Locale.US, "%.4f", re.score) + "," + re.delta_c + "," + String.format(Locale.US, "%.2f", re.ppm) + "," + re.seq_1 + "-" + link_site_1 + "-" + re.seq_2 + "-" + link_site_2 + "," + re.pro_id_1 + "-" + re.pro_id_2 + ",\"" + annotate_1 + "\",\"" + annotate_2 + "\"," + (cal_evalue ? String.format(Locale.US, "%E", re.e_value) : "-") + "," + String.format(Locale.US, "%.4f", re.qvalue) + ",\"" + re.mgfTitle + "\"\n");
}
}
}
Expand Down Expand Up @@ -286,9 +286,9 @@ private static void saveDecoyResult(List<FinalResultEntry> result, Map<String, S
}

if (dev) {
writer.write(re.scan_num + "," + re.spectrum_id + "," + re.spectrum_mz + "," + re.spectrum_mass + "," + re.peptide_mass + "," + re.rt + "," + re.C13_correction + "," + re.charge + "," + String.format("%.4f", re.score) + "," + re.delta_c + "," + String.format("%.2f", re.ppm) + "," + re.seq_1 + "-" + link_site_1 + "-" + re.seq_2 + "-" + link_site_2 + "," + re.pro_id_1 + "-" + re.pro_id_2 + ',' + annotate_1 + "," + annotate_2 + "," + (cal_evalue ? String.format("%E", re.e_value) : "-") + ",\"" + re.mgfTitle + "\",," + re.candidate_num + "," + re.point_count + "," + String.format("%.4f", re.r_square) + "," + String.format("%.4f", re.slope) + "," + String.format("%.4f", re.intercept) + "," + re.start_idx + "," + re.end_idx + "," + String.format("%.4f", re.chain_score_1) + "," + re.chain_rank_1 + "," + String.format("%.4f", re.chain_score_2) + "," + re.chain_rank_2 + "\n");
writer.write(re.scan_num + "," + re.spectrum_id + "," + re.spectrum_mz + "," + re.spectrum_mass + "," + re.peptide_mass + "," + re.rt + "," + re.C13_correction + "," + re.charge + "," + String.format(Locale.US, "%.4f", re.score) + "," + re.delta_c + "," + String.format(Locale.US, "%.2f", re.ppm) + "," + re.seq_1 + "-" + link_site_1 + "-" + re.seq_2 + "-" + link_site_2 + "," + re.pro_id_1 + "-" + re.pro_id_2 + ",\"" + annotate_1 + "\",\"" + annotate_2 + "\"," + (cal_evalue ? String.format(Locale.US, "%E", re.e_value) : "-") + ",\"" + re.mgfTitle + "\",," + re.candidate_num + "," + re.point_count + "," + String.format(Locale.US, "%.4f", re.r_square) + "," + String.format(Locale.US, "%.4f", re.slope) + "," + String.format(Locale.US, "%.4f", re.intercept) + "," + re.start_idx + "," + re.end_idx + "," + String.format(Locale.US, "%.4f", re.chain_score_1) + "," + re.chain_rank_1 + "," + String.format(Locale.US, "%.4f", re.chain_score_2) + "," + re.chain_rank_2 + "\n");
} else {
writer.write(re.scan_num + "," + re.spectrum_id + "," + re.spectrum_mz + "," + re.spectrum_mass + "," + re.peptide_mass + "," + re.rt + "," + re.C13_correction + "," + re.charge + "," + String.format("%.4f", re.score) + "," + re.delta_c + "," + String.format("%.2f", re.ppm) + "," + re.seq_1 + "-" + link_site_1 + "-" + re.seq_2 + "-" + link_site_2 + "," + re.pro_id_1 + "-" + re.pro_id_2 + ',' + annotate_1 + "," + annotate_2 + "," + (cal_evalue ? String.format("%E", re.e_value) : "-") + ",\"" + re.mgfTitle + "\"\n");
writer.write(re.scan_num + "," + re.spectrum_id + "," + re.spectrum_mz + "," + re.spectrum_mass + "," + re.peptide_mass + "," + re.rt + "," + re.C13_correction + "," + re.charge + "," + String.format(Locale.US, "%.4f", re.score) + "," + re.delta_c + "," + String.format(Locale.US, "%.2f", re.ppm) + "," + re.seq_1 + "-" + link_site_1 + "-" + re.seq_2 + "-" + link_site_2 + "," + re.pro_id_1 + "-" + re.pro_id_2 + ",\"" + annotate_1 + "\",\"" + annotate_2 + "\"," + (cal_evalue ? String.format(Locale.US, "%E", re.e_value) : "-") + ",\"" + re.mgfTitle + "\"\n");
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/proteomics/Index/BuildIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ private Set<VarSequence> generateModSeq(String seq, Set<Short> modFreeListSites,
for (int i = 0; i < seq.length(); ++i) {
sb.append(seq.substring(i, i + 1));
if (idxBinaryModMassMap.containsKey(i)) {
sb.append(String.format("[%.2f]", idxBinaryModMassMap.get(i).get(0)));
sb.append(String.format(Locale.US, "[%.2f]", idxBinaryModMassMap.get(i).get(0)));
}
}
varSeqSet.add(new VarSequence(sb.toString(), linkSite, binaryModParam.hashCode()));
Expand Down Expand Up @@ -445,7 +445,7 @@ private Set<VarSequence> generateModSeqSub(String seq, int[] idxCombination, Map
for (int i = 0; i < seq.length(); ++i) {
sb.append(seq.charAt(i));
if (localIdxModMassMap.containsKey(i)) {
sb.append(String.format("[%.2f]", localIdxModMassMap.get(i)));
sb.append(String.format(Locale.US, "[%.2f]", localIdxModMassMap.get(i)));
}
}
outputSet.add(new VarSequence(sb.toString(), linkSite, binaryModType));
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/proteomics/Search/CalEValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Locale;
import java.util.TreeMap;

public class CalEValue {
Expand Down Expand Up @@ -67,7 +68,7 @@ public class CalEValue {
try (BufferedWriter writer = new BufferedWriter(new FileWriter(scan_num + ".evalue.csv"))) {
writer.write("histogram\n");
for (int i = 0; i < max_nonzero_idx; ++i) {
writer.write(String.format("%d\n", score_histogram[i]));
writer.write(String.format(Locale.US, "%d\n", score_histogram[i]));
}
} catch (IOException ex) {
logger.error(ex.getMessage());
Expand Down Expand Up @@ -188,12 +189,12 @@ public class CalEValue {

if (ECL2.debug) {
try (BufferedWriter writer = new BufferedWriter(new FileWriter(scan_num + ".evalue.csv"))) {
writer.write(String.format("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=%.4f,intercept=%.4f,rsquare=%.4f,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("%d,%d,%.4f\n", score_histogram[i], survival_count_array[i], ln_survival_count_array[i]));
writer.write(String.format(Locale.US, "%d,%d,%.4f\n", score_histogram[i], survival_count_array[i], ln_survival_count_array[i]));
} else {
writer.write(String.format("%d,%d\n", score_histogram[i], survival_count_array[i]));
writer.write(String.format(Locale.US, "%d,%d\n", score_histogram[i], survival_count_array[i]));
}
}
} catch (IOException ex) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/proteomics/Search/Search.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ ResultEntry doSearch(SpectrumEntry spectrumEntry, SparseVector xcorrPL, int spec
debugEntryList.sort(Comparator.reverseOrder());
writer.write("chain,link_site,mass,score\n");
for (DebugEntry t : debugEntryList) {
writer.write(String.format("%s,%d,%f,%f\n", addFixMod(t.chain, t.link_site), t.link_site, t.mass, t.score));
writer.write(String.format(Locale.US, "%s,%d,%f,%f\n", addFixMod(t.chain, t.link_site), t.link_site, t.mass, t.score));
}
} catch (IOException ex) {
logger.error(ex.getMessage());
Expand Down Expand Up @@ -372,10 +372,10 @@ private String addFixMod(String seq, int linkSite) {
if (i == linkSite) { // priority order: linkSite > fixMod > varMod
sb.append(aa.aa);
} else if (Math.abs(fix_mod_map.get(aa.aa)) > 1e-6) {
sb.append(String.format("%c[%.2f]", aa.aa, fix_mod_map.get(aa.aa)));
sb.append(String.format(Locale.US, "%c[%.2f]", aa.aa, fix_mod_map.get(aa.aa)));
} else {
if (Math.abs(aa.delta_mass) > 1e-6) {
sb.append(String.format("%c[%.2f]", aa.aa, aa.delta_mass));
sb.append(String.format(Locale.US, "%c[%.2f]", aa.aa, aa.delta_mass));
} else {
sb.append(aa.aa);
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/proteomics/Types/AA.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package proteomics.Types;

import java.util.Locale;

public class AA {

public final char aa;
Expand All @@ -11,7 +13,7 @@ public AA(char aa, float delta_mass) {
this.aa = aa;
this.delta_mass = delta_mass;
if (Math.abs(delta_mass) > 1e-6) {
toString = String.format("%c[%.2f]", aa, delta_mass);
toString = String.format(Locale.US, "%c[%.2f]", aa, delta_mass);
} else {
toString = String.valueOf(aa);
}
Expand Down

0 comments on commit 50fd06f

Please sign in to comment.