Tuesday 24 May 2022

Finding a Spliced Motif (Rosalind | English)

      

   rosalind


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: 
  1. static void solve() {
  2. Scanner sc = new Scanner(System.in);
  3. String strand = "";
  4. String sample = "";
  5. boolean ganti = false;
  6. sc.next();
  7. while (sc.hasNext()) {
  8. String masuk = sc.next();
  9. if (masuk.charAt(0) == '>') {
  10. ganti = true; continue;
  11. }
  12. if (ganti) {
  13. sample += masuk;
  14. }
  15. else {
  16. strand += masuk;
  17. }
  18. }
  19. int pvt = 0;
  20. for (int i = 0; i < sample.length(); i++) {
  21. while (strand.charAt(pvt) != sample.charAt(i)) {
  22. pvt++;
  23. }
  24. out.print((pvt + 1) + " ");
  25. pvt++;
  26. }
  27.     
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. 

While in the output I used out.print() function (line 24). That function is a modification function from System.out.print() which is the default function in java. For more details, 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 image 1: https://www.facebook.com/ProjectRosalind/

No comments:

Post a Comment