示例#1
0
 def test_get_coord(self):
     """MagePoint _get_coord should return coordinate that is asked for"""
     m = MagePoint([0, 1, 2])
     self.assertEqual(m.X, m.Coordinates[0])
     self.assertEqual(m.Y, m.Coordinates[1])
     self.assertEqual(m.Z, m.Coordinates[2])
     m = MagePoint()
     self.assertEqual(m.X, m.Coordinates[0])
     self.assertEqual(m.Y, m.Coordinates[1])
     self.assertEqual(m.Z, m.Coordinates[2])
示例#2
0
 def setUp(self):
     """Define a few standard points and lists of points."""
     self.null = MagePoint([0, 0, 0])
     self.label = MagePoint([1, 1, 1], 'test')
     self.properties = MagePoint(Width=1, Label='point', State='L',\
         Color='blue', Coordinates=[2.0,4.0,6.0])
     self.radius1 = MagePoint([2, 2, 2], Radius=.1)
     self.radius2 = MagePoint([3, 3, 3], Radius=.5)
     self.first_list = [self.null, self.properties]
     self.empty_list = []
     self.minimal_list = [self.null]
     self.single_list = [self.label]
     self.multi_list = [self.properties] * 10
     self.radii = [self.radius1, self.radius2]
示例#3
0
 def test_set_coord(self):
     """MagePoint _get_coord should return coordinate that is asked for"""
     m = MagePoint([0, 1, 2])
     m.X, m.Y, m.Z = 2, 3, 4
     self.assertEqual(m.Coordinates, [2, 3, 4])
     m = MagePoint()
     m.X, m.Y, m.Z = 5, 4, 3
     self.assertEqual(m.Coordinates, [5, 4, 3])
     m = MagePoint()
     m.X = 5
     self.assertEqual(m.Coordinates, [5, 0, 0])
示例#4
0
 def setUp(self):
     self.point = MagePoint([0, 0, 0], 'x')
     self.ml = MageList([self.point], Label='y', Color='green')
     self.mg1 = MageGroup([self.ml], Label='z')
     self.mg2 = MageGroup([self.ml, self.ml], Label='b')
     self.kin = Kinemage(1)
     self.kin.Groups = [self.mg1, self.mg2]
示例#5
0
 def test_fromCartesian(self):
     """MageList fromCartesian() should return new list with ACG coordinates
     """
     point = MagePoint([.1, .2, .3])
     m = MageList([point] * 5, Color='green')
     res = m.toCartesian().fromCartesian()
     self.assertEqual(str(m), str(res))
示例#6
0
 def test_init(self):
     """MagePoint should init correctly with normal cases"""
     #label and coords
     m = MagePoint([0.200, 0.000, 0.800], '0.800')
     self.assertEqual(str(m), '{0.800} ' + \
         ' '.join(map(str, ([0.200,0.000,0.800]))))
     #coords only
     m = MagePoint([0.200, 0.000, 0.800])
     self.assertEqual(str(m), ' '.join(map(str, ([0.200, 0.000, 0.800]))))
     #label only
     m = MagePoint(Label='abc')
     self.assertEqual(str(m), '{abc} ' + ' '.join(map(str, [0, 0, 0])))
     #all fields occupied
     m = MagePoint(Label='abc', Coordinates=[3, 6, 1.5], Radius=0.5, \
         Width=2, State='P', Color='green')
     self.assertEqual(str(m), \
     '{abc} P green width2 r=0.5 3 6 1.5')
示例#7
0
 def test_fromCartesian(self):
     """MageGroup fromCartesian should return a new MageGroup"""
     point = MagePoint([.1, .2, .3])
     l = MageList([point] * 5, Color='red')
     m = MageGroup([l], Radius=0.02, Subgroup=True)
     mg = MageGroup([m])
     res = mg.toCartesian().fromCartesian()
     self.assertEqual(str(mg), str(res))
示例#8
0
    def test_fromCartesian(self):
        """MagePoint fromCartesian should transform coordinates correctly"""
        mp = MagePoint([2/3.0,1/3.0,2/3.0])
        self.assertFloatEqual(mp.fromCartesian().Coordinates,[1/3.0,1/3.0,0])
        points = [MagePoint([.1,.2,.3]),MagePoint([.25,.25,.25],Color='red',
                Label='label',State='L'),MagePoint([1/3,1/3,0]),
                MagePoint([0,0,0]),MagePoint([1/7,2/7,3/7])]
        for m in points:
            b = m.toCartesian().fromCartesian()
            self.assertFloatEqual(m.Coordinates,b.Coordinates)
            self.assertEqual(m.Color,b.Color)
            self.assertEqual(m.Label,b.Label)
            self.assertEqual(m.State,b.State)

            #even after multiple iterations?
            mutant = deepcopy(m)
            for x in range(10):
                mutant = mutant.toCartesian().fromCartesian()
            self.assertFloatEqual(m.Coordinates,mutant.Coordinates)
示例#9
0
 def test_fromCartesian(self):
     """Kinemage fromCartesian should return Kinemage with A,C,G(,U) coords
     """
     point = MagePoint([.1, .2, .3])
     l = MageList([point] * 5, Color='red')
     m1 = MageGroup([l], Radius=0.02, Subgroup=True)
     m2 = MageGroup([l], Radius=0.02)
     mg = MageGroup([m1])
     k = Kinemage(Count=1, Groups=[mg, m2])
     res = k.toCartesian().fromCartesian()
     self.assertEqual(str(k), str(res))
示例#10
0
 def setUp(self):
     """Define some standard lists and groups."""
     self.p1 = MagePoint([0, 1, 0], Color='green', Label='x')
     self.p0 = MagePoint([0, 0, 0])
     self.min_list = MageList([self.p0] * 2, 'y')
     self.max_list = MageList([self.p1]*5,'z',Color='blue',Off=True, \
         Style='ball')
     self.min_group = MageGroup([self.min_list], Label="min_group")
     self.max_group = MageGroup([self.min_list, self.max_list],
                                Color='red',
                                Label="max_group",
                                Style='dot')
     self.nested = MageGroup([self.min_group, self.max_group],
                             Label='nest',
                             Color='orange',
                             Radius=0.3,
                             Style='vector')
     self.empty = MageGroup(Label='empty',
                            Color='orange',
                            NoButton=True,
                            Style='vector',
                            RecessiveOn=False)
示例#11
0
 def test_set_coord(self):
     """MagePoint _get_coord should return coordinate that is asked for"""
     m = MagePoint([0,1,2])
     m.X, m.Y, m.Z = 2,3,4
     self.assertEqual(m.Coordinates,[2,3,4])
     m = MagePoint()
     m.X, m.Y, m.Z = 5,4,3
     self.assertEqual(m.Coordinates,[5,4,3])
     m = MagePoint()
     m.X = 5
     self.assertEqual(m.Coordinates,[5,0,0])
示例#12
0
    def test_fromCartesian(self):
        """MagePoint fromCartesian should transform coordinates correctly"""
        mp = MagePoint([2 / 3.0, 1 / 3.0, 2 / 3.0])
        self.assertFloatEqual(mp.fromCartesian().Coordinates,
                              [1 / 3.0, 1 / 3.0, 0])
        points = [
            MagePoint([.1, .2, .3]),
            MagePoint([.25, .25, .25], Color='red', Label='label', State='L'),
            MagePoint([1 / 3, 1 / 3, 0]),
            MagePoint([0, 0, 0]),
            MagePoint([1 / 7, 2 / 7, 3 / 7])
        ]
        for m in points:
            b = m.toCartesian().fromCartesian()
            self.assertFloatEqual(m.Coordinates, b.Coordinates)
            self.assertEqual(m.Color, b.Color)
            self.assertEqual(m.Label, b.Label)
            self.assertEqual(m.State, b.State)

            #even after multiple iterations?
            mutant = deepcopy(m)
            for x in range(10):
                mutant = mutant.toCartesian().fromCartesian()
            self.assertFloatEqual(m.Coordinates, mutant.Coordinates)
示例#13
0
 def test_toCartesian(self):
     """MagePoint toCartesian() should transform coordinates correctly"""
     m = MagePoint([.1, .2, .3])
     self.assertEqual(m.toCartesian().Coordinates, [.6, .7, .5])
     m = MagePoint()
     self.assertEqual(m.toCartesian().Coordinates, [1, 1, 1])
     m = MagePoint([.25, .25, .25], Color='red', Label='label', State='L')
     self.assertEqual(m.toCartesian().Coordinates, [.5, .5, .5])
     self.assertEqual(m.toCartesian().Color, m.Color)
     self.assertEqual(m.toCartesian().Label, m.Label)
     self.assertEqual(m.toCartesian().State, m.State)
     m = MagePoint([1 / 3.0, 1 / 3.0, 0])
     self.assertFloatEqual(m.toCartesian().Coordinates,
                           [2 / 3.0, 1 / 3.0, 2 / 3.0])
     m = MagePoint([1 / 3.0, 1 / 3.0, 1 / 3.0])
     self.assertFloatEqual(m.toCartesian().Coordinates,
                           [1 / 3.0, 1 / 3.0, 1 / 3.0])
     m = MagePoint([3, 4, 5])
     self.assertRaises(ValueError, m.toCartesian)
示例#14
0
 def test_cmp(self):
     """MagePoint cmp should compare all fields"""
     self.assertEqual(MagePoint([0, 0, 0]), MagePoint([0, 0, 0]))
     self.assertNotEqual(MagePoint([0, 0, 0]),
                         MagePoint([0, 0, 0], Color='red'))
示例#15
0
 def test_init_empty(self):
     """MagePoint should init correctly with no data"""
     m = MagePoint()
     self.assertEqual(str(m), ' '.join(map(str, [0, 0, 0])))
示例#16
0
 def test_toCartesian(self):
     """MagePoint toCartesian() should transform coordinates correctly"""
     m = MagePoint([.1,.2,.3])
     self.assertEqual(m.toCartesian().Coordinates,[.6,.7,.5])
     m = MagePoint()
     self.assertEqual(m.toCartesian().Coordinates,[1,1,1])
     m = MagePoint([.25,.25,.25],Color='red',Label='label',State='L')
     self.assertEqual(m.toCartesian().Coordinates,[.5,.5,.5])
     self.assertEqual(m.toCartesian().Color,m.Color)
     self.assertEqual(m.toCartesian().Label,m.Label)
     self.assertEqual(m.toCartesian().State,m.State)
     m = MagePoint([1/3.0,1/3.0,0])
     self.assertFloatEqual(m.toCartesian().Coordinates,
             [2/3.0,1/3.0,2/3.0])
     m = MagePoint([1/3.0,1/3.0,1/3.0])
     self.assertFloatEqual(m.toCartesian().Coordinates,
             [1/3.0,1/3.0,1/3.0])
     m = MagePoint([3,4,5])
     self.assertRaises(ValueError,m.toCartesian)
示例#17
0
def MagePointFromString(line):
    """Constructs a new MagePoint from a one-line string."""
    #handle the label if there is one: note that it might contain spaces
    line = line.strip()
    result = MagePoint()
    label = extract_delimited(line, '{', '}')
    if label:
        pieces = line.replace('{'+label+'}', '').split()
    else:
        pieces = line.split()
    fields = []
    #also have to take into account the possibility of comma-delimited parts
    for p in pieces:
        fields.extend(filter(None, p.split(',')))
    pieces = fields
    result.Label = label
    #get the coordinates and remove them from the list of items
    result.Coordinates = map(float, pieces[-3:])
    pieces = pieces[:-3]
    #parse the remaining attributes in more detail
    result.State = None
    result.Width = None
    result.Radius = None
    result.Color = None
    for attr in pieces:
        #handle radius
        if attr.startswith('r='):  #radius: note case sensitivity
            result.Radius = float(attr[2:])
        #handle single-character attributes
        elif len(attr) == 1:
            result.State = attr
        #handle line width
        elif attr.startswith('width'):
            result.Width = int(attr[5:])
        else:
            #otherwise assume it's a color label
            result.Color = attr
    return result
示例#18
0
 def test_toCartesian(self):
     """MagePoint toCartesian() should transform coordinates correctly"""
     m = MagePoint([0.1, 0.2, 0.3])
     self.assertEqual(m.toCartesian().Coordinates, [0.6, 0.7, 0.5])
     m = MagePoint()
     self.assertEqual(m.toCartesian().Coordinates, [1, 1, 1])
     m = MagePoint([0.25, 0.25, 0.25], Color="red", Label="label", State="L")
     self.assertEqual(m.toCartesian().Coordinates, [0.5, 0.5, 0.5])
     self.assertEqual(m.toCartesian().Color, m.Color)
     self.assertEqual(m.toCartesian().Label, m.Label)
     self.assertEqual(m.toCartesian().State, m.State)
     m = MagePoint([1 / 3.0, 1 / 3.0, 0])
     self.assertFloatEqual(m.toCartesian().Coordinates, [2 / 3.0, 1 / 3.0, 2 / 3.0])
     m = MagePoint([1 / 3.0, 1 / 3.0, 1 / 3.0])
     self.assertFloatEqual(m.toCartesian().Coordinates, [1 / 3.0, 1 / 3.0, 1 / 3.0])
     m = MagePoint([3, 4, 5])
     self.assertRaises(ValueError, m.toCartesian)