From: jprocter Date: Wed, 25 Apr 2007 11:52:32 +0000 (+0000) Subject: Functions for parsing free text properties on sequences, alignments and annotations. X-Git-Tag: Release_2_3~180 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=1c6e3aa5ffd0d3fbbfe5bffbdeaa9c4f54a61cd3;p=jalview.git Functions for parsing free text properties on sequences, alignments and annotations. --- diff --git a/src/jalview/analysis/ParseProperties.java b/src/jalview/analysis/ParseProperties.java new file mode 100644 index 0000000..015fcfe --- /dev/null +++ b/src/jalview/analysis/ParseProperties.java @@ -0,0 +1,116 @@ +package jalview.analysis; + +import com.stevesoft.pat.Regex; + +import jalview.datamodel.*; + +public class ParseProperties +{ + /** + * Methods for parsing free text properties on alignments and sequences. + */ + /** + * The alignment being operated on + */ + private AlignmentI al=null; + + /** + * initialise a new property parser + * @param al + */ + ParseProperties(AlignmentI al) { + this.al = al; + } + + public int getScoresFromDescription(String ScoreName, String ScoreDescriptions, String regex) + { + return getScoresFromDescription(new String[] { ScoreName }, new String[] { ScoreDescriptions}, regex); + } + + public int getScoresFromDescription(String[] ScoreNames, String[] ScoreDescriptions, String regex) + { + return getScoresFromDescription(al.getSequencesArray(), ScoreNames, ScoreDescriptions, regex); + } + /** + * Extract scores for sequences by applying regex to description string. + * @param seqs seuqences to extract annotation from. + * @param ScoreNames labels for each numeric field in regex match + * @param ScoreDescriptions description for each numeric field in regex match + * @param regex Regular Expression string for passing to new com.stevesoft.patt.Regex(regex) + * @return total number of sequences that matched the regex + */ + public int getScoresFromDescription(SequenceI[] seqs, String[] ScoreNames, String[] ScoreDescriptions, String regex) + { + int count=0; + Regex pattern = new Regex(regex); + if (pattern.numSubs()>ScoreNames.length) + { + // Check that we have enough labels and descriptions for any parsed scores. + int onamelen = ScoreNames.length; + String[] tnames = new String[pattern.numSubs()+1]; + System.arraycopy(ScoreNames, 0, tnames, 0, ScoreNames.length); + String base = tnames[ScoreNames.length-1]; + ScoreNames = tnames; + String descrbase = ScoreDescriptions[ScoreNames.length-1]; + if (descrbase == null) + descrbase = "Score parsed from ("+regex+")"; + tnames = new String[pattern.numSubs()]; + System.arraycopy(ScoreDescriptions, 0, tnames, 0, ScoreDescriptions.length); + ScoreDescriptions = tnames; + for (int i=onamelen; i