[docs]classTrainedIntegratedReferences:"""Object containing integrated references, typically constructed by :py:meth:`~singler.train_integrated.train_integrated`."""def__init__(self,ptr:int,ref_labels:list):self._ptr=ptrself._labels=ref_labels@propertydefreference_labels(self)->list:"""List of lists containing the names of the labels for each reference. Each entry corresponds to a reference in :py:attr:`~reference_names`, if ``reference_names`` is not ``None``. """returnself._labels
[docs]deftrain_integrated(test_features:Sequence,ref_prebuilt:list[TrainedSingleReference],warn_lost:bool=True,num_threads:int=1,)->TrainedIntegratedReferences:"""Build a set of integrated references for classification of a test dataset. Arguments: test_features: Sequence of features for the test dataset. ref_prebuilt: List of prebuilt references, typically created by calling :py:meth:`~singler.train_single.train_single`. warn_lost: Whether to emit a warning if the markers for each reference are not all present in all references. num_threads: Number of threads. Returns: Integrated references for classification with :py:meth:`~singler.classify_integrated_references.classify_integrated`. """# Checking the genes.ifwarn_lost:all_refnames=[x.featuresforxinref_prebuilt]intersected=set(_stable_intersect(*all_refnames))fortrainedinref_prebuilt:forgintrained.marker_subset():ifgnotinintersected:warnings.warn("not all markers in 'ref_prebuilt' are available in each reference")all_inter_test=[]all_inter_ref=[]fori,trainedinenumerate(ref_prebuilt):common=_stable_intersect(test_features,trained.features)all_inter_test.append(biocutils.match(common,test_features,dtype=numpy.uint32))all_inter_ref.append(biocutils.match(common,trained.features,dtype=numpy.uint32))all_data=[mattress.initialize(x._full_data)forxinref_prebuilt]# Applying the integration.ibuilt=lib.train_integrated(all_inter_test,[x.ptrforxinall_data],all_inter_ref,[x._full_label_codesforxinref_prebuilt],[x._ptrforxinref_prebuilt],num_threads)returnTrainedIntegratedReferences(ptr=ibuilt,ref_labels=[x.labelsforxinref_prebuilt],)