<s> """<STR_LIT>""" <EOL> import numpy as np <EOL> import scipy . spatial . distance <EOL> import skbio <EOL> from skbio . util . _decorator import experimental <EOL> @ experimental ( as_of = '<STR_LIT>' ) <EOL> def hamming ( seq1 , seq2 ) : <EOL> """<STR_LIT>""" <EOL> _check_seqs ( seq1 , seq2 ) <EOL> if len ( seq1 ) != len ( seq2 ) : <EOL> raise ValueError ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % ( len ( seq1 ) , len ( seq2 ) ) ) <EOL> if not seq1 : <EOL> distance = np . nan <EOL> else : <EOL> distance = scipy . spatial . distance . hamming ( seq1 . values , seq2 . values ) <EOL> return float ( distance ) <EOL> @ experimental ( as_of = '<STR_LIT>' ) <EOL> def kmer_distance ( seq1 , seq2 , k , overlap = True ) : <EOL> """<STR_LIT>""" <EOL> _check_seqs ( seq1 , seq2 ) <EOL> seq1_kmers = set ( map ( str , seq1 . iter_kmers ( k , overlap = overlap ) ) ) <EOL> seq2_kmers = set ( map ( str , seq2 . iter_kmers ( k , overlap = overlap ) ) ) <EOL> all_kmers = seq1_kmers | seq2_kmers <EOL> if not all_kmers : <EOL> return np . nan <EOL> shared_kmers = seq1_kmers & seq2_kmers <EOL> number_unique = len ( all_kmers ) - len ( shared_kmers ) <EOL> fraction_unique = number_unique / len ( all_kmers ) <EOL> return fraction_unique <EOL> def _check_seqs ( seq1 , seq2 ) : <EOL> for seq in seq1 , seq2 : <EOL> if not isinstance ( seq , skbio . Sequence ) : <EOL> raise TypeError ( <EOL> "<STR_LIT>" <EOL> % type ( seq ) . __name__ ) <EOL> if type ( seq1 ) is not type ( seq2 ) : <EOL> raise TypeError ( <EOL> "<STR_LIT>" <EOL> % ( type ( seq1 ) . __name__ , type ( seq2 ) . __name__ ) ) </s>
