@@ -164,6 +164,8 @@ def align_and_link(
164164 * ,
165165 alignment_method : str = "pose_clustering" ,
166166 alignment_params : Optional [Dict [str , Union [int , float , str ]]] = None ,
167+ grouping_method : str = "qt" ,
168+ grouping_params : Optional [Dict [str , Union [int , float , str ]]] = None ,
167169 ) -> 'Py_ConsensusMap' :
168170 """Align multiple feature maps and return their linked consensus map.
169171
@@ -180,14 +182,21 @@ def align_and_link(
180182 alignment_params:
181183 Optional dictionary of parameters applied to the selected
182184 alignment algorithm.
185+ grouping_method:
186+ Name of the OpenMS feature grouping algorithm to use. Supported values
187+ are ``"qt"`` (QT clustering, default), ``"kd"`` (KD-tree based),
188+ ``"labeled"`` (for labeled data), and ``"unlabeled"`` (for unlabeled data).
189+ grouping_params:
190+ Optional dictionary of parameters applied to the selected
191+ grouping algorithm.
183192 """
184193
185194 if not feature_maps :
186195 return cls ()
187196
188197 native_maps = [cls ._copy_feature_map (feature_map ) for feature_map in feature_maps ]
189198 cls ._align_feature_maps (native_maps , alignment_method , alignment_params )
190- consensus_map = cls ._link_feature_maps (native_maps )
199+ consensus_map = cls ._link_feature_maps (native_maps , grouping_method , grouping_params )
191200 return cls (consensus_map )
192201
193202 # ==================== pandas integration ====================
@@ -388,11 +397,37 @@ def _create_alignment_algorithm(method: str):
388397 "Unsupported alignment_method. Use 'pose_clustering', 'identification', or 'identity'."
389398 )
390399
400+ @staticmethod
401+ def _create_grouping_algorithm (method : str ):
402+ """Create the appropriate feature grouping algorithm."""
403+ normalized = method .lower ()
404+ if normalized in {"qt" , "qtcluster" }:
405+ return oms .FeatureGroupingAlgorithmQT ()
406+ if normalized in {"kd" , "tree" }:
407+ return oms .FeatureGroupingAlgorithmKD ()
408+ if normalized == "labeled" :
409+ return oms .FeatureGroupingAlgorithmLabeled ()
410+ if normalized == "unlabeled" :
411+ return oms .FeatureGroupingAlgorithmUnlabeled ()
412+ raise ValueError (
413+ "Unsupported grouping_method. Use 'qt', 'kd', 'labeled', or 'unlabeled'."
414+ )
415+
391416 @staticmethod
392417 def _link_feature_maps (
393418 feature_maps : Sequence [oms .FeatureMap ],
419+ grouping_method : str = "qt" ,
420+ grouping_params : Optional [Dict [str , Union [int , float , str ]]] = None ,
394421 ) -> oms .ConsensusMap :
395- grouping = oms .FeatureGroupingAlgorithmQT ()
422+ grouping = Py_ConsensusMap ._create_grouping_algorithm (grouping_method )
423+
424+ # Apply parameters if provided
425+ if grouping_params :
426+ params = grouping .getDefaults ()
427+ for key , value in grouping_params .items ():
428+ params .setValue (str (key ), value )
429+ grouping .setParameters (params )
430+
396431 consensus_map = oms .ConsensusMap ()
397432 grouping .group (feature_maps , consensus_map )
398433
0 commit comments