| 1 | 1 | def hamming_distance(dna_strand_1, dna_strand_2): |
| 2 | pass | |
| 2 | # Edge Case: Handle None inputs | |
| 3 | if dna_strand_1 is None or dna_strand_2 is None: | |
| 4 | raise ValueError("DNA strands cannot be None") | |
| 5 | ||
| 6 | # Edge Case: Handle empty strings | |
| 7 | if len(dna_strand_1) == 0 and len(dna_strand_2) == 0: | |
| 8 | return 0 | |
| 9 | ||
| 10 | # Edge Case: Handle invalid characters | |
| 11 | valid_bases = set('ACGT') | |
| 12 | if not all(base in valid_bases for base in dna_strand_1) or not all(base in valid_bases for base in dna_strand_2): | |
| 13 | raise ValueError("DNA strands must contain only valid nucleotide bases (A, C, G, T)") | |
| 14 | ||
| 15 | # Calculate Hamming distance (compare up to the length of the shorter strand) | |
| 16 | distance = 0 | |
| 17 | min_length = min(len(dna_strand_1), len(dna_strand_2)) | |
| 18 | for i in range(min_length): | |
| 19 | if dna_strand_1[i] != dna_strand_2[i]: | |
| 20 | distance += 1 | |
| 21 | ||
| 22 | return distance | |
| 23 | # Handled Edge Cases: None inputs, empty strings, unequal lengths, invalid characters |