From aab514f0d55b43f9f4f5154e3e34103c1b41becc Mon Sep 17 00:00:00 2001 From: jprocter Date: Thu, 8 Mar 2007 14:07:22 +0000 Subject: [PATCH] utility functions for dealing with Range and Properties elements. git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@353 be28352e-c001-0410-b1a7-c7978e42abec --- src/uk/ac/vamsas/objects/utils/Properties.java | 21 ++++ src/uk/ac/vamsas/objects/utils/Range.java | 146 ++++++++++++++++++++++++ 2 files changed, 167 insertions(+) create mode 100644 src/uk/ac/vamsas/objects/utils/Properties.java create mode 100644 src/uk/ac/vamsas/objects/utils/Range.java diff --git a/src/uk/ac/vamsas/objects/utils/Properties.java b/src/uk/ac/vamsas/objects/utils/Properties.java new file mode 100644 index 0000000..491a781 --- /dev/null +++ b/src/uk/ac/vamsas/objects/utils/Properties.java @@ -0,0 +1,21 @@ +package uk.ac.vamsas.objects.utils; + +import uk.ac.vamsas.objects.core.Property; + +public class Properties { + public static Property newProperty(String name, String type, String content) + { + Property vProperty = new Property(); + vProperty.setName(name); + if (type != null) + { + vProperty.setType(type); + } + else + { + vProperty.setType("String"); + } + vProperty.setContent(content); + return vProperty; + } +} diff --git a/src/uk/ac/vamsas/objects/utils/Range.java b/src/uk/ac/vamsas/objects/utils/Range.java new file mode 100644 index 0000000..b20cb5b --- /dev/null +++ b/src/uk/ac/vamsas/objects/utils/Range.java @@ -0,0 +1,146 @@ +package uk.ac.vamsas.objects.utils; + +import java.util.Vector; + + +import uk.ac.vamsas.objects.core.RangeType; +import uk.ac.vamsas.objects.core.Seg; + +public class Range { + + /** + * get start 0 && dseta.getPosCount() > 0) + { + throw new Error("Invalid vamsas RangeType - cannot resolve both lists of Pos and Seg from choice!"); + } + if (dseta.getSegCount() > 0) + { + se = getSegRange(dseta.getSeg(0), true); + for (int s = 1, sSize = dseta.getSegCount(); s < sSize; s++) + { + int nse[] = getSegRange(dseta.getSeg(s), true); + if (se[0] > nse[0]) + { + se[0] = nse[0]; + } + if (se[1] < nse[1]) + { + se[1] = nse[1]; + } + } + } + if (dseta.getPosCount() > 0) + { + // could do a polarity for pos range too. and pass back indication of discontinuities. + int pos = dseta.getPos(0).getI(); + se = new int[] + { + pos, pos}; + for (int p = 0, pSize = dseta.getPosCount(); p < pSize; p++) + { + pos = dseta.getPos(p).getI(); + if (se[0] > pos) + { + se[0] = pos; + } + if (se[1] < pos) + { + se[1] = pos; + } + } + } + return se; + } + return null; + } + + /** + * map from a rangeType's internal frame to the referenced object's coordinate frame. + * @param dseta + * @return int [] { ref(pos)...} for all pos in rangeType's frame. + */ + public static int[] getMapping(RangeType dseta) + { + Vector posList = new Vector(); + if (dseta != null) + { + int[] se = null; + if (dseta.getSegCount() > 0 && dseta.getPosCount() > 0) + { + throw new Error("Invalid vamsas RangeType - cannot resolve both lists of Pos and Seg from choice!"); + } + if (dseta.getSegCount() > 0) + { + for (int s = 0, sSize = dseta.getSegCount(); s < sSize; s++) + { + se = getSegRange(dseta.getSeg(s), false); + int se_end = se[1 - se[2]] + (se[2] == 0 ? 1 : -1); + for (int p = se[se[2]]; p != se_end; p += se[2] == 0 ? 1 : -1) + { + posList.add(new Integer(p)); + } + } + } + else if (dseta.getPosCount() > 0) + { + int pos = dseta.getPos(0).getI(); + + for (int p = 0, pSize = dseta.getPosCount(); p < pSize; p++) + { + pos = dseta.getPos(p).getI(); + posList.add(new Integer(pos)); + } + } + } + if (posList != null && posList.size() > 0) + { + int[] range = new int[posList.size()]; + for (int i = 0; i < range.length; i++) + { + range[i] = ( (Integer) posList.elementAt(i)).intValue(); + } + posList.clear(); + return range; + } + return null; + } +} -- 1.7.10.2