@@ -781,7 +781,7 @@ def sym_to_aux(self):
781
781
def get_contained_labels (self , inplace = True ):
782
782
"""
783
783
Get the set of unique labels contained in this annotation.
784
- Returns a pandas dataframe or sets the __contained__ labels
784
+ Returns a pandas dataframe or sets the contained_labels
785
785
attribute of the object.
786
786
787
787
@@ -827,19 +827,27 @@ def get_contained_labels(self, inplace=True):
827
827
if self .label_store is not None :
828
828
index_vals = set (self .label_store )
829
829
reset_index = False
830
+ counts = np .unique (self .label_store , return_counts = True )
830
831
elif self .symbol is not None :
831
832
index_vals = set (self .symbol )
832
833
label_map .set_index (label_map ['symbol' ].values , inplace = True )
833
834
reset_index = True
835
+ counts = np .unique (self .symbol , return_counts = True )
834
836
elif self .description is not None :
835
837
index_vals = set (self .description )
836
838
label_map .set_index (label_map ['description' ].values , inplace = True )
837
839
reset_index = True
840
+ counts = np .unique (self .description , return_counts = True )
838
841
else :
839
842
raise Exception ('No annotation labels contained in object' )
840
843
841
844
contained_labels = label_map .loc [index_vals , :]
842
845
846
+ # Add the counts
847
+ for i in range (len (counts [0 ])):
848
+ contained_labels .loc [counts [0 ][i ], 'n_occurrences' ] = counts [1 ][i ]
849
+ contained_labels ['n_occurrences' ] = pd .to_numeric (contained_labels ['n_occurrences' ], downcast = 'integer' )
850
+
843
851
if reset_index :
844
852
contained_labels .set_index (contained_labels ['label_store' ].values ,
845
853
inplace = True )
@@ -1220,7 +1228,7 @@ def rdann(record_name, extension, sampfrom=0, sampto=None, shift_samps=False,
1220
1228
If True, assign a summary table of the set of annotation labels
1221
1229
contained in the file to the 'contained_labels' attribute of the
1222
1230
returned object. This table will contain the columns:
1223
- ['label_store', 'symbol', 'description', 'n_occurences ']
1231
+ ['label_store', 'symbol', 'description', 'n_occurrences ']
1224
1232
1225
1233
Returns
1226
1234
-------
0 commit comments