Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def percent_id(seq1,seq2):
alignment = global_align(seq1,seq2)
return (1. - hamming_distance(alignment[0],alignment[1]) / float(len(alignment[0]))) * 100.
Available algorithms:
* levenshtein
* damerau-levenshtein (DEFAULT)
* hamming
* jaro
* jaro-winkler
Return values:
"levenshtein", "damerau-levenshtein" and "hamming" return integers
"jaro" and "jaro-winkler" return floats in the range of 0.0 (completely
different) to 1.0 (identical strings).
'''
algos = {
"levenshtein":levenshtein_distance,
"damerau-levenshtein":damerau_levenshtein_distance,
"hamming":hamming_distance,
"jaro":jaro_similarity,
"jaro-winkler":jaro_winkler_similarity
}
if not method in list(algos.keys()):
raise ValueError("Unsupported algorithm type: %s" % method)
if str1 is None or str2 is None or not isinstance(str1, str) or not isinstance(str2, str):
raise TypeError("Arguments must be strings.")
distance_function = algos[method]
# All the jellyfish distance functions expect unicode, which is the default
# for Python3. If we're running in Python2, we need to convert them.
python_version = sys.version_info
if python_version.major == 2:
def barcode_hamming(observed,barcodes):
"""Compute entropy of probabilistic barcode assignment.
observed -- SeqRecord of the barcode
barcodes -- list of barcode possibilities (python strings)
"""
obs_seq = observed.seq.tostring()
distances = [(barcode,hamming_distance(obs_seq,barcode)) for barcode in barcodes]
closest = min(distances,key=lambda p: p[1])
return closest # tuple of (barcode, distance)