pegasusio/unimodal_data.py
def _polish_featurekey(self, feature_metadata: pd.DataFrame, genome: str) -> None:
        """    Remove prefixing genome strings and deduplicate feature keys
        """
        if genome != "unknown":
            # remove genome strings for 10x chemistry if > 1 genomes exist
            import re
            prefix = re.compile(f"^{genome}_+")
            if prefix.match(feature_metadata["featurekey"][0]):
                feature_metadata["featurekey"] = np.array([prefix.sub("", x) for x in feature_metadata["featurekey"].values], dtype = object)
                if "featureid" in feature_metadata:
                    feature_metadata["featureid"] = np.array([prefix.sub("", x) for x in feature_metadata["featureid"].values], dtype = object)

        if feature_metadata["featurekey"].duplicated().sum() > 0:
            # deduplicate feature keys
            keys = feature_metadata["featurekey"].values
            ids = feature_metadata["featureid"].values if "featureid" in feature_metadata else None

            from collections import Counter
            dup_ids = Counter()

            for i in range(keys.size):
                idn = dup_ids[keys[i]]
                if idn > 0:
                    # key only is duplicated
                    if ids is not None:
                        keys[i] = keys[i] + '_' + ids[i]
                        idn = dup_ids[keys[i]]
                idn += 1
                dup_ids[keys[i]] = idn
                if idn > 1:
                    keys[i] = keys[i] + f".#~{idn}"
    Remove prefixing genome strings and deduplicate feature keys
        
Remove prefixing genome strings and deduplicate feature keys
Remove prefixing genome strings and deduplicate feature keys
def _polish_featurekey(self, feature_metadata: pd.DataFrame, genome: str) -> None:
        if genome != "unknown":
            import re
            prefix = re.compile(f"^{genome}_+")
            if prefix.match(feature_metadata["featurekey"][0]):
                feature_metadata["featurekey"] = np.array([prefix.sub("", x) for x in feature_metadata["featurekey"].values], dtype = object)
                if "featureid" in feature_metadata:
                    feature_metadata["featureid"] = np.array([prefix.sub("", x) for x in feature_metadata["featureid"].values], dtype = object)
        if feature_metadata["featurekey"].duplicated().sum() > 0:
            keys = feature_metadata["featurekey"].values
            ids = feature_metadata["featureid"].values if "featureid" in feature_metadata else None
            from collections import Counter
            dup_ids = Counter()
            for i in range(keys.size):
                idn = dup_ids[keys[i]]
                if idn > 0:
                    if ids is not None:
                        keys[i] = keys[i] + '_' + ids[i]
                        idn = dup_ids[keys[i]]
                idn += 1
                dup_ids[keys[i]] = idn
                if idn > 1:
                    keys[i] = keys[i] + f".#~{idn}"
def _polish_featurekey ( self , feature_metadata : pd . DataFrame , genome : str ) -> None : if genome != "unknown" : import re prefix = re . compile ( f"^{genome}_+" ) if prefix . match ( feature_metadata [ "featurekey" ] [ 0 ] ) : feature_metadata [ "featurekey" ] = np . array ( [ prefix . sub ( "" , x ) for x in feature_metadata [ "featurekey" ] . values ] , dtype = object ) if "featureid" in feature_metadata : feature_metadata [ "featureid" ] = np . array ( [ prefix . sub ( "" , x ) for x in feature_metadata [ "featureid" ] . values ] , dtype = object ) if feature_metadata [ "featurekey" ] . duplicated ( ) . sum ( ) > 0 : keys = feature_metadata [ "featurekey" ] . values ids = feature_metadata [ "featureid" ] . values if "featureid" in feature_metadata else None from collections import Counter dup_ids = Counter ( ) for i in range ( keys . size ) : idn = dup_ids [ keys [ i ] ] if idn > 0 : if ids is not None : keys [ i ] = keys [ i ] + '_' + ids [ i ] idn = dup_ids [ keys [ i ] ] idn += 1 dup_ids [ keys [ i ] ] = idn if idn > 1 : keys [ i ] = keys [ i ] + f".#~{idn}"
Remove prefixing genome strings and deduplicate feature keys
Remove prefixing genome strings and deduplicate feature keys
"""    Remove prefixing genome strings and deduplicate feature keys
        """ # remove genome strings for 10x chemistry if > 1 genomes exist # deduplicate feature keys # key only is duplicated
self
feature_metadata
pd.DataFrame
genome
str