저는 유전자 서열이나 하위 서열 내 특정 염기 서열의 지표를 찾고 있다고 생각합니다. 다음 예제 클래스는 Java의 정규 표현식 라이브러리를 사용하여 다음과 같은 일반적인 접근법을 보여줍니다.
package jcc.tj.dnamatch;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Gene {
private String gene;
public Gene() {}
public Gene(String gene) {
this.gene = gene;
}
public List<Integer> find(String seq) {
List<Integer> indices = new ArrayList<Integer>();
Pattern pat = Pattern.compile(seq);
Matcher m = pat.matcher(gene);
while (m.find())
indices.add(m.start());
return indices;
}
public String getGene() {
return gene;
}
public void setGene(String gene) {
this.gene = gene;
}
}
위의 예에서 Matcher를 사용하여 패턴을 찾습니다. 더 효율적일 수있는 다른 String 기반 알고리즘이 있지만 출발점으로 Matcher는 모든 유형의 텍스트 패턴 검색에 대한 일반적인 솔루션을 제공합니다.
문자로 된 뉴클레오티드 (ATCG)는 매우 유연하고 편리하여 문자열 기반 도구를 사용하여 시퀀스 및/또는 하위 시퀀스를 분석하고 특성을 지정할 수 있습니다. 불행히도, 그들은 잘 확장되지 않습니다. 그러한 경우, 서열을 표현하고 관리하기위한 좀 더 구체적인 생물 정보학 기술을 고려하는 것이 낫다.
특정 기술에 대한 좋은 참조는 서적 Next Generation Sequencing Technologies and Challenges in Sequence Assembly의 2 장 - 차세대 시퀀싱의 알고리즘 및 데이터 구조입니다. 더 자세한 PDF 미리보기는 this Google 링크에서 제공됩니다. 비록 내가 영원히 작동하지 않을지라도.
BioJava을보고 싶을 수도 있습니다. 필자는 자바에서 당신을 멀게하고 싶지는 않지만 Perl은 시퀀스 분석을위한 또 다른 좋은 대안이다. Beginning Perl for Bioinformatics; Perl and Bioinformatics; 또는 BioPerl.
이 답변은 TMI 일 수 있음을 알고 있습니다. 그러나 귀하 또는 다른 사람들이보다 적절한 해결책을 찾는데 도움이된다면 그 목적을 달성 할 수 있습니다.
는
편집 : 아래의 의견을 바탕으로
,이 검색이 StringBuilder.indexOf()
하여 수행 할 것을 요구 사항 주어진 숙제 질문 것으로 보인다. 다음 방법은 그에 따라 검색을 수행합니다.
public List<Integer> findBySb(String seq) {
List<Integer> indices = new ArrayList<Integer>();
StringBuilder sb = new StringBuilder(gene);
int strIdx = 0;
while (strIdx < sb.length()) {
int idx = sb.indexOf(seq, strIdx);
if (idx == -1)
break;
indices.add(idx);
strIdx = idx + seq.length();
}
return indices;
}
동일한 indexOf()
접근법을 문자열과 함께 사용할 수 있습니다.
public List<Integer> findByString(String seq) {
List<Integer> indices = new ArrayList<Integer>();
int strIdx = 0;
while (strIdx < gene.length()) {
int idx = gene.indexOf(seq, strIdx);
if (idx == -1)
break;
indices.add(idx);
strIdx = idx + seq.length();
}
return indices;
}
모두 StringBuilder
와 String
따라서 기능적으로 차이가 없으며, String.indexOf()
같은 정적 구현을 사용한다. 그러나 검색을 위해서 StringBuilder
을 인스턴스화하는 것은 잔인하며 약간 문자열 조작을 관리하기 위해 버퍼를 할당하므로 더 낭비 적이기 때문입니다. 나는 갈 수 있었다 :). 그러나 그것은 대답에 추가하지 않는다.
'StringBuilder'에 다른'indexOf' 메소드가 있습니까? –
음, 그렇습니다.''indexOf (String str, int fromIndex) ''가 있습니다 만, 아직 'str'이 (분명히) 어디에 있는지 알지 못하기 때문에 그렇게 도움이되지 않습니다. – Smunfr
[Date()]에서 유닉스 타임 스탬프를 얻는 것 (// stackoverflow.com/q/7784421) –