java dna框架_Taking DNA and printing out Protein regions Java

This should work. There should be a better way to find out the lowest out of the three indexes greater than -1 instead of putting those in an array and comparing. Please try this code. None of your lines actually begin with TGA. So, you might want to change it before you start testing. I modified the dna file while testing.

import java.io.File;

import java.io.FileNotFoundException;

import java.util.Scanner;

public class DNAApp {

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

System.out.println("Please enter the full path to the fasta file.");

String input = in.nextLine();

File file = new File(input);

try {

Scanner fileScan = new Scanner(file);

while (fileScan.hasNextLine()) {

String line = fileScan.nextLine();

line = line.replaceAll("X", "A");

if (line.startsWith("ATG")) {

int[] dnaArray = new int[3];

//Get the lowest index out of TAA, TGA, or TAG

dnaArray[0] = line.indexOf("TAA",3);

dnaArray[1] = line.indexOf("TGA",3);

dnaArray[2] = line.indexOf("TAG",3);

//We cannot use Math.min, because it will consider -1 as the lowest if it does not find a string with the index passed to it.

int lowestIndex = Integer.MAX_VALUE;

//We try to find the lowest of all indexes.

for(int index : dnaArray) {

//Check only if the current index is greater than -1 and less than the current lowest index.

if(index > -1 && index < lowestIndex) {

lowestIndex = index;

}

}

//Do a substring from the line only if lowestIndex is not equal to the Integer.MAX_VALUE (intial value set

if(lowestIndex != Integer.MAX_VALUE) {

line = line.substring(0,lowestIndex + 3);

}

System.out.println(line);

}

}

} catch (FileNotFoundException fnfe) {

fnfe.printStackTrace();

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值