Skip to content
Snippets Groups Projects
Commit 306af45c authored by valot's avatar valot
Browse files

Add equals function to group and subgroup

Don't clear and addAll at each subgroup addition of groupList
Performed removed non informative sub-group after finish grouping.
Now, all work fine and are reproductibly.

git-svn-id: https://subversion.renater.fr/xtandempipeline/trunk@301 b8ef2a07-7df7-436f-90b9-41648038564b
parent 917e6a16
No related branches found
No related tags found
No related merge requests found
package fr.inra.pappso.xtandempipeline.grouping;
import java.util.ArrayList;
import java.util.HashSet;
import org.apache.log4j.Logger;
......@@ -30,7 +31,13 @@ public class Group extends HashKey4GroupsSet implements Comparable<Group> {
groupStr = groupStr + sg.toString();
}
return groupStr;
}
@Override
public boolean equals(Object InCompare) {
if (this == InCompare)
return (true);
return false;
}
public boolean fusionWith(Group incomingGroup) throws Exception {
......@@ -58,7 +65,8 @@ public class Group extends HashKey4GroupsSet implements Comparable<Group> {
throw new Exception(message);
}
if (this.contains(hashPeptide)) {
logger.debug("launch fusion : this peptide was found in group "+hashPeptide.toString());
logger.debug("launch fusion : this peptide was found in group "
+ hashPeptide.toString());
return true;
} else {
// logger.debug(" hashPeptide " + hashPeptide +
......@@ -101,156 +109,172 @@ public class Group extends HashKey4GroupsSet implements Comparable<Group> {
}
}
@SuppressWarnings("unused")
private boolean removeNonInformativeConsideringGroup(Group incomingGroup)
throws Exception {
boolean changed = false;
HashSampleScanSet sampleScanSetOverall = new HashSampleScanSet();
sampleScanSetOverall.addAll(this.getHashSampleScanSet());
sampleScanSetOverall.addAll(incomingGroup.getHashSampleScanSet());
// remove in self
SubGroupSet newSubGroupListToKeepSelf = new SubGroupSet();
for (HashSampleScan SampleScan : sampleScanSetOverall) {
int nbPresence = 0;
SubGroup sgSpec = null;
for (SubGroup sg : this.subGroupList) {
if (sg.contains(SampleScan)) {
nbPresence++;
sgSpec = sg;
}
}
if (nbPresence == 1) {
newSubGroupListToKeepSelf.add(sgSpec);
}
}
if (this.subGroupList.size() > newSubGroupListToKeepSelf.size()) {
logger.debug((this.subGroupList.size() - newSubGroupListToKeepSelf
.size()) + " subgroups removed : non informative");
this.subGroupList.clear();
this.subGroupList.addAll(newSubGroupListToKeepSelf);
HashKey4GroupsSet newKeys = new HashKey4GroupsSet();
for (SubGroup sg : subGroupList) {
newKeys.addAll(sg.getHashKey4GroupsSet());
}
if (this.size() > newKeys.size()) {
logger.debug(" this group has changed : " + this.size() + " > "
+ newKeys.size());
this.clear();
this.addAll(newKeys);
changed = true;
logger.debug(" this group new size : " + this.size());
}
}
// remove in incoming
SubGroupSet newSubGroupListToKeepIncoming = new SubGroupSet();
for (HashSampleScan SampleScan : sampleScanSetOverall) {
int nbPresence = 0;
SubGroup sgSpec = null;
for (SubGroup sg : incomingGroup.subGroupList) {
if (sg.contains(SampleScan)) {
nbPresence++;
sgSpec = sg;
}
}
if (nbPresence == 1) {
newSubGroupListToKeepIncoming.add(sgSpec);
}
}
if (incomingGroup.subGroupList.size() > newSubGroupListToKeepIncoming
.size()) {
logger.debug("incoming group before : \n"
+ incomingGroup.toString());
logger.debug((incomingGroup.subGroupList.size() - newSubGroupListToKeepIncoming
.size())
+ " subgroups removed from incomingGroup : non informative");
incomingGroup.subGroupList.clear();
incomingGroup.subGroupList.addAll(newSubGroupListToKeepIncoming);
HashKey4GroupsSet newKeys = new HashKey4GroupsSet();
for (SubGroup sg : incomingGroup.subGroupList) {
newKeys.addAll(sg.getHashKey4GroupsSet());
}
if (incomingGroup.size() > newKeys.size()) {
logger.debug(" incoming group has changed : "
+ incomingGroup.size() + " > " + newKeys.size());
incomingGroup.clear();
incomingGroup.addAll(newKeys);
changed = true;
logger.debug(" incoming group new size : "
+ incomingGroup.size());
logger.debug("incoming group after : \n"
+ incomingGroup.toString());
}
}
return changed;
}
// @SuppressWarnings("unused")
// private boolean removeNonInformativeConsideringGroup(Group incomingGroup)
// throws Exception {
//
// boolean changed = false;
// HashSampleScanSet sampleScanSetOverall = new HashSampleScanSet();
// sampleScanSetOverall.addAll(this.getHashSampleScanSet());
// sampleScanSetOverall.addAll(incomingGroup.getHashSampleScanSet());
//
// // remove in self
// SubGroupSet newSubGroupListToKeepSelf = new SubGroupSet();
//
// for (HashSampleScan SampleScan : sampleScanSetOverall) {
// int nbPresence = 0;
// SubGroup sgSpec = null;
// for (SubGroup sg : this.subGroupList) {
// if (sg.contains(SampleScan)) {
// nbPresence++;
// sgSpec = sg;
// }
// }
// if (nbPresence == 1) {
// newSubGroupListToKeepSelf.add(sgSpec);
// }
// }
//
// if (this.subGroupList.size() > newSubGroupListToKeepSelf.size()) {
// logger.debug((this.subGroupList.size() - newSubGroupListToKeepSelf
// .size()) + " subgroups removed : non informative");
// this.subGroupList.clear();
// this.subGroupList.addAll(newSubGroupListToKeepSelf);
//
// HashKey4GroupsSet newKeys = new HashKey4GroupsSet();
// for (SubGroup sg : subGroupList) {
// newKeys.addAll(sg.getHashKey4GroupsSet());
// }
// if (this.size() > newKeys.size()) {
// logger.debug(" this group has changed : " + this.size() + " > "
// + newKeys.size());
// this.clear();
// this.addAll(newKeys);
// changed = true;
// logger.debug(" this group new size : " + this.size());
// }
// }
//
// // remove in incoming
//
// SubGroupSet newSubGroupListToKeepIncoming = new SubGroupSet();
//
// for (HashSampleScan SampleScan : sampleScanSetOverall) {
// int nbPresence = 0;
// SubGroup sgSpec = null;
// for (SubGroup sg : incomingGroup.subGroupList) {
// if (sg.contains(SampleScan)) {
// nbPresence++;
// sgSpec = sg;
// }
// }
// if (nbPresence == 1) {
// newSubGroupListToKeepIncoming.add(sgSpec);
// }
// }
//
// if (incomingGroup.subGroupList.size() > newSubGroupListToKeepIncoming
// .size()) {
// logger.debug("incoming group before : \n"
// + incomingGroup.toString());
// logger.debug((incomingGroup.subGroupList.size() - newSubGroupListToKeepIncoming
// .size())
// + " subgroups removed from incomingGroup : non informative");
// incomingGroup.subGroupList.clear();
// incomingGroup.subGroupList.addAll(newSubGroupListToKeepIncoming);
//
// HashKey4GroupsSet newKeys = new HashKey4GroupsSet();
// for (SubGroup sg : incomingGroup.subGroupList) {
// newKeys.addAll(sg.getHashKey4GroupsSet());
// }
// if (incomingGroup.size() > newKeys.size()) {
// logger.debug(" incoming group has changed : "
// + incomingGroup.size() + " > " + newKeys.size());
// incomingGroup.clear();
// incomingGroup.addAll(newKeys);
// changed = true;
// logger.debug(" incoming group new size : "
// + incomingGroup.size());
// logger.debug("incoming group after : \n"
// + incomingGroup.toString());
// }
// }
// return changed;
// }
protected boolean removeNonInformative() throws Exception {
boolean changed = false;
HashSampleScanSet sampleScanSetOverall = this.getHashSampleScanSet();
SubGroupSet newSubGroupListToKeep = new SubGroupSet();
for (HashSampleScan SampleScan : sampleScanSetOverall) {
int nbPresence = 0;
SubGroup sgSpec = null;
for (SubGroup sg : this.subGroupList) {
if (sg.contains(SampleScan)) {
nbPresence++;
sgSpec = sg;
}
}
if (nbPresence == 1) {
newSubGroupListToKeep.add(sgSpec);
}
}
int deltaSize = this.subGroupList.size()- newSubGroupListToKeep.size();
if (deltaSize == 0) {
changed = false;
}
else if (deltaSize == 1) {
logger.debug((this.subGroupList.size() - newSubGroupListToKeep
.size()) + " subgroups removed : non informative");
this.subGroupList.clear();
this.subGroupList.addAll(newSubGroupListToKeep);
changed = true;
}
else {
//Plusieurs sous-groupe à enlever ???
SubGroupSet sgListToRemove = new SubGroupSet();
sgListToRemove.addAll(subGroupList);
sgListToRemove.removeAll(newSubGroupListToKeep);
SubGroup sgToRemove = null;
int sgToRemoveSize = 1000000;
for (SubGroup sg : sgListToRemove) {
logger.debug("Remove non informative : "
+ sg.getHashSampleScanSetProtList().get(0)
ArrayList<SubGroup> sgList = this.subGroupList.getSubGroupList();
for (int i = sgList.size() - 1; i >= 0; i--) {
HashSampleScanSetProt hashProt = sgList.get(i)
.getHashSampleScanSetProtList().get(0);
int count = this.getNumberOfSpecificPeptideInSubGroup(hashProt);
if (count == 0) {
this.subGroupList.remove(sgList.get(i));
logger.debug("Remove non informative subgroup "
+ sgList.get(i).getHashSampleScanSetProtList().get(0)
.getMatch().get_protein_match()
.get_cle_accession());
if (sg.size() < sgToRemoveSize) {
sgToRemove = sg;
sgToRemoveSize = sg.size();
}
return(true);
}
this.subGroupList.remove(sgToRemove);
this.removeNonInformative();
changed=true;
}
return changed;
return(false);
}
// protected boolean removeNonInformative() throws Exception {
// boolean changed = false;
// HashSampleScanSet sampleScanSetOverall = this.getHashSampleScanSet();
// SubGroupSet newSubGroupListToKeep = new SubGroupSet();
// for (HashSampleScan SampleScan : sampleScanSetOverall) {
// int nbPresence = 0;
// SubGroup sgSpec = null;
// for (SubGroup sg : this.subGroupList) {
// if (sg.contains(SampleScan)) {
// nbPresence++;
// sgSpec = sg;
// }
// }
// if (nbPresence == 1) {
// newSubGroupListToKeep.add(sgSpec);
// }
// }
// int deltaSize = this.subGroupList.size() - newSubGroupListToKeep.size();
// if (deltaSize == 0) {
// changed = false;
// } else if (deltaSize == 1) {
// logger.debug((this.subGroupList.size() - newSubGroupListToKeep
// .size()) + " subgroups removed : non informative");
// this.subGroupList.clear();
// this.subGroupList.addAll(newSubGroupListToKeep);
// changed = true;
// } else {
// logger.debug((this.subGroupList.size() - newSubGroupListToKeep
// .size()) + " subgroups removed : non informative");
// // Plusieurs sous-groupe à enlever ???
// SubGroupSet sgListToRemove = new SubGroupSet();
// sgListToRemove.addAll(subGroupList);
// sgListToRemove.removeAll(newSubGroupListToKeep);
//
// SubGroup sgToRemove = null;
// int sgToRemoveSize = 1000000;
//
// for (SubGroup sg : sgListToRemove) {
// logger.debug("Remove non informative : "
// + sg.getHashSampleScanSetProtList().get(0).getMatch()
// .get_protein_match().get_cle_accession());
// if (sg.size() < sgToRemoveSize) {
// sgToRemove = sg;
// sgToRemoveSize = sg.size();
// }
// }
// this.subGroupList.remove(sgToRemove);
// this.removeNonInformative();
//
// changed = true;
//
// }
// return changed;
// }
public SubGroupSet getSubGroupSet() {
return this.subGroupList;
}
......
......@@ -21,9 +21,11 @@ public class GroupSet {
for (SubGroup subGroup : subGroupSet) {
this.addSubGroup(subGroup);
}
/*
* for (Group group : this.groupList) { group.removeNonInformative(); }
*/
logger.debug("Removing Non Informative Sub-Group");
this.removingNonIformativeGroup();
logger.debug("Numbering group");
this.numbering();
}
......@@ -40,41 +42,50 @@ public class GroupSet {
}
}
private void removingNonIformativeGroup() throws Exception {
HashSet<Group> toRemove = new HashSet<Group>(0);
HashSet<Group> toAdd = new HashSet<Group>(0);
for (Group group : this.groupList) {
boolean remove = false;
//remove sequentially sub-group to
while(group.removeNonInformative()){
remove=true;
}
//There is removed Sub-grouped, check it
if(remove){
toAdd.addAll(group.reGroup());
toRemove.add(group);
}
}
this.groupList.removeAll(toRemove);
this.groupList.addAll(toAdd);
}
protected void addSubGroup(SubGroup subGroup) throws Exception {
logger.debug("addSubGroup "+subGroup.getHashSampleScanSetProtList().get(0).toString());
logger.debug("addSubGroup "
+ subGroup.getHashSampleScanSetProtList().get(0).toString());
Group group = new Group(subGroup);
this.add(group);
}
private boolean add(Group groupToAdd) throws Exception {
HashSet<Group> newGroupList = new HashSet<Group>(0);
HashSet<Group> removeGroupList = new HashSet<Group>(0);
boolean fusion = false;
for (Group group : groupList) {
if (groupToAdd.fusionWith(group)) {
fusion = true;
} else {
newGroupList.add(group);
removeGroupList.add(group);
}
}
if (fusion) {
logger.debug("fusioning");
if (groupToAdd.removeNonInformative()) {
logger.debug("fusioning, deleting new non informative info");
newGroupList.addAll(groupToAdd.reGroup());
}
else {
logger.debug("fusioning, no removal of non informative");
newGroupList.add(groupToAdd);
}
this.groupList.add(groupToAdd);
this.groupList.removeAll(removeGroupList);
} else {
this.groupList.add(groupToAdd);
}
else {
newGroupList.add(groupToAdd);
}
this.groupList.clear();
this.groupList.addAll(newGroupList);
return true;
}
......
......@@ -36,6 +36,14 @@ public class SubGroup extends HashSampleScanSet {
return subGroupStr;
}
@Override
public boolean equals(Object toCompar) {
if(this==toCompar){
return(true);
}
return(false);
}
// @Override
public boolean addHashSampleScanSetProt(HashSampleScanSetProt incomingProt) {
......@@ -90,11 +98,6 @@ public class SubGroup extends HashSampleScanSet {
public void loggerDebug() {
super.loggerDebug();
/*logger.debug(" int this subgroup:" );
for (HashSampleScanSetProt scanProt :this.peptideSetProtList) {
logger.debug(" scanProt "+scanProt.getMatch().get_protein_match().get_cle_accession()+" "+ scanProt.size());
}
logger.debug(" end of subgroup:" ); */
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment