package org.java.evolutionary.sequence.func; import org.biojava.bio.symbol.SymbolList; import org.biojava.utils.regex.Matcher; import org.biojava.utils.regex.Pattern; import org.biojava.utils.regex.PatternFactory; import ec.EvolutionState; import ec.Problem; import org.java.evolutionary.sequence.MotifData; import org.java.evolutionary.sequence.SequenceClassificationProblem; import ec.gp.ADFStack; import ec.gp.GPData; import ec.gp.GPIndividual; import ec.gp.GPNode; import ec.util.Parameter; /** * This function or non-terminal is used for Compositional Based matching, i.e indepndent of position * testing for compositions like AGGG anywhere in the sequence. * @author udaykamath * */ public class Compositional extends GPNode{ public String toString() { return " matches "; } public void checkConstraints(final EvolutionState state, final int tree, final GPIndividual typicalIndividual, final Parameter individualBase) { super.checkConstraints(state, tree, typicalIndividual, individualBase); if (children.length != 1) state.output.error("Incorrect number of children for node " + toStringForError() + " at " + individualBase); } public void eval(final EvolutionState state, final int thread, final GPData input, final ADFStack stack, final GPIndividual individual, final Problem problem) { MotifData motifData = ((MotifData) (input)); //child should give me motif children[0].eval(state, thread, input, stack, individual, problem); //get the curernt motif char[] currentMotif = motifData.currentMotif; //check for match using biojava SequenceClassificationProblem spliceSetProblem =(SequenceClassificationProblem)problem; SymbolList sequence = spliceSetProblem.getCurrentSequence(); PatternFactory factory = spliceSetProblem.getFactory(thread); motifData.matches = matches(sequence,currentMotif, factory); } private boolean matches(SymbolList seq, char[] currentMotif, PatternFactory factory){ boolean matched = false; try{ //in the sequence find the match Pattern p = factory.compile(new String(currentMotif)); Matcher occurences= p.matcher(seq); while(occurences.find()){ matched = true; break; } }catch(Exception e){ e.printStackTrace(); } return matched; } }