Search in sources :

Example 1 with BNGSpeciesComponent

use of cbit.vcell.bionetgen.BNGSpeciesComponent in project vcell by virtualcell.

the class BNGExecutorServiceMultipass method findRuleProductCompartment.

private static String findRuleProductCompartment(BNGSpecies s) {
    boolean needsCorrection = false;
    // the structures we encounter in this species (use tree set to avoid duplicates)
    Set<String> structureNameSet = new TreeSet<>();
    // if it's a complex species we break it down in simple ones and populate this list
    List<BNGSpecies> simpleSpeciesList = new ArrayList<>();
    if (s instanceof BNGComplexSpecies) {
        simpleSpeciesList.addAll(Arrays.asList(s.parseBNGSpeciesName()));
    } else {
        // if it's a simple species to begin with we'll only have one element in this list
        simpleSpeciesList.add(s);
    }
    for (BNGSpecies simpleSpecies : simpleSpeciesList) {
        // must be multi state (actually multi-site!), we have at least 2 components (sites): RbmUtils.SiteStruct and RbmUtils.SiteProduct
        if (!(simpleSpecies instanceof BNGMultiStateSpecies)) {
            throw new RuntimeException("Species " + s.getName() + " must be instance of BNGMultiStateSpecies");
        }
        BNGMultiStateSpecies mss = (BNGMultiStateSpecies) simpleSpecies;
        // System.out.println("  " + mss.toString());
        List<BNGSpeciesComponent> componentsList = new ArrayList<>(Arrays.asList(mss.getComponents()));
        String structName = "";
        String prodPosition = "";
        for (BNGSpeciesComponent sc : componentsList) {
            // System.out.println("     " + sc.getComponentName() + "~" + sc.getCurrentState());
            if (sc.getComponentName().equals(RbmUtils.SiteStruct)) {
                structName = sc.getCurrentState();
            } else if (sc.getComponentName().equals(RbmUtils.SiteProduct)) {
                prodPosition = sc.getCurrentState();
            }
        }
        if (structName == null || structName.isEmpty() || structName.equals("null")) {
            throw new RuntimeException("Structure name site missing from BNGSpecies " + mss);
        }
        if (prodPosition == null || prodPosition.isEmpty() || prodPosition.equals("null")) {
            throw new RuntimeException("Index of original rule product site missing from BNGSpecies " + mss);
        }
        switch(prodPosition) {
            case // comes from matching a wildcard with a seed species, its compartment may be wrong
            "0":
                break;
            case // comes by directly applying a rule, this is the correct compartment inherited from the rule product
            "1":
                structureNameSet.add(structName);
                break;
            default:
                throw new RuntimeException("Product position must be 0 or 1 for " + mss.getName());
        }
    }
    if (structureNameSet.size() != 1) {
        throw new RuntimeException("The number of structures for " + s.getName() + " must be exactly 1.");
    }
    String structName = structureNameSet.iterator().next();
    return structName;
}
Also used : BNGSpeciesComponent(cbit.vcell.bionetgen.BNGSpeciesComponent) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) BNGMultiStateSpecies(cbit.vcell.bionetgen.BNGMultiStateSpecies) BNGComplexSpecies(cbit.vcell.bionetgen.BNGComplexSpecies) BNGSpecies(cbit.vcell.bionetgen.BNGSpecies)

Aggregations

BNGComplexSpecies (cbit.vcell.bionetgen.BNGComplexSpecies)1 BNGMultiStateSpecies (cbit.vcell.bionetgen.BNGMultiStateSpecies)1 BNGSpecies (cbit.vcell.bionetgen.BNGSpecies)1 BNGSpeciesComponent (cbit.vcell.bionetgen.BNGSpeciesComponent)1 ArrayList (java.util.ArrayList)1 TreeSet (java.util.TreeSet)1