Skip to content

Commit

Permalink
Improve the String output with String.join(";"). Output all proteins'…
Browse files Browse the repository at this point in the history
… annotations.
  • Loading branch information
fcyu committed Dec 23, 2017
1 parent 4769cb3 commit 452667e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
19 changes: 8 additions & 11 deletions src/main/java/proteomics/ECL2.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,22 +234,19 @@ private static void saveTargetResult(List<FinalResultEntry> result, Map<String,
if (re.hit_type == 0) {
int link_site_1 = re.link_site_1;
int link_site_2 = re.link_site_2;
String pro_1 = re.pro_id_1;
if (re.pro_id_1.contains(";")) {
pro_1 = re.pro_id_1.split(";")[0];
List<String> proAnnotationList1 = new LinkedList<>();
for (String s : re.pro_id_1.split(";")) {
proAnnotationList1.add(pro_annotate_map.get(s));
}
String pro_2 = re.pro_id_2;
if (re.pro_id_2.contains(";")) {
pro_2 = re.pro_id_2.split(";")[0];
List<String> proAnnotationList2 = new LinkedList<>();
for (String s : re.pro_id_2.split(";")) {
proAnnotationList2.add(pro_annotate_map.get(s));
}

String annotate_1 = pro_annotate_map.get(pro_1).replace(',', ';');
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(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");
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 + ",\"" + String.join(";", proAnnotationList1) + "\",\"" + String.join(";", proAnnotationList2) + "\"," + (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(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");
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 + ",\"" + String.join(";", proAnnotationList1) + "\",\"" + String.join(";", proAnnotationList2) + "\"," + (cal_evalue ? String.format(Locale.US, "%E", re.e_value) : "-") + "," + String.format(Locale.US, "%.4f", re.qvalue) + ",\"" + re.mgfTitle + "\"\n");
}
}
}
Expand Down
22 changes: 15 additions & 7 deletions src/main/java/proteomics/Search/Search.java
Original file line number Diff line number Diff line change
Expand Up @@ -257,19 +257,27 @@ public FinalResultEntry convertResultEntry(int scanNum, ResultEntry result_entry
spectrum_mass += C13_Diff_num * 1.00335483f;
float ppm = (spectrum_mass - theo_mass) * 1e6f / theo_mass;

String pro_1 = "";
Set<String> pro1Set = new TreeSet<>();
boolean isDecoy1 = false;
for (String temp : seqProMap.get(chain_entry_1.seq.replaceAll("[^A-Znc]", ""))) {
pro_1 += temp + ";";
pro1Set.add(temp);
if (temp.startsWith("DECOY")) { // there is no overlapped peptide between target and decoy.
isDecoy1 = true;
}
}
String pro_2 = "";
Set<String> pro2Set = new TreeSet<>();
boolean isDecoy2 = false;
for (String temp : seqProMap.get(chain_entry_2.seq.replaceAll("[^A-Znc]", ""))) {
pro_2 += temp + ";";
pro2Set.add(temp);
if (temp.startsWith("DECOY")) { // there is no overlapped peptide between target and decoy.
isDecoy2 = true;
}
}

int hit_type; // 0 = T-T; 1 = D-D; 2 = T-D;
if (pro_1.startsWith("DECOY") && pro_2.startsWith("DECOY")) {
if (isDecoy1 && isDecoy2) {
hit_type = 1;
} else if (!pro_1.startsWith("DECOY") && !pro_2.startsWith("DECOY")) {
} else if (!isDecoy1 && !isDecoy2) {
hit_type = 0;
} else {
hit_type = 2;
Expand Down Expand Up @@ -305,7 +313,7 @@ public FinalResultEntry convertResultEntry(int scanNum, ResultEntry result_entry
String final_seq_1 = addFixMod(chain_seq_1, result_entry.getLinkSite1());
String final_seq_2 = addFixMod(chain_seq_2, result_entry.getLinkSite2());

return new FinalResultEntry(scanNum, result_entry.spectrum_id, rank, result_entry.charge, result_entry.spectrum_mz, result_entry.spectrum_mass, theo_mass, result_entry.rt, ppm, result_entry.getScore(), delta_c, final_seq_1, result_entry.getLinkSite1(), pro_1, final_seq_2, result_entry.getLinkSite2(), pro_2, cl_type, hit_type, C13_Diff_num, result_entry.getEValue(), result_entry.getScoreCount(), result_entry.getRSquare(), result_entry.getSlope(), result_entry.getIntercept(), result_entry.getStartIdx(), result_entry.getEndIdx(), result_entry.getChainScore1(), result_entry.getChainRank1(), result_entry.getChainScore2(), result_entry.getChainRank2(), result_entry.getCandidateNum(), cal_evalue, spectrumEntry.mgfTitle);
return new FinalResultEntry(scanNum, result_entry.spectrum_id, rank, result_entry.charge, result_entry.spectrum_mz, result_entry.spectrum_mass, theo_mass, result_entry.rt, ppm, result_entry.getScore(), delta_c, final_seq_1, result_entry.getLinkSite1(), String.join(";", pro1Set), final_seq_2, result_entry.getLinkSite2(), String.join(";", pro2Set), cl_type, hit_type, C13_Diff_num, result_entry.getEValue(), result_entry.getScoreCount(), result_entry.getRSquare(), result_entry.getSlope(), result_entry.getIntercept(), result_entry.getStartIdx(), result_entry.getEndIdx(), result_entry.getChainScore1(), result_entry.getChainRank1(), result_entry.getChainScore2(), result_entry.getChainRank2(), result_entry.getCandidateNum(), cal_evalue, spectrumEntry.mgfTitle);
}

private void linearScan(SpectrumEntry spectrumEntry, SparseVector xcorrPL, int specMaxBinIdx, ChainEntry chainEntry, int binInx, TreeMap<Integer, ChainResultEntry> binChainMap, List<DebugEntry> debugEntryList, Map<String, Double> devChainScoreMap) {
Expand Down

0 comments on commit 452667e

Please sign in to comment.