Converts a BioPAX Model, Level 1 or 2, to the Level 3.

@param model BioPAX model to upgrade
@return new Level3 model
187797
public Model filter(Model model) {
		if(model == null || model.getLevel() != BioPAXLevel.L2)
			return model; // nothing to do

		preparePep2PEIDMap(model);

		final Model newModel = factory.createModel();
		newModel.getNameSpacePrefixMap().putAll(model.getNameSpacePrefixMap());
		newModel.setXmlBase(model.getXmlBase());
		
		// facilitate the conversion
		normalize(model);
		
		// First, map classes (and only set ID) if possible (pre-processing)
		for(BioPAXElement bpe : model.getObjects()) {
			Level3Element l3element = mapClass(bpe);
			if(l3element != null) {
				newModel.add(l3element);
			} else {
				log.debug("Skipping " + bpe + " " + bpe.getModelInterface().getSimpleName());
			}
		}
		
		/* process each L2 element (mapping properties), 
		 * except for pEPs and oCVs that must be processed as values
		 * (anyway, we do not want dangling elements)
		 */
		for(BioPAXElement e : model.getObjects()) {
			if(e instanceof physicalEntityParticipant
				|| e instanceof openControlledVocabulary) {
				continue;
			}
			
			// map properties
			traverse((Level2Element) e, newModel);
		}

		log.info("Done: new L3 model contains " + newModel.getObjects().size() + " BioPAX individuals.");
		
		// fix new model (e.g., add PathwayStep's processes to the pathway components ;))
		normalize(newModel);
		
		return newModel;
	}
1064785
public Collection<GMTEntry> convert(final Model model)
	{
		final Collection<GMTEntry> toReturn = new TreeSet<GMTEntry>(new Comparator<GMTEntry>() {
			@Override
			public int compare(GMTEntry o1, GMTEntry o2) {
				return o1.toString().compareTo(o2.toString());
			}
		});

		Model l3Model;
		// convert to level 3 in necessary
		if (model.getLevel() == BioPAXLevel.L2)
			l3Model = (new LevelUpgrader()).filter(model);
		else
			l3Model = model;
		
		//a modifiable copy of the set of all PRs in the model - 
		//after all, it has all the PRs that do not belong to any pathway
		final Set<SequenceEntityReference> sequenceEntityReferences =
				new HashSet<SequenceEntityReference>(l3Model.getObjects(SequenceEntityReference.class));

		final Set<Pathway> pathways = l3Model.getObjects(Pathway.class);
		for (Pathway pathway : pathways) 
		{
			String name = (pathway.getDisplayName() == null) ? pathway.getStandardName() : pathway.getDisplayName();
			if(name == null || name.isEmpty()) 
				name = pathway.getUri();

			final Pathway currentPathway = pathway;
			final String currentPathwayName = name;

			final boolean ignoreSubPathways =
				(!skipSubPathwaysOf.isEmpty() && shareSomeObjects(currentPathway.getDataSource(), skipSubPathwaysOf))
					|| skipSubPathways;

			LOG.debug("Begin converting " + currentPathwayName + " pathway, uri=" + currentPathway.getUri());

			// collect sequence entity references from current pathway
			//TODO: add Fetcher.evidenceFilter?
			Fetcher fetcher = new Fetcher(SimpleEditorMap.L3, Fetcher.nextStepFilter);
			fetcher.setSkipSubPathways(ignoreSubPathways);
			Set<SequenceEntityReference> pathwaySers = fetcher.fetch(currentPathway, SequenceEntityReference.class);

			if(!pathwaySers.isEmpty()) {
				LOG.debug("For pathway: " + currentPathwayName + " (" + currentPathway.getUri()
						+ "), got " + pathwaySers.size() + " sERs; now - grouping by organism...");
				Map<String,Set<SequenceEntityReference>> orgToPrsMap = organismToProteinRefsMap(pathwaySers);
				// create GSEA/GMT entries - one entry per organism (null organism also makes one)
				String dataSource = getDataSource(currentPathway.getDataSource());
				Collection<GMTEntry> entries = createGseaEntries(currentPathway.getUri(),
						currentPathwayName, dataSource, orgToPrsMap);
				if(!entries.isEmpty())
					toReturn.addAll(entries);
				sequenceEntityReferences.removeAll(pathwaySers);//keep not processed PRs (a PR can be processed multiple times)
				LOG.debug("- collected " + entries.size() + "entries.");
			}
		}
		
		//when there're no pathways, only empty pathays, pathways w/o PRs, then use all/rest of PRs -
		//organize PRs by species (GSEA s/w can handle only same species identifiers in a data row)
		if(!sequenceEntityReferences.isEmpty() && !skipOutsidePathways) {
			LOG.info("Creating entries for the rest of PRs (outside any pathway)...");
			Map<String,Set<SequenceEntityReference>> orgToPrsMap = organismToProteinRefsMap(sequenceEntityReferences);
			if(!orgToPrsMap.isEmpty()) {
				// create GSEA/GMT entries - one entry per organism (null organism also makes one)
				if(model.getUri()==null) {
					toReturn.addAll(createGseaEntries(
						"other", "other", getDataSource(l3Model.getObjects(Provenance.class)), orgToPrsMap));
				} else {
					toReturn.addAll(createGseaEntries(model.getUri()
						, model.getName(), getDataSource(l3Model.getObjects(Provenance.class)), orgToPrsMap));
				}
			}
		}
					
		return toReturn;
	}
1308801
protected Label newRootLabel(final String forId, final IModel<String> model) {
		return ComponentFactory.newLabel("rootLabel", forId, model);
	}
568074
public void updateModel(@NonNull Model model) {
        if (zoo != null) {
            for (val w: zoo)
                w.updateModel(model);
        } else {
            // if zoo wasn't initalized yet - just replace model
            this.model = model;
        }
    }
726142
public final void setModel(PixelModel newModel) {
		if (newModel == null) throw new NullPointerException();
		
		if (model != newModel) {
			if (model != null)
				model.removeChangeListener(modelListener);
			model = newModel;
			model.addChangeListener(modelListener);
			update();
		}
	}
410772
public static List<Match> searchPlain(Model model, Pattern pattern)
	{
		List<Match> list = new LinkedList<Match>();

		Map<BioPAXElement, List<Match>> map = search(model, pattern);
		for (List<Match> matches : map.values())
		{
			list.addAll(matches);
		}
		return list;
	}
174937
public void put(DajlabModelInterface model) {
		if (model != null) {
			String name = model.getClass().getName();
			dajlab.put(name, model);
		}
	}
1202315
public List<Triple> getSortedTriples(final Model model, final Iterator<Triple> it) {
        final List<Triple> triples = newArrayList(it);
        triples.sort(new TripleOrdering(model));
        return triples;
    }
295289
public <S extends Model> ResultKey save(S model) {
        List<Object> columnValues = AnimaUtils.toColumnValues(model, true);
        String       sql          = this.buildInsertSQL(model, columnValues);
        Connection   conn         = getConn();
        try {

            List<Object> params = columnValues.stream()
                    .filter(Objects::nonNull)
                    .collect(toList());

            return new ResultKey(conn.createQuery(sql)
                    .withParams(params)
                    .executeUpdate()
                    .getKey());
        } finally {
            this.closeConn(conn);
            this.clean(conn);
        }
    }
1249395
@Override public DeepLearningModel createImpl() {
    DeepLearningModel.DeepLearningParameters parms = parameters.createImpl();
    return new DeepLearningModel(Key.make() /*dest*/, parms, new DeepLearningModel.DeepLearningModelOutput(null), null, null, 0);
  }
854709
private static void convert(unificationXref uni, Model level2)
	{
		//We can not simply convert a class, so we need to remove the
        //uni and insert a new relationship xref

        //First get all the objects that refers to this uni
        Set<XReferrable> referrables =
			new HashSet<XReferrable>(uni.isXREFof());

        //Create the new relationship xref in the model.
        relationshipXref relationshipXref =
        	level2.addNew(relationshipXref.class, uni.getUri());

        //Copy the fields from uni
		relationshipXref.setCOMMENT(uni.getCOMMENT());
		relationshipXref.setDB(uni.getDB());
		relationshipXref.setDB_VERSION(uni.getDB_VERSION());
		relationshipXref.setID(uni.getID());
		relationshipXref.setID_VERSION(uni.getID_VERSION());
		relationshipXref.setRELATIONSHIP_TYPE(
			"http://www.biopax.org/paxtools/convertedGOUnificationXREF");

        //Create a link to the new xref from all the owners.
        for (XReferrable referrable : referrables)
		{
			referrable.addXREF(relationshipXref);
		}

        //Remove the references to the old uni
        for (XReferrable referrable : referrables)
        {
            referrable.removeXREF(uni);
        }
        //Now remove it from the model.
        level2.remove(uni);

        //We are done!
    }
508740
public synchronized void replaceModel (MaxentModel model) {
	replacementThread = Thread.currentThread();
	while (!replacementCanProceed) Thread.yield();
	setter.setModel(model);
	replacementThread = null;
    }
1067479
public List<EDBObject> convertModelToEDBObject(Object model, ConnectorInformation info) {
        if (!OpenEngSBModel.class.isAssignableFrom(model.getClass())) {
            throw new IllegalArgumentException("This function need to get a model passed");
        }
        List<EDBObject> objects = new ArrayList<>();
        if (model != null) {
            convertSubModel((OpenEngSBModel) model, objects, info);
        }
        return objects;
    }
164187
public function newModelStateSuccess(ModelInterface $model, $processName, $stepName, $previous = null)
    {
        $modelState = $this->createModelState($model, $processName, $stepName, $previous);
        $modelState->setSuccessful(true);

        $this->om->persist($modelState);
        $this->om->flush($modelState);

        return $modelState;
    }
226371
public static IModel<String> newResourceModel(final ResourceBundleKey resourceBundleKey,
		final IModel<?> model)
	{
		IModel<String> resourceModel;
		resourceModel = newResourceModel(resourceBundleKey.getKey(), null, model, 
				resourceBundleKey.getDefaultValue(), resourceBundleKey.getParameters());
		return resourceModel;
	}
181520
public GuidedDecisionTable52 upgrade(GuidedDecisionTable legacyDTModel) {

        assertConditionColumnPatternGrouping(legacyDTModel);

        GuidedDecisionTable52 newDTModel = new GuidedDecisionTable52();

        newDTModel.setTableFormat(GuidedDecisionTable52.TableFormat.EXTENDED_ENTRY);

        newDTModel.setTableName(legacyDTModel.tableName);
        newDTModel.setParentName(legacyDTModel.parentName);

        newDTModel.setRowNumberCol(new RowNumberCol52());
        newDTModel.setDescriptionCol(new DescriptionCol52());

        //Metadata columns' data-type is implicitly defined in the metadata value. For example
        //a String metadata attribute is: "value", a numerical: 1. No conversion action required
        if (legacyDTModel.metadataCols != null) {
            for (MetadataCol c : legacyDTModel.metadataCols) {
                newDTModel.getMetadataCols().add(makeNewColumn(c));
            }
        }

        //Attribute columns' data-type is based upon the attribute name
        if (legacyDTModel.attributeCols != null) {
            for (AttributeCol c : legacyDTModel.attributeCols) {
                newDTModel.getAttributeCols().add(makeNewColumn(c));
            }
        }

        //Legacy decision tables did not have Condition field data-types. Set all Condition 
        //fields to a *sensible* default of String (as this matches legacy behaviour).
        List<Pattern52> patterns = new ArrayList<Pattern52>();
        Map<String, Pattern52> uniquePatterns = new HashMap<String, Pattern52>();
        if (legacyDTModel.conditionCols != null) {
            for (int i = 0; i < legacyDTModel.conditionCols.size(); i++) {
                ConditionCol c = legacyDTModel.conditionCols.get(i);
                String boundName = c.boundName;
                Pattern52 p = uniquePatterns.get(boundName);
                if (p == null) {
                    p = new Pattern52();
                    p.setBoundName(boundName);
                    p.setFactType(c.factType);
                    patterns.add(p);
                    uniquePatterns.put(boundName,
                                       p);
                }
                if (p.getFactType() != null && !p.getFactType().equals(c.factType)) {
                    throw new IllegalArgumentException("Inconsistent FactTypes for ConditionCols bound to '" + boundName + "' detected.");
                }
                p.getChildColumns().add(makeNewColumn(c));
            }
            for (Pattern52 p : patterns) {
                newDTModel.getConditions().add(p);
            }
        }

        //Action columns have a discrete data-type. No conversion action required.
        if (legacyDTModel.actionCols != null) {
            for (ActionCol c : legacyDTModel.actionCols) {
                newDTModel.getActionCols().add(makeNewColumn(c));
            }
        }

        //Copy across data
        newDTModel.setData(DataUtilities.makeDataLists(legacyDTModel.data));

        //Copy the boundName for ActionRetractFactCol into the data of the new Guided Decision Table model
        if (legacyDTModel.actionCols != null) {
            final int metaDataColCount = (legacyDTModel.metadataCols == null ? 0 : legacyDTModel.metadataCols.size());
            final int attributeColCount = (legacyDTModel.attributeCols == null ? 0 : legacyDTModel.attributeCols.size());
            final int conditionColCount = (legacyDTModel.conditionCols == null ? 0 : legacyDTModel.conditionCols.size());
            final int DATA_COLUMN_OFFSET = metaDataColCount + attributeColCount + conditionColCount + GuidedDecisionTable.INTERNAL_ELEMENTS;
            for (int iCol = 0; iCol < legacyDTModel.actionCols.size(); iCol++) {
                ActionCol lc = legacyDTModel.actionCols.get(iCol);
                if (lc instanceof ActionRetractFactCol) {
                    String boundName = ((ActionRetractFactCol) lc).boundName;
                    for (List<DTCellValue52> row : newDTModel.getData()) {
                        row.get(DATA_COLUMN_OFFSET + iCol).setStringValue(boundName);
                    }
                }
            }
        }

        return newDTModel;
    }
1109053
public function bulkSerialise($model)
    {
        $class = get_class($model);
        if (!$model instanceof Model) {
            throw new InvalidOperationException($class);
        }
        // dig up metadata
        if (!isset(self::$metadataCache[$class])) {
            self::$metadataCache[$class] = $model->metadata();
        }
        $meta = self::$metadataCache[$class];
        $keys = array_keys($meta);
        // dig up getter list - we only care about the mutators that end up in metadata
        if (!isset(self::$mutatorCache[$class])) {
            $getterz = [];
            $datez = $model->getDates();
            $castz = $model->retrieveCasts();
            foreach ($keys as $key) {
                if ($model->hasGetMutator($key) || in_array($key, $datez) || array_key_exists($key, $castz)) {
                    $getterz[] = $key;
                }
            }
            self::$mutatorCache[$class] = $getterz;
        }
        $getterz = self::$mutatorCache[$class];
        $modelAttrib = $model->getAttributes();
        $result = array_intersect_key($modelAttrib, $meta);
        foreach ($keys as $key) {
            if (!isset($result[$key])) {
                $result[$key] = null;
            }
        }
        foreach ($getterz as $getter) {
            $result[$getter] = $model->$getter;
        }

        return $result;
    }