PROGRAM FOR DNA CONCEPT
PROGRAM:
import java.util.*;
import java.io.*;
public class DNAdescending
{
public static void main(String
args[])
{
final String
DNAfilname="dnasequence.txt";
final String
outputFile="dnaout1.txt";
DNAdescending dnaTest=new
DNAdescending();
try
{
File f=new File(outputFile);
BufferedOutputStream
outputstream=new BufferedOutputStream(new FileOutputStream(f));
PrintWriter
pw=new PrintWriter(outputstream);
dnaTest.readfileAsstring(DNAfilname,pw);
pw.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
private void
readfileAsstring(String filename,PrintWriter pw)throws java.io.IOException
{
BufferedReader
read=new BufferedReader(new
InputStreamReader(this.getClass().getClassLoader().getResourceAsStream(filename)));
String
strline;
int
count,i,j,temp;
boolean
flag;
String[][]
line=new String[15][6];
while((strline=read.readLine())!=null)
{
String[] word=strline.split(" ");
count=0;
flag=false;
for(i=0;i<word.length;i++)
{
if(word[i].contains("TATA"))
{
count++;
flag=true;
}
}
if(flag)
{
for(int k=0;k<6;k++)
{
if(line[count][k]==null)
{
line[count][k]=strline;
System.out.println(line[count][k]);
break;
}
}
}
}
for(i=4;i>0;i--)
for(j=5;j>=0;j--)
{
if(line[i][j]!=null)
writeIntoFile(line[i][j],pw);
}
}
private void
writeIntoFile(String str,PrintWriter pw)
{
try
{
pw.println(str);
System.out.println("The
dna pattern has been written");
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
OUTPUT:
Z:\javapgms>javac
DNAdescending.java
Z:\javapgms>java
DNAdescending
TATAHH TATAHH TATFH
TATASG TATAGG TATAG
TATGGG TATAGG TAGGG
The dna pattern has
been written
The dna pattern has
been written
The dna pattern has
been written