From 42f165d56ce74a4f2aabadf897bf5025b704034b Mon Sep 17 00:00:00 2001
From: Olivier Langella <Olivier.Langella@moulon.inra.fr>
Date: Tue, 3 Dec 2013 16:41:18 +0100
Subject: [PATCH] fixed and understand the treatment of best phospho positions
 et observed phospho positions

---
 .../GroupingProtein/PeptideMass.java          |   2 -
 .../xtandempipeline/class_msms/Match.java     |   2 +-
 .../filter_print/swt_table_peptide.java       |   4 +-
 .../grouping/HashSampleScanSetPhospho.java    | 101 +++++++++++++-----
 .../grouping/interfaces/GrpProtMatch.java     |   9 +-
 .../SpreadSheets/OdsPhosphoPeptideOutput.java |   7 +-
 .../SpreadSheets/OdsPhosphoSpectraOutput.java |  21 ++--
 7 files changed, 98 insertions(+), 48 deletions(-)

diff --git a/src/fr/inra/pappso/xtandempipeline/class_msms/GroupingProtein/PeptideMass.java b/src/fr/inra/pappso/xtandempipeline/class_msms/GroupingProtein/PeptideMass.java
index 25d910d7d..fd484299a 100644
--- a/src/fr/inra/pappso/xtandempipeline/class_msms/GroupingProtein/PeptideMass.java
+++ b/src/fr/inra/pappso/xtandempipeline/class_msms/GroupingProtein/PeptideMass.java
@@ -24,11 +24,9 @@ import java.util.HashMap;
 
 import org.apache.log4j.Logger;
 
-import fr.inra.pappso.xtandempipeline.Utils;
 import fr.inra.pappso.xtandempipeline.MsException.MSMSException;
 import fr.inra.pappso.xtandempipeline.class_msms.MsRun;
 import fr.inra.pappso.xtandempipeline.class_msms.MapDb.Peptide;
-import fr.inra.pappso.xtandempipeline.grouping.Group;
 import fr.inra.pappso.xtandempipeline.grouping.HashSampleScan;
 import fr.inra.pappso.xtandempipeline.grouping.HashSampleScanSet;
 import fr.inra.pappso.xtandempipeline.grouping.SubGroup;
diff --git a/src/fr/inra/pappso/xtandempipeline/class_msms/Match.java b/src/fr/inra/pappso/xtandempipeline/class_msms/Match.java
index 5943a52c3..558feb385 100644
--- a/src/fr/inra/pappso/xtandempipeline/class_msms/Match.java
+++ b/src/fr/inra/pappso/xtandempipeline/class_msms/Match.java
@@ -13,7 +13,6 @@ import fr.inra.pappso.xtandempipeline.class_msms.MapDb.Peptide;
 import fr.inra.pappso.xtandempipeline.grouping.HashProtein;
 import fr.inra.pappso.xtandempipeline.grouping.HashSampleScan;
 import fr.inra.pappso.xtandempipeline.grouping.HashSampleScanSetPhospho;
-import fr.inra.pappso.xtandempipeline.grouping.HashSampleScanSetProt;
 import fr.inra.pappso.xtandempipeline.grouping.interfaces.GrpPeptide;
 import fr.inra.pappso.xtandempipeline.grouping.interfaces.GrpProtMatch;
 
@@ -352,6 +351,7 @@ public class Match implements Comparable<Match>, GrpProtMatch {
 		return protein_match;
 	}
 
+	@Override
 	public ArrayList<Peptide> getValidPeptideInPhosphoIsland(
 			HashSampleScanSetPhospho hashPhospho) throws MSMSException {
 		ArrayList<Peptide> peps = new ArrayList<Peptide>();
diff --git a/src/fr/inra/pappso/xtandempipeline/filter_print/swt_table_peptide.java b/src/fr/inra/pappso/xtandempipeline/filter_print/swt_table_peptide.java
index 8a7efa7e8..7d9eaf9fc 100644
--- a/src/fr/inra/pappso/xtandempipeline/filter_print/swt_table_peptide.java
+++ b/src/fr/inra/pappso/xtandempipeline/filter_print/swt_table_peptide.java
@@ -114,8 +114,8 @@ public class swt_table_peptide extends swt_table_base {
 				if (pep.getSequence().contains(this.filter_value))
 					filterPeptideSet.add(hash);
 			} else if (this.filtercolumn.equals("Sample")) {
-				if (hash.getGrpMsSample().getSampleName().contains(
-						this.filter_value))
+				if (hash.getGrpMsSample().getSampleName()
+						.contains(this.filter_value))
 					filterPeptideSet.add(hash);
 			} else if (this.filtercolumn.equals("Modifs")) {
 				if (pep.get_Modifs_formater().contains(this.filter_value))
diff --git a/src/fr/inra/pappso/xtandempipeline/grouping/HashSampleScanSetPhospho.java b/src/fr/inra/pappso/xtandempipeline/grouping/HashSampleScanSetPhospho.java
index e5feea0bc..c638df84b 100644
--- a/src/fr/inra/pappso/xtandempipeline/grouping/HashSampleScanSetPhospho.java
+++ b/src/fr/inra/pappso/xtandempipeline/grouping/HashSampleScanSetPhospho.java
@@ -1,11 +1,14 @@
 package fr.inra.pappso.xtandempipeline.grouping;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.TreeSet;
 
 import org.apache.log4j.Logger;
 
 import fr.inra.pappso.xtandempipeline.MsException.MSMSException;
+import fr.inra.pappso.xtandempipeline.class_msms.GroupingProtein.PeptideMass;
+import fr.inra.pappso.xtandempipeline.class_msms.MapDb.Peptide;
 import fr.inra.pappso.xtandempipeline.grouping.interfaces.GrpPeptide;
 import fr.inra.pappso.xtandempipeline.grouping.interfaces.GrpPhosphoModif;
 import fr.inra.pappso.xtandempipeline.grouping.interfaces.GrpProtMatch;
@@ -50,55 +53,95 @@ public class HashSampleScanSetPhospho extends HashSampleScanSetProt {
 		super.clear();
 	}
 
-/*
-	@Override
-	public int compareTo(HashSampleScanSet o) {
-		int i = o.size() - this.size();
-		if (i != 0)
-			return i;
-		return (o.hashCode() - this.hashCode());
-	}
-*/
-	public TreeSet<Integer> getPhosphoPositions(){
-		return(phosphoPositions);
+	/*
+	 * @Override public int compareTo(HashSampleScanSet o) { int i = o.size() -
+	 * this.size(); if (i != 0) return i; return (o.hashCode() -
+	 * this.hashCode()); }
+	 */
+	public TreeSet<Integer> getPhosphoPositions() {
+		return (phosphoPositions);
 	}
-	
-	public String getPhosphoPositionToPrint(){
+
+	public String getPhosphoPositionToPrint() {
 		String S = "";
-		for(Integer value : this.phosphoPositions){
-			S = S +" "+ value;
+		for (Integer value : this.phosphoPositions) {
+			S = S + " " + value;
 		}
 		S.replaceFirst(" ", "");
-		return(S);
+		return (S);
 	}
-	
-	public boolean haveMultiPhosphoPeptide() throws MSMSException{
+
+	public boolean haveMultiPhosphoPeptide() throws MSMSException {
 		boolean multi = false;
-		for(HashSampleScan hash: this){
-			if(this.match.getBestPeptideToHashSampleScan(hash).getGrpPhosphoModifs().size()>1)
+		for (HashSampleScan hash : this) {
+			if (this.match.getBestPeptideToHashSampleScan(hash)
+					.getGrpPhosphoModifs().size() > 1)
 				multi = true;
 		}
-		return(multi);
+		return (multi);
 	}
-	
-	
+
 	@Override
 	public HashKey4GroupsSet getHashKey4GroupsSet() throws Exception {
 		HashKey4GroupsSet hashPeptideSet = new HashKey4GroupsSet();
 
 		HashProtein hashProtein = match.getHashProtein();
-		
+
 		hashPeptideSet.add(hashProtein);
 
 		return hashPeptideSet;
 	}
 
-	public TreeSet<Integer> getAllPositionIncluderedon(HashSampleScan hash) throws MSMSException {
-		TreeSet<Integer> posi = new TreeSet<Integer> ();
-		for (GrpPeptide pepTemp : this.match.getGrpPeptidesSharingHashSampleScan(hash)) {
-			for (GrpPhosphoModif mods : pepTemp.getGrpPhosphoModifs())
-				posi.add(mods.getPosi_in_prot());
+	public TreeSet<Integer> getAllPositionIncluderedon(HashSampleScan hash)
+			throws MSMSException {
+		TreeSet<Integer> posi = new TreeSet<Integer>();
+
+		for (GrpPhosphoModif mods : getAllPhosphoPeptideModif(hash)) {
+			posi.add(mods.getPosi_in_prot());
 		}
+
 		return posi;
 	}
+
+	/**
+	 * retrieve all Phospho Modifs concerning one Peptide
+	 * 
+	 * @param peptide
+	 * @return
+	 * @throws MSMSException
+	 */
+	public Collection<GrpPhosphoModif> getAllPhosphoPeptideModif(Peptide peptide)
+			throws MSMSException {
+		return getAllPhosphoPeptideModif(peptide.getHashSampleScan());
+	}
+
+	private Collection<GrpPhosphoModif> getAllPhosphoPeptideModif(
+			HashSampleScan hash) throws MSMSException {
+
+		ArrayList<GrpPhosphoModif> modifs = new ArrayList<GrpPhosphoModif>();
+		for (GrpPeptide pepTemp : this.match
+				.getGrpPeptidesSharingHashSampleScan(hash)) {
+			modifs.addAll(pepTemp.getGrpPhosphoModifs());
+		}
+		return modifs;
+	}
+
+	/**
+	 * retrieve all Phospho Modifs concerning one PeptideMass
+	 * 
+	 * @param peptideMass
+	 * @return
+	 * @throws MSMSException
+	 */
+
+	public Collection<GrpPhosphoModif> getAllPhosphoModif(
+			PeptideMass peptideMass) throws MSMSException {
+
+		ArrayList<GrpPhosphoModif> modifs = new ArrayList<GrpPhosphoModif>();
+		for (HashSampleScan sampleScan : peptideMass.getHashSampleScanSet()) {
+			modifs.addAll(getAllPhosphoPeptideModif(sampleScan));
+		}
+		return modifs;
+	}
+
 }
diff --git a/src/fr/inra/pappso/xtandempipeline/grouping/interfaces/GrpProtMatch.java b/src/fr/inra/pappso/xtandempipeline/grouping/interfaces/GrpProtMatch.java
index 0cb13ed40..7a2b3ca1a 100644
--- a/src/fr/inra/pappso/xtandempipeline/grouping/interfaces/GrpProtMatch.java
+++ b/src/fr/inra/pappso/xtandempipeline/grouping/interfaces/GrpProtMatch.java
@@ -1,20 +1,27 @@
 package fr.inra.pappso.xtandempipeline.grouping.interfaces;
 
+import java.util.ArrayList;
 import java.util.Collection;
 
 import fr.inra.pappso.xtandempipeline.MsException.MSMSException;
+import fr.inra.pappso.xtandempipeline.class_msms.MapDb.Peptide;
 import fr.inra.pappso.xtandempipeline.grouping.HashProtein;
 import fr.inra.pappso.xtandempipeline.grouping.HashSampleScan;
+import fr.inra.pappso.xtandempipeline.grouping.HashSampleScanSetPhospho;
 
 public interface GrpProtMatch {
 	GrpProtein getGrpProtein();
 
 	Collection<GrpPeptide> getGrpPeptides() throws MSMSException;
 
-	GrpPeptide getBestPeptideToHashSampleScan(HashSampleScan hash) throws MSMSException;
+	GrpPeptide getBestPeptideToHashSampleScan(HashSampleScan hash)
+			throws MSMSException;
 
 	HashProtein getHashProtein() throws MSMSException;
 
 	Collection<GrpPeptide> getGrpPeptidesSharingHashSampleScan(
 			HashSampleScan hash) throws MSMSException;
+
+	public ArrayList<Peptide> getValidPeptideInPhosphoIsland(
+			HashSampleScanSetPhospho hashPhospho) throws MSMSException;
 }
diff --git a/src/fr/inra/pappso/xtandempipeline/output/SpreadSheets/OdsPhosphoPeptideOutput.java b/src/fr/inra/pappso/xtandempipeline/output/SpreadSheets/OdsPhosphoPeptideOutput.java
index 6953799bc..5bf956940 100644
--- a/src/fr/inra/pappso/xtandempipeline/output/SpreadSheets/OdsPhosphoPeptideOutput.java
+++ b/src/fr/inra/pappso/xtandempipeline/output/SpreadSheets/OdsPhosphoPeptideOutput.java
@@ -48,7 +48,6 @@ import fr.inra.pappso.xtandempipeline.grouping.Group;
 import fr.inra.pappso.xtandempipeline.grouping.HashSampleScanSetPhospho;
 import fr.inra.pappso.xtandempipeline.grouping.HashSampleScanSetProt;
 import fr.inra.pappso.xtandempipeline.grouping.SubGroup;
-import fr.inra.pappso.xtandempipeline.grouping.SubGroupSet;
 import fr.inra.pappso.xtandempipeline.grouping.interfaces.GrpPhosphoModif;
 
 public class OdsPhosphoPeptideOutput {
@@ -226,6 +225,8 @@ public class OdsPhosphoPeptideOutput {
 			 * hashSampleScanSetPhospho = (HashSampleScanSetPhospho) sgList
 			 * .get(0).getHashSampleScanSetProtList().get(0);
 			 */
+			HashSampleScanSetPhospho hashSampleScanSetPhospho = (HashSampleScanSetPhospho) sg
+					.getHashSampleScanSetProtList().get(0);
 			// odsTable.writeCell("Group ID");
 			odsTable.writeCell(Utils.getPappsoGroupId(group));
 			odsTable.writeCell(Utils.getPappsoSubGroupId(group, sg));
@@ -253,12 +254,16 @@ public class OdsPhosphoPeptideOutput {
 			for (Peptide peptide : peptideSet) {
 				phosphoAllModifs.addAll(peptide.getGrpPhosphoModifs());
 			}
+
+			phosphoModifs = hashSampleScanSetPhospho
+					.getAllPhosphoModif(pepMass);
 			obsPhosphoPos = new TreeSet<Integer>();
 			for (GrpPhosphoModif phosphoModif : phosphoModifs) {
 				Modifs modif = (Modifs) phosphoModif;
 				obsPhosphoPos.add(modif.get_posi());
 			}
 			// odsTable.writeCell("All positions");
+			// TreeSet<Integer> posi = phospho.getAllPositionIncluderedon(hash);
 			odsTable.writeCell(Utils.collectionToString(obsPhosphoPos));
 
 			TreeSet<Integer> obsCharges = new TreeSet<Integer>();
diff --git a/src/fr/inra/pappso/xtandempipeline/output/SpreadSheets/OdsPhosphoSpectraOutput.java b/src/fr/inra/pappso/xtandempipeline/output/SpreadSheets/OdsPhosphoSpectraOutput.java
index 345d3fbbf..c50b11a5d 100644
--- a/src/fr/inra/pappso/xtandempipeline/output/SpreadSheets/OdsPhosphoSpectraOutput.java
+++ b/src/fr/inra/pappso/xtandempipeline/output/SpreadSheets/OdsPhosphoSpectraOutput.java
@@ -130,7 +130,7 @@ public class OdsPhosphoSpectraOutput {
 			odsTable.writeCell("Sequence (top)");
 			odsTable.writeCell("Modifs (top)");
 			odsTable.writeCell("Best position in peptide");
-			odsTable.writeCell("All Position in sequence");
+			odsTable.writeCell("All observed positions in phosphopeptide");
 			odsTable.writeCell("Number of phosphoislands");
 			odsTable.writeCell("Phosphoislands Ids");
 			odsTable.writeCell("Best e-value");
@@ -206,8 +206,6 @@ public class OdsPhosphoSpectraOutput {
 							.getHashSampleScanSetProtSet()) {
 						HashSampleScanSetPhospho hashPhospho = (HashSampleScanSetPhospho) hashPprot;
 
-						Protein prot = (Protein) hashPhospho.getGrpProtMatch()
-								.getGrpProtein();
 						HashSet<PeptideMass> uniquePepMass = new HashSet<PeptideMass>();
 
 						for (Peptide peptide : ((Match) hashPhospho
@@ -224,8 +222,10 @@ public class OdsPhosphoSpectraOutput {
 										.getHashSampleScanSet()) {
 
 									if (uniqueHashSampleScan.add(scan)) {
+
 										this.writeOneHashSampleScan(ident,
-												group, sg, prot, pepMass, scan,
+												group, sg, hashPhospho,
+												pepMass, scan,
 												hashPeptideMass2Peptides
 														.get(pepMass));
 									}
@@ -255,9 +255,9 @@ public class OdsPhosphoSpectraOutput {
 	}
 
 	private void writeOneHashSampleScan(Identification ident, Group group,
-			SubGroup sg, Protein prot, PeptideMass pepMass,
-			HashSampleScan scan, HashSet<Peptide> peptideSet)
-			throws MSMSException {
+			SubGroup sg, HashSampleScanSetPhospho hashPhospho,
+			PeptideMass pepMass, HashSampleScan scan,
+			HashSet<Peptide> peptideSet) throws MSMSException {
 		try {
 			logger.debug("writeOneHashSampleScan begin " + group + pepMass);
 			HashSet<Peptide> peptideSetScan = new HashSet<Peptide>();
@@ -317,12 +317,9 @@ public class OdsPhosphoSpectraOutput {
 
 			// odsTable.writeCell(pepMass.getSequenceLi());
 
-			HashSet<GrpPhosphoModif> phosphoAllModifs = new HashSet<GrpPhosphoModif>();
-			for (Peptide peptide : peptideSet) {
-				phosphoAllModifs.addAll(peptide.getGrpPhosphoModifs());
-			}
 			obsPhosphoPos = new TreeSet<Integer>();
-			for (GrpPhosphoModif phosphoModif : phosphoModifs) {
+			for (GrpPhosphoModif phosphoModif : hashPhospho
+					.getAllPhosphoModif(pepMass)) {
 				Modifs modif = (Modifs) phosphoModif;
 				obsPhosphoPos.add(modif.get_posi());
 			}
-- 
GitLab