Saturday, 30 October 2021

Counting Point Mutations (Rosalind | English)

          

rosalind


Hi everyone, how are you? On this occasion, I want to discuss about one of the problems from rosalind.info's web. That title is "Counting Point Mutations". For the reference, you can first check out the problem what will be discussed (here). 

Overview

In this problem we will be given 2 DNA strings of equal length, let's call them s and t. Our job is to find the hamming distance between those strings. The hamming distance between 2 strings of equal length is the number of positions in the string which are different between those two. 

For example, the hamming distance for 2 strings at the image below is 7. 


The hamming distance between 2 strings is colored by red.

The Code 

This is the code for solving this problem (with java language): 

public void solve() {
String s = in.read();
String t = in.read();
int res = 0;
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) != t.charAt(i)) {
res++;
}
}
out.println(res);
}

As you've seen, the code is quite simple: we just have to scan those 2 strings; and if a different character found then save it as counted. 

Input and Output

In the code above, I used read() function for entering the string-form data. That function is a extend from one of the system inputs which are available in java, called BufferedReader. 

And for the output I used out.print() function. That function is a modification from System.out.print() function which is very familiar in java. You can see the additional code for that modification (input and output) in my complete code at github

That's it. If you want to ask something, you can write it in the comment section below. I hope this article is useful and see you in the next article! 


Reference :
Source of image 1 :https://www.facebook.com/ProjectRosalind/
Source of image 2 :http://rosalind.info/glossary/hamming-distance/

No comments:

Post a Comment