Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to view repeated DNA sequences in java

Shulou Source: shulou.com Published: 2022-06-01 01:02:05 10月01日 Update

This article will introduce in detail for you "how to view repeated DNA sequences in java", the content steps are clear and detailed, and the details are handled properly, and the editor updates different knowledge points every day, I hope this article "how to view repeated DNA sequences in java" can give you unexpected gains, please follow the editor's ideas slowly in depth, the specific contents are as follows, to harvest new knowledge.

All DNA are made up of a series of nucleotides abbreviated as Ameme Cpene G and T, such as "ACGAATTCCG". In the study of DNA, it is sometimes very helpful to identify repetitive sequences in DNA.

Write a function to find all 10-letter sequences (substrings) in the DNA molecule that appear more than once.

Example:

Enter: s = "AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT"

Output: ["AAAAACCCCC", "CCCCCAAAAA"]

Answer:

1public List findRepeatedDnaSequences (String s) {

2 Set seen = new HashSet ()

3 Set repeated = new HashSet ()

4 for (int I = 0; I + 9 < s.length (); iTunes +) {

5 String ten = s.substring (I, I + 10)

6 if (! seen.add (ten))

7 repeated.add (ten)

8}

9 return new ArrayList (repeated)

10}

Parsing:

It means to intercept a substring of 10 characters at a time, and this kind of string appears more than once. The code is very simple. Each time it is intercepted, it will be stored in the seen collection. If the storage fails, it indicates that there is a repetition. Let's take a look at another way to write it.

1public List findRepeatedDnaSequences (String s) {

2 Set words = new HashSet ()

3 Set repeated = new HashSet ()

4 char [] map = new char [26]

5 / / map ['A' -'A'] = 0

6 map ['C' -'A'] = 1

7 map ['G' -'A'] = 2

8 map ['T' -'A'] = 3

9 for (int I = 0; I < s.length ()-9; iTunes +) {

10 int v = 0

11 for (int j = I; j < I + 10; jacks +) {

12 v

Tags: Type sequence data storage content character integer practice research different proper unexpected that is code key keyword writing function molecule principle Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Huawei macOS MariaDB Microsoft