@@ -439,35 +439,60 @@ def _to_xml_element(self):
439
439
return vox_ind
440
440
441
441
442
- class Cifti2Vertices (xml .XmlSerializable ):
442
+ class Cifti2Vertices (xml .XmlSerializable , collections . MutableSequence ):
443
443
"""Cifti2 vertices - association of brain structure and a list of vertices
444
444
445
445
"Contains a BrainStructure type and a list of vertex indices within a
446
446
Parcel."
447
447
448
448
Attribute descriptions are from the CIFTI-2 spec dated 2014-03-01.
449
+ The class behaves like a list of Vertex indices
450
+ (which are independent for each surface, and zero-based)
449
451
450
452
Attributes
451
453
----------
452
454
brain_structure : str
453
455
A string from the BrainStructure list to identify what surface this
454
456
vertex list is from (usually left cortex, right cortex, or cerebellum).
455
- vertices : ndarray shape (N,)
456
- Vertex indices (which are independent for each surface, and zero-based)
457
457
"""
458
458
def __init__ (self , brain_structure = None , vertices = None ):
459
- self .vertices = vertices
459
+ self ._vertices = []
460
+ if vertices is not None :
461
+ self .extend (vertices )
462
+
460
463
self .brain_structure = brain_structure
461
464
465
+ def __len__ (self ):
466
+ return len (self ._vertices )
467
+
468
+ def __delitem__ (self , index ):
469
+ del self ._vertices [index ]
470
+
471
+ def __getitem__ (self , index ):
472
+ return self ._vertices [index ]
473
+
474
+ def __setitem__ (self , index , value ):
475
+ try :
476
+ value = int (value )
477
+ self ._vertices [index ] = value
478
+ except ValueError :
479
+ raise ValueError ('value must be an int' )
480
+
481
+ def insert (self , index , value ):
482
+ try :
483
+ value = int (value )
484
+ self ._vertices .insert (index , value )
485
+ except ValueError :
486
+ raise ValueError ('value must be an int' )
487
+
462
488
def _to_xml_element (self ):
463
489
if self .brain_structure is None :
464
490
raise CIFTI2HeaderError ('Vertices element require a BrainStructure' )
465
491
466
492
vertices = xml .Element ('Vertices' )
467
493
vertices .attrib ['BrainStructure' ] = str (self .brain_structure )
468
494
469
- if self .vertices is not None :
470
- vertices .text = ' ' .join (self .vertices .astype (str ))
495
+ vertices .text = ' ' .join ([str (i ) for i in self ])
471
496
return vertices
472
497
473
498
0 commit comments