<commit_before>/*******************************************************************************
 * Copyright 2016 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *******************************************************************************/
package org.sbml.layoutconverter;

import java.util.List;

import org.sbml._2001.ns.celldesigner.Gene;
import org.sbml.jsbml.ListOf;
import org.sbml.jsbml.Model;
import org.sbml.jsbml.Reaction;
import org.sbml.jsbml.Species;
import org.sbml.jsbml.ext.fbc.FBCConstants;
import org.sbml.jsbml.ext.fbc.FBCModelPlugin;
import org.sbml.jsbml.ext.fbc.FBCReactionPlugin;
import org.sbml.jsbml.ext.fbc.FBCSpeciesPlugin;
import org.sbml.jsbml.ext.fbc.GeneProduct;
import org.sbml.wrapper.ModelWrapper;
import org.sbml.wrapper.SpeciesWrapper;

// TODO: Auto-generated Javadoc
/**
 * The Class FBCConverter.
 *
 * @author <NAME>
 * 
 * Date Created: Aug 6, 2016
 */

public class FBCConverter {
	
	/** The model. */
	private Model model;
	
	/** The m wrapper. */
	private ModelWrapper mWrapper;
	
	/** The fbc plugin. */
	private FBCModelPlugin fbcPlugin;
	
	/**
	 * Instantiates a new FBC converter.
	 *
	 * @param model the model
	 * @param mWrapper the m wrapper
	 */
	public FBCConverter(Model model, ModelWrapper mWrapper) {
		this.model = model;
		this.mWrapper = mWrapper;
	}
	
	/**
	 * Convert.
	 */
	public void convert(){
		convertModel();
		convertSpecies();
		convertReactions();
	}

	/**
	 * Convert model.
	 */
	public void convertModel(){
		fbcPlugin = (FBCModelPlugin) model.getPlugin(FBCConstants.shortLabel);
		fbcPlugin.setStrict(false);
	}
	
	/**
	 * Convert species.
	 */
	public void convertSpecies(){
		List<SpeciesWrapper> swList = mWrapper.getListOfSpeciesWrapper();

		for(SpeciesWrapper sw : swList){
			if(sw.getCharge() != null){
				Species s = model.getSpecies(sw.getId());
				FBCSpeciesPlugin speciesPlugin = (FBCSpeciesPlugin) s.getPlugin(FBCConstants.shortLabel);
				speciesPlugin.setCharge(sw.getCharge().intValue());
			}
	
			if(sw.getClazz().equals("GENE")){
				Gene gene = mWrapper.getGeneBySpeciesId(sw.getId());
				GeneProduct geneProduct = fbcPlugin.createGeneProduct(gene.getId());
				geneProduct.setLabel(gene.getType() + "_" + gene.getId());
				geneProduct.setAssociatedSpecies(sw.getId());
			}
		}
		
	}

	
	/**
	 * Convert reactions.
	 */
	public void convertReactions(){
		ListOf<Reaction> lor = model.getListOfReactions();
		for(Reaction reaction : lor){
			FBCReactionPlugin reactionPlugin = (FBCReactionPlugin) reaction.getPlugin(FBCConstants.shortLabel);
		}
	}
	
}
<commit_msg>added conversion for simple fbc reaction<commit_after>/*******************************************************************************
 * Copyright 2016 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *******************************************************************************/
package org.sbml.layoutconverter;

import java.util.List;

import org.sbml._2001.ns.celldesigner.Gene;
import org.sbml._2001.ns.celldesigner.Modification;
import org.sbml.jsbml.Model;
import org.sbml.jsbml.Reaction;
import org.sbml.jsbml.Species;
import org.sbml.jsbml.ext.fbc.And;
import org.sbml.jsbml.ext.fbc.FBCConstants;
import org.sbml.jsbml.ext.fbc.FBCModelPlugin;
import org.sbml.jsbml.ext.fbc.FBCReactionPlugin;
import org.sbml.jsbml.ext.fbc.FBCSpeciesPlugin;
import org.sbml.jsbml.ext.fbc.GeneProduct;
import org.sbml.jsbml.ext.fbc.GeneProductAssociation;
import org.sbml.jsbml.ext.fbc.GeneProductRef;
import org.sbml.jsbml.ext.fbc.LogicalOperator;
import org.sbml.jsbml.ext.fbc.Or;
import org.sbml.wrapper.ModelWrapper;
import org.sbml.wrapper.ReactionWrapper;
import org.sbml.wrapper.SpeciesWrapper;

// TODO: Auto-generated Javadoc
/**
 * The Class FBCConverter.
 *
 * @author <NAME>
 * 
 * Date Created: Aug 6, 2016
 */

public class FBCConverter {
	
	/** The model. */
	private Model model;
	
	/** The m wrapper. */
	private ModelWrapper mWrapper;
	
	/** The fbc plugin. */
	private FBCModelPlugin fbcPlugin;
	
	/**
	 * Instantiates a new FBC converter.
	 *
	 * @param model the model
	 * @param mWrapper the m wrapper
	 */
	public FBCConverter(Model model, ModelWrapper mWrapper) {
		this.model = model;
		this.mWrapper = mWrapper;
	}
	
	/**
	 * Convert.
	 */
	public void convert(){
		convertModel();
		convertSpecies();
		convertReactions();
	}

	/**
	 * Convert model.
	 */
	public void convertModel(){
		fbcPlugin = (FBCModelPlugin) model.getPlugin(FBCConstants.shortLabel);
		fbcPlugin.setStrict(false);
	}
	
	/**
	 * Convert species.
	 */
	public void convertSpecies(){
		List<SpeciesWrapper> swList = mWrapper.getListOfSpeciesWrapper();
		for(SpeciesWrapper sw : swList){
			if(sw.getCharge() != null){
				Species s = model.getSpecies(sw.getId());
				FBCSpeciesPlugin speciesPlugin = (FBCSpeciesPlugin) s.getPlugin(FBCConstants.shortLabel);
				speciesPlugin.setCharge(sw.getCharge().intValue());
			}
		}
		
	}
	
	/**
	 * Convert reactions.
	 */
	public void convertReactions(){
		List<ReactionWrapper> rwList = mWrapper.getListOfReactionWrapper();
		for(ReactionWrapper rw : rwList){
			List<Modification> mList = rw.getListOfModification();
			for(Modification modification : mList){
				if(modification.getType().contains("BOOLEAN_LOGIC_GATE")){
					Reaction reaction = model.getReaction(rw.getId());
					FBCReactionPlugin reactionPlugin = (FBCReactionPlugin) reaction.getPlugin(FBCConstants.shortLabel);
					GeneProductAssociation  gpa;
					if(reactionPlugin.isSetGeneProductAssociation())
						gpa = reactionPlugin.getGeneProductAssociation();
					else
						gpa = reactionPlugin.createGeneProductAssociation("ga_" + rw.getId());
					
					String modifiers = modification.getModifiers();
					String[] modifierList = modifiers.split(",");
					for(String m : modifierList){
						if(fbcPlugin.getListOfGeneProducts().get(m) == null){
							GeneProduct geneProduct = fbcPlugin.createGeneProduct("gene_" + m);
							geneProduct.setLabel(m);
							geneProduct.setAssociatedSpecies(m);
						}
					}
					
					LogicalOperator lo;
					if(modification.getType().contains("AND")){
						lo = setAllProductRef(new And(), modifierList);
					} else {
						lo = setAllProductRef(new Or(), modifierList);
					}
					gpa.setAssociation(lo);		
				}
			}
		}
	}
	
	/**
	 * Sets the all product ref.
	 *
	 * @param lo the lo
	 * @param modifiers the modifiers
	 * @return the logical operator
	 */
	public LogicalOperator setAllProductRef(LogicalOperator lo, String[] modifiers){
		for(String modifier : modifiers){
				GeneProductRef gpr = lo.createGeneProductRef("GeneProductRef_" + modifier);
				gpr.setGeneProduct("gene_" + modifier);
		}
		
		return lo;
	}	
}

{'fraction_non_alphanumeric': 0.1553675992192583, 'fraction_numerical': 0.00494469746258946, 'mean_word_length': 4.073267326732673, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '817183', 'n_tokens_mistral': 2753, 'n_tokens_neox': 2381, 'n_words': 546}