予想どおりに実行される Java コードがいくつかありますが、ジョブが配列をループしているだけでも、ある程度の時間 (数秒) がかかります。
入力ファイルは、下の画像に示すように Fasta ファイルです。私が使用しているファイルは 2.9Mo で、最大 20Mo の Fasta ファイルがいくつかあります。
AGC TTT TCA ... などコードには機能的なセンスがありませんが、私が望むのは、各アミノ酸を対応する塩基の束に追加することです。例 :
AGC - Ser / CUG Leu / ...など
では、コードの何が問題なのですか? それをより良くする方法はありますか?最適化はありますか?文字列全体をループするには時間がかかりますが、おそらく数秒かかりますが、より良い方法を見つける必要があります。
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class fasta {
public static void main(String[] args) throws IOException {
File fastaFile;
FileReader fastaReader;
BufferedReader fastaBuffer = null;
StringBuilder fastaString = new StringBuilder();
try {
fastaFile = new File("res/NC_017108.fna");
fastaReader = new FileReader(fastaFile);
fastaBuffer = new BufferedReader(fastaReader);
String fastaDescription = fastaBuffer.readLine();
String line = fastaBuffer.readLine();
while (line != null) {
fastaString.append(line);
line = fastaBuffer.readLine();
}
System.out.println(fastaDescription);
System.out.println();
String currentFastaAcid;
for (int i = 0; i < fastaString.length(); i+=3) {
currentFastaAcid = fastaString.toString().substring(i, i + 3);
System.out.println(currentFastaAcid);
}
} catch (NullPointerException e) {
System.out.println(e.getMessage());
} catch (FileNotFoundException e) {
System.out.println(e.getMessage());
} catch (IOException e) {
System.out.println(e.getMessage());
} finally {
fastaBuffer.close();
}
}
}