From d6f378ff4d767169376e6f2489a00b75d8a36e39 Mon Sep 17 00:00:00 2001 From: jprocter Date: Thu, 28 Jun 2007 20:12:32 +0000 Subject: [PATCH] added mapType utilities. git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@421 be28352e-c001-0410-b1a7-c7978e42abec --- src/uk/ac/vamsas/objects/utils/Range.java | 140 ++++++++++++++++++++++++++++- 1 file changed, 139 insertions(+), 1 deletion(-) diff --git a/src/uk/ac/vamsas/objects/utils/Range.java b/src/uk/ac/vamsas/objects/utils/Range.java index b20cb5b..f66df31 100644 --- a/src/uk/ac/vamsas/objects/utils/Range.java +++ b/src/uk/ac/vamsas/objects/utils/Range.java @@ -2,10 +2,18 @@ package uk.ac.vamsas.objects.utils; import java.util.Vector; - +import uk.ac.vamsas.objects.core.Local; +import uk.ac.vamsas.objects.core.MapType; +import uk.ac.vamsas.objects.core.Mapped; import uk.ac.vamsas.objects.core.RangeType; import uk.ac.vamsas.objects.core.Seg; +/** + * Utilities for working with RangeType and MapType objects. + * Derived from bitter experience. + * @author JimP + * + */ public class Range { /** @@ -143,4 +151,134 @@ public class Range { } return null; } + + public static int[] getIntervals(RangeType range) + { + int[] intervals=null; + Vector posList = new Vector(); + if (range != null) + { + int[] se = null; + if (range.getSegCount() > 0 && range.getPosCount() > 0) + { + throw new Error("Invalid vamsas RangeType - cannot resolve both lists of Pos and Seg from choice!"); } + if (range.getSegCount() > 0) + { + for (int s = 0, sSize = range.getSegCount(); s < sSize; s++) + { + se = getSegRange(range.getSeg(s), false); + posList.addElement(new Integer(se[0])); + posList.addElement(new Integer(se[1])); + } + } + else if (range.getPosCount() > 0) + { + int pos = range.getPos(0).getI(); + for (int p = 0, pSize = range.getPosCount(); p < pSize; p++) + { + pos = range.getPos(p).getI(); + posList.add(new Integer(pos)); + posList.add(new Integer(pos)); + } + } + } + if (posList != null && posList.size() > 0) + { + intervals=new int[posList.size()]; + java.util.Enumeration e = posList.elements(); + int i=0; + while (e.hasMoreElements()) + { + intervals[i++] = ((Integer)e.nextElement()).intValue(); + } + } + return intervals; + } + /** + * initialise a range type object from a set of start/end inclusive intervals + * @param mrt + * @param range + */ + public static void initRangeType(RangeType mrt, int[] range) + { + for (int i=0; i