Hella everybody,
I have written a program. The motive of this program is to find a
pattern. my pattern is 'a' linked with both 'b' and 'c', the it should write to the output file. for example in my input file:
1 2
1 3
1 5
2 4
2 6.
3 5
MY output would be
1 2 3
1 2 5
1 3 5
2 4 6.
But as such my input text file has 2636 rows and 2 columns.
I have used 2D array which stores the tokens of my text file and then started my main loop. Cos this is the suggestion given by an expert in this forum to speed up the program vastly. now i am getting Array Out of bound Exception and also when I am comparing the values in my 2D array with the loop elements, it gives me a error. PLs fix up this code.
import java.io.*;
import java.util.*;
import java.lang.String.*;
public class motif_analysis1
{
public motif_analysis1() throws Exception
{
{
int ln=0;int ln1=0;int count=0;//int a,b,c=0;
String line,line1,A,B = " ";
int [][]x = new int[2636][2];
String value[] =new String[200];
String values[] =new String[200];
BufferedReader b1 = new BufferedReader(new FileReader("E:/Final_files/motif_analysis/Transreg_Motif.txt"));
PrintWriter p = new PrintWriter(new BufferedWriter(new FileWriter("E:/Final_files/motif_analysis/motif1_output.txt")));
LineNumberReader l = new LineNumberReader(b1);
int A1=0;int B1=0;int C1=0;
while(true)
{
line = l.readLine();if (line==null) break;
StringTokenizer st = new StringTokenizer(line);
ln = l.getLineNumber();
if (ln>=1)
{
int i = 0;int j=1;
while(st.hasMoreTokens())
{
value[i] = st.nextToken();
x[ln][i+1] = Integer.parseInt(value[i]);p.print(x[ln][i+1]+"\t");
i++;
} j++;
}p.println();
}
}
for(int a=1; a<900; a++){
for (int b=1; b<1280; b++){
for (int c=b+1; c<1280; c++){
for (int j=1; j<=2636;j++)
{
if((a==x[j][1])&& (b== x[j][2]))
{A1=a; B1=b;/*p.println(A1+"\t"+B1+"\t");}
if((a==x[j][1])&& (c== x[j][2]))
{A1=a; C1=c;}
if(B1!=0&&C1!=0)
}
{p.println(A1+"\t"+B1+"\t"+C1);}
}}}p.close();*/
}
public static void main(String s[]) throws Exception
{
new motif_analysis1();
}
}
Thanks in advance