use of cbit.vcell.graph.ReactionParticipantShape in project vcell by virtualcell.
the class ReactionCartoonTool method detailsDeleteSpecies.
private static DeleteSpeciesInfo detailsDeleteSpecies(Component requester, SpeciesContext[] speciesContextArr, ReactionStep[] toBeDeletedReactStepArr, ReactionCartoon rxCartoon) throws Exception, UserCancelException {
if (speciesContextArr == null || speciesContextArr.length == 0) {
return null;
}
// Warn user that there may be some BioModel components that reference speciesContext to be removed
// Get ReactionParticipant list
Collection<Shape> rxPartColl = rxCartoon.getShapes();
HashMap<SpeciesContext, HashSet<ReactionParticipant>> rxPartHashMap = new HashMap<SpeciesContext, HashSet<ReactionParticipant>>();
for (Shape objShape : rxPartColl) {
if (objShape instanceof ReactionParticipantShape) {
ReactionParticipant objReactionParticipant = ((ReactionParticipantShape) objShape).getReactionParticipant();
if (Arrays.asList(speciesContextArr).contains(objReactionParticipant.getSpeciesContext())) {
if (!rxPartHashMap.containsKey(objReactionParticipant.getSpeciesContext())) {
rxPartHashMap.put(objReactionParticipant.getSpeciesContext(), new HashSet<ReactionParticipant>());
}
if (!rxPartHashMap.get(objReactionParticipant.getSpeciesContext()).contains(objReactionParticipant)) {
rxPartHashMap.get(objReactionParticipant.getSpeciesContext()).add(objReactionParticipant);
}
}
}
}
int reactionParticipantCount = 0;
for (HashSet<ReactionParticipant> objReactPart : rxPartHashMap.values()) {
reactionParticipantCount += objReactPart.size();
}
// find bioModel and get SymbolTable references to SpeciesContext
BioModelEditor bioModelEditor = (BioModelEditor) BeanUtils.findTypeParentOfComponent(requester, BioModelEditor.class);
if (bioModelEditor == null) {
throw new Exception("Error deleting Speciescontext, Can't find BiomodelEditor");
}
BioModel bioModel = bioModelEditor.getBioModelWindowManager().getVCDocument();
HashMap<SpeciesContext, HashSet<SymbolTableEntry>> referencingSymbolsHashMap = new HashMap<SpeciesContext, HashSet<SymbolTableEntry>>();
for (int i = 0; i < speciesContextArr.length; i++) {
List<SymbolTableEntry> referencingSymbolsList = bioModel.findReferences(speciesContextArr[i]);
if (referencingSymbolsList != null && referencingSymbolsList.size() > 0) {
if (!referencingSymbolsHashMap.containsKey(speciesContextArr[i])) {
referencingSymbolsHashMap.put(speciesContextArr[i], new HashSet<SymbolTableEntry>());
}
referencingSymbolsHashMap.get(speciesContextArr[i]).addAll(referencingSymbolsList);
}
}
int referencingSymbolsCount = 0;
for (HashSet<SymbolTableEntry> objSimTableEntry : referencingSymbolsHashMap.values()) {
referencingSymbolsCount += objSimTableEntry.size();
}
// Warn user about delete
HashMap<SpeciesContext, Boolean> bUnresolvableHashMap = new HashMap<SpeciesContext, Boolean>();
for (int i = 0; i < speciesContextArr.length; i++) {
bUnresolvableHashMap.put(speciesContextArr[i], Boolean.FALSE);
}
String[][] rowData = null;
if (rxPartHashMap.size() == 0 && referencingSymbolsHashMap.size() == 0) {
rowData = new String[speciesContextArr.length][4];
for (int i = 0; i < speciesContextArr.length; i++) {
rowData[i][0] = speciesContextArr[i].getName();
rowData[i][1] = "";
rowData[i][2] = "";
rowData[i][3] = "";
}
Arrays.sort(rowData, new Comparator<String[]>() {
@Override
public int compare(String[] o1, String[] o2) {
return o1[0].compareToIgnoreCase(o2[0]);
}
});
} else {
// find SpeciesContext that had no reference warnings
Vector<SpeciesContext> speciesContextNoReferences = new Vector<SpeciesContext>();
for (int i = 0; i < speciesContextArr.length; i++) {
if (!rxPartHashMap.containsKey(speciesContextArr[i]) && !referencingSymbolsHashMap.containsKey(speciesContextArr[i])) {
speciesContextNoReferences.add(speciesContextArr[i]);
}
}
rowData = new String[reactionParticipantCount + referencingSymbolsCount + speciesContextNoReferences.size()][4];
int count = 0;
for (SpeciesContext objSpeciesContext : speciesContextNoReferences) {
rowData[count][0] = objSpeciesContext.getName();
rowData[count][1] = "";
rowData[count][2] = "";
rowData[count][3] = "";
count++;
}
for (SpeciesContext objSpeciesContext : rxPartHashMap.keySet()) {
Iterator<ReactionParticipant> iterRxPart = rxPartHashMap.get(objSpeciesContext).iterator();
while (iterRxPart.hasNext()) {
rowData[count][0] = objSpeciesContext.getName();
rowData[count][1] = "";
rowData[count][2] = "Reaction Diagram stoichiometry '" + iterRxPart.next().getReactionStep().getName() + "'";
rowData[count][3] = "";
count++;
}
}
for (SpeciesContext objSpeciesContext : referencingSymbolsHashMap.keySet()) {
Iterator<SymbolTableEntry> iterSymbolTableEntry = referencingSymbolsHashMap.get(objSpeciesContext).iterator();
while (iterSymbolTableEntry.hasNext()) {
rowData[count][0] = objSpeciesContext.getName();
rowData[count][1] = "";
SymbolTableEntry objSymbolTableEntry = iterSymbolTableEntry.next();
boolean bKineticsParameter = objSymbolTableEntry instanceof KineticsParameter;
if (bKineticsParameter) {
KineticsParameter kp = (KineticsParameter) objSymbolTableEntry;
boolean isOK = kp.isRegenerated();
for (int i = 0; toBeDeletedReactStepArr != null && i < toBeDeletedReactStepArr.length; i++) {
if (toBeDeletedReactStepArr[i] == kp.getKinetics().getReactionStep()) {
// OK to delete this Speciescontext if were deleting the reaction that contained the reference
isOK = true;
}
}
rowData[count][1] = (isOK ? "" : RXSPECIES_ERROR);
bUnresolvableHashMap.put(objSpeciesContext, bUnresolvableHashMap.get(objSpeciesContext) || !isOK);
}
boolean bReaction = objSymbolTableEntry.getNameScope() instanceof ReactionNameScope;
rowData[count][2] = (bReaction ? "Reaction" : objSymbolTableEntry.getNameScope().getClass().getName()) + "( " + objSymbolTableEntry.getNameScope().getName() + " )";
rowData[count][3] = (bKineticsParameter ? "Parameter" : objSymbolTableEntry.getClass().getName()) + "( " + objSymbolTableEntry.getName() + " )";
count++;
}
}
// for (SymbolTableEntry referencingSTE : referencingSymbols) {
// System.out.println("REFERENCE "+referencingSTE.getClass().getName()+"("+referencingSTE.getName()+") nameScope "+referencingSTE.getNameScope().getClass().getName()+"("+referencingSTE.getNameScope().getName()+")");
// }
Arrays.sort(rowData, new Comparator<String[]>() {
@Override
public int compare(String[] o1, String[] o2) {
return o1[0].compareToIgnoreCase(o2[0]);
}
});
}
if (rowData == null || rowData.length == 0) {
return null;
}
return new DeleteSpeciesInfo(rxPartHashMap, bUnresolvableHashMap, rowData);
}
Aggregations