Hi everyone, how are you? This time, I want to discuss about one problem that exists in rosalind.info's web. The title is "Finding a Spliced Motif". For the reference, you can first check out the problem that will be discussed (here).
Overview
In this problem, we will given 2 strings modelled in FASTA format (let's call them s and t). The first string (or s) represents the DNA sequence. And the second string (or t) represent the subsequence of string s. Our task is to find the index of subsequence t at string s. For example, the index of subsequence "ACG" in string "TATCCAG" is (2, 4, 7) and (2, 5, 7).
The Code
This is the code for solving this problem using java language:
- static void solve() {
- Scanner sc = new Scanner(System.in);
- String strand = "";
- String sample = "";
- boolean ganti = false;
- sc.next();
- while (sc.hasNext()) {
- String masuk = sc.next();
- if (masuk.charAt(0) == '>') {
- ganti = true; continue;
- }
- if (ganti) {
- sample += masuk;
- }
- else {
- strand += masuk;
- }
- }
- int pvt = 0;
- for (int i = 0; i < sample.length(); i++) {
- while (strand.charAt(pvt) != sample.charAt(i)) {
- pvt++;
- }
- out.print((pvt + 1) + " ");
- pvt++;
- }
- }
Input dan Output
As you can see, in the code above I used next() function for entering the string-form dataset (line 8).
I also used another input function called hasNext() (line 7) because of its ability to entering the unknown amount of data. That function is very suitable to be used for entering a FASTA format-form data.
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 image 1: https://www.facebook.com/ProjectRosalind/
No comments:
Post a Comment