PageRenderTime 1527ms CodeModel.GetById 271ms app.highlight 1048ms RepoModel.GetById 190ms app.codeStats 1ms

/sPlot/src/Splot.java

https://github.com/alphonse23/luc_splot
Java | 1750 lines | 1399 code | 252 blank | 99 comment | 325 complexity | 704c123d7ac196e27bc786bb083d59ca MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1import java.beans.PropertyChangeSupport;
   2import java.io.BufferedReader;
   3import java.io.BufferedWriter;
   4import java.io.File;
   5import java.io.FileReader;
   6import java.io.FileWriter;
   7import java.io.IOException;
   8import java.io.PrintWriter;
   9import java.text.DateFormat;
  10import java.text.SimpleDateFormat;
  11import java.util.Calendar;
  12
  13import javax.swing.JOptionPane;
  14
  15public class Splot {
  16//Input
  17	private int w_size;				//window size
  18	private int nmer_size;
  19	private boolean use_complementary;
  20//Parameters 
  21	private int num_possible_nmers;
  22	private float min_percent_nt_in_w = (float)0.1;
  23	private int min_num_nmers_in_w=50;
  24	
  25//Output
  26	private int len_X;
  27	private int len_Y;
  28	
  29	private char[][] seq_inX_w;		//Holds all X window sequences [# of windows][sequence for each window]
  30	private int w_num_X;				//Number of windows for X sequence
  31	
  32	private char[][] seq_inY_w;		//Holds all Y window sequences [# of windows][sequence for each window]
  33	private int w_num_Y;				//Number of windows for Y sequence 
  34	
  35	private static String[] X_geneSynonyms;
  36	private static String[] Y_geneSynonyms;
  37	
  38	private float[][] score;
  39	private int[] hisPlot;
  40	private float[] avgCorrX;
  41	private float[] avgCorrY;
  42	private float[] stdev_pearCorrX;
  43	private float[] stdev_pearCorrY;
  44	
  45	private boolean[] valid_X;
  46	private boolean[] valid_Y;
  47	
  48	private float[][] nmer_counts_X;
  49	private float[][] nmer_counts_Y;
  50	
  51	private float[] w_meanVals_X;
  52	private float[] w_meanVals_Y;
  53	
  54	private float[] X_square;
  55	private float[] Y_square;
  56	private static String X_header;
  57	private static String Y_header;
  58	
  59//FileWriters 
  60	private PrintWriter writeGC;
  61
  62//Sean's stuff
  63	private String args[];
  64	public final PropertyChangeSupport pcs = new PropertyChangeSupport( this );
  65	private boolean process = false;
  66	
  67	// Some OO changes
  68	public Splot(String[] args_i){
  69		/* 
  70		 * String[] args
  71	     * 0 - Sequence X
  72	     * 1 - Sequence Y
  73	     * 2 - nmer_size
  74	     * 3 - w_size	//VALUE=-1 IF USING GENE
  75	     * 4 - use_complementary
  76	     * 5 - gene file X 
  77	     * 6 - gene file Y 
  78	     * 7 - Dir for scoreMatrix file  
  79	     * 8 - Dir for avg+stdev file  
  80	     * 9 - Dir for window_GC_content file
  81	     * 10 - Dir for maxCorr_w_pairs file 
  82	     * 11 - Dir for geneScoreMatrix file
  83	     * 12 - Dir for geneAvgStdev file
  84	     * 13 - Dir for gene_GC_content file
  85	     * 14 - Dir for maxCorr_gene_pairs file
  86		 * 
  87		 */
  88		
  89		this.args = args_i;
  90	}
  91	
  92	public void init(){
  93		System.err.println("heLL!");
  94		int one=1;	 
  95        nmer_size = Integer.parseInt(args[2]);
  96        w_size = Integer.parseInt(args[3]);
  97        if(w_size!=-1)
  98        {
  99                    parse_X(args[0]);
 100                    if(process) return;
 101                    parse_Y(args[1]);
 102                    if(process) return;
 103                    
 104                    use_complementary = Boolean.valueOf(args[4]);
 105                    score = new float[w_num_X][w_num_Y];
 106                    valid_X = new boolean[w_num_X];
 107                    valid_Y = new boolean[w_num_Y];
 108
 109                    num_possible_nmers = one<<(nmer_size*2);
 110                    nmer_counts_X = new float[w_num_X][num_possible_nmers];
 111                    nmer_counts_Y = new float[w_num_Y][num_possible_nmers];
 112
 113                    w_meanVals_X = new float[w_num_X];
 114                    w_meanVals_Y = new float[w_num_Y];
 115                    X_square = new float[w_num_X];
 116                    Y_square = new float[w_num_Y];	
 117                    
 118                    compute();
 119                    
 120                    //writeScoreMatrix(args[7]);
 121                    //write_Avg_Stdev(args[8]);
 122                    //write_GC_w_content(args[9]);
 123                    //write_max_w_Corr(args[10]);
 124        }
 125        else
 126        {
 127        			Prepare_Sequences_var_window_X(args[0], args[5]);
 128        			if(process) return;
 129        			Prepare_Sequences_var_window_Y(args[1], args[6]);
 130        			if(process) return;
 131        			use_complementary = Boolean.valueOf(args[4]);
 132                    
 133                    score = new float[w_num_X][w_num_Y]; //508952576 33030144
 134                    valid_X = new boolean[w_num_X]; //C:\\DOCUME~1\\ADMINI~1\\LOCALS~1\\Temp\\NC_009925.fna
 135                    valid_Y = new boolean[w_num_Y];
 136                    
 137                    // TEST WITH N-MER SIZE 3
 138                    num_possible_nmers = one<<(nmer_size*2);
 139                    nmer_counts_X = new float[w_num_X][num_possible_nmers];
 140                    nmer_counts_Y = new float[w_num_Y][num_possible_nmers];
 141                    w_meanVals_X = new float[w_num_X];
 142                    w_meanVals_Y = new float[w_num_Y];
 143                    X_square = new float[w_num_X];
 144                    Y_square = new float[w_num_Y];
 145                    
 146                    S_Plot_Correlation_var_windows();
 147                    //writeGeneMatrix(args[11]);
 148                    //write_Gene_Avg_Stdev(args[12]);
 149                    //write_GC_gene_content(args[13]);
 150                    //write_max_gene_Corr(args[14]);
 151        }
 152	}
 153	
 154	public void parse_X(String xSquence){
 155		File f_X = new File(xSquence);
 156		BufferedReader in = getReader(f_X);
 157		
 158		StringBuilder sb = new StringBuilder();
 159		String line = getLine(in);
 160		while (line!=null) {
 161			line = getLine(in);
 162			if(line!=null){
 163				len_X += (long)line.length();
 164				sb.append(line);
 165			}
 166		}
 167		StringBuilder sb2 = sb;
 168			
 169			w_num_X=len_X/w_size;
 170			if(((len_X%w_size)/(float)w_size)>=min_percent_nt_in_w) w_num_X++;
 171			seq_inX_w = new char[w_num_X][w_size+1];
 172			
 173			int k = 0;
 174			int j = 0;
 175			for(int i=0; i<w_num_X; i++){
 176				for(j=0; j<w_size; j++){
 177					seq_inX_w[i][j] = sb2.charAt(k);
 178					if(k<(len_X-1)){k++;}
 179						else{break;}
 180				}
 181				seq_inX_w[i][j]='\0';
 182			}
 183	}
 184	public void parse_Y(String ySequence){
 185		File f_Y = new File(ySequence);
 186		BufferedReader in = getReader(f_Y);
 187		
 188		StringBuilder sb = new StringBuilder();
 189		String line = getLine(in);
 190			while (line!=null) {
 191				line = getLine(in);
 192				if(line!=null){
 193					len_Y += (long)line.length();
 194					sb.append(line);
 195					}
 196			}
 197			StringBuilder sb2 = sb;
 198			
 199			w_num_Y=len_Y/w_size;
 200			if(((len_Y%w_size)/(float)w_size)>=min_percent_nt_in_w) w_num_Y++;
 201			seq_inY_w = new char[w_num_Y][w_size+1];
 202			
 203			int k = 0;
 204			int j = 0;
 205			for(int i=0; i<w_num_Y; i++){
 206				for(j=0; j<w_size; j++){
 207					seq_inY_w[i][j] = sb2.charAt(k);
 208					if(k<(len_Y-1)){k++;}
 209						else{break;}
 210				}
 211				seq_inY_w[i][j]='\0';
 212			}
 213	}
 214	public void getTime() {
 215		Calendar cal = Calendar.getInstance();
 216	    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SS");
 217		System.out.println(sdf.format(cal.getTime()));
 218	}
 219	public void compute(){
 220		int i, j;
 221		int n_x, n_y;
 222		char c;
 223		String sNmer = new String();
 224		boolean okay = true;
 225		
 226		/*
 227			Sean
 228		*/
 229		frame.progressBar.setStringPainted(true);
 230		frame.progressBar.setMinimum(0);
 231		frame.progressBar.setMaximum(w_num_Y+w_num_X+w_num_X);
 232		
 233		///---------------------------X
 234		
 235		for(n_x=0;n_x<w_num_X;n_x++){
 236			i=-1;
 237			for(;;){
 238				i++;
 239				if(seq_inX_w[n_x][i]=='\0') {break;}
 240				c=seq_inX_w[n_x][i];
 241				if(c=='a'||c=='A'){sNmer+="00";}
 242					else if(c=='t'||c=='T'){sNmer+="01";}
 243					else if(c=='g'||c=='G'){sNmer+="10";}
 244					else if(c=='c'||c=='C'){sNmer+="11";}
 245					else continue;
 246
 247				
 248				for(j=1;j<nmer_size;j++){
 249					i++;
 250					if(seq_inX_w[n_x][i]=='\0'){break;}
 251					c=seq_inX_w[n_x][i];
 252
 253					okay=true;
 254					if(c=='a'||c=='A'){sNmer+="00";}
 255						else if(c=='t'||c=='T'){sNmer+="01";}
 256						else if(c=='g'||c=='G'){sNmer+="10";}
 257						else if(c=='c'||c=='C'){sNmer+="11";}
 258						else okay=false;
 259					
 260					if(!okay){j=nmer_size;}
 261					
 262				} //first nmer found
 263				
 264				if(okay){
 265				nmer_counts_X[n_x][Integer.parseInt(sNmer,2)]++;
 266				}
 267				
 268				if(use_complementary&&okay){nmer_counts_X[n_x][Integer.parseInt(giveR_ComplementX(n_x,i),2)]++;}
 269				
 270				for(;;){
 271					i++;
 272					if(seq_inX_w[n_x][i]=='\0') {
 273						i--;
 274						break; }
 275					
 276					c=seq_inX_w[n_x][i];
 277					if(c=='a'||c=='A'){sNmer=sNmer.substring(2);sNmer+="00";}
 278						else if(c=='t'||c=='T'){sNmer=sNmer.substring(2);sNmer+="01";}
 279						else if(c=='g'||c=='G'){sNmer=sNmer.substring(2);sNmer+="10";}
 280						else if(c=='c'||c=='C'){sNmer=sNmer.substring(2);sNmer+="11";}
 281						else break;
 282
 283					
 284					nmer_counts_X[n_x][Integer.parseInt(sNmer,2)]++;
 285					if(use_complementary){nmer_counts_X[n_x][Integer.parseInt(giveR_ComplementX(n_x,i),2)]++;}
 286					
 287				}
 288				
 289				sNmer = new String();
 290				
 291			}
 292			
 293			for(int nmer_i=0;nmer_i<num_possible_nmers;nmer_i++){
 294				w_meanVals_X[n_x]+=nmer_counts_X[n_x][nmer_i]; }
 295
 296			if(w_meanVals_X[n_x]<min_num_nmers_in_w) {valid_X[n_x]=true; continue;}
 297			if(w_meanVals_X[n_x]/i<min_percent_nt_in_w) {valid_X[n_x]=true; continue;}
 298			
 299			w_meanVals_X[n_x] = w_meanVals_X[n_x]/num_possible_nmers; 
 300			
 301			pcs.firePropertyChange("progress", null, n_x);	// progressbar stuff
 302		
 303		}//end window loop
 304		
 305		///---------------------Y
 306		sNmer = new String();
 307		
 308		for(n_y=0;n_y<w_num_Y;n_y++){ 
 309			i=-1;
 310			for(;;){
 311				i++;
 312				if(seq_inY_w[n_y][i]=='\0'){break;}
 313				c=seq_inY_w[n_y][i];
 314				if(c=='a'||c=='A'){sNmer+="00";}
 315					else if(c=='t'||c=='T'){sNmer+="01";}
 316					else if(c=='g'||c=='G'){sNmer+="10";}
 317					else if(c=='c'||c=='C'){sNmer+="11";}
 318					else continue;
 319
 320				
 321				for(j=1;j<nmer_size;j++){
 322					i++;
 323					if(seq_inY_w[n_y][i]=='\0')break;
 324					c=seq_inY_w[n_y][i];
 325
 326					okay=true;
 327					if(c=='a'||c=='A'){sNmer+="00";}
 328						else if(c=='t'||c=='T'){sNmer+="01";}
 329						else if(c=='g'||c=='G'){sNmer+="10";}
 330						else if(c=='c'||c=='C'){sNmer+="11";}
 331						else okay=false;
 332					
 333					if(!okay){j=nmer_size;}
 334					
 335				}//found first nmer
 336				
 337				if(okay){
 338				nmer_counts_Y[n_y][Integer.parseInt(sNmer,2)]++;
 339				}
 340				if(use_complementary&&okay){nmer_counts_Y[n_y][Integer.parseInt(giveR_ComplementY(n_y,i),2)]++;}
 341				
 342				for(;;){
 343					i++;
 344					if(seq_inY_w[n_y][i]=='\0') {
 345						i--;
 346						break; }
 347					
 348					c=seq_inY_w[n_y][i];
 349					if(c=='a'||c=='A'){sNmer=sNmer.substring(2);sNmer+="00";}
 350						else if(c=='t'||c=='T'){sNmer=sNmer.substring(2);sNmer+="01";}
 351						else if(c=='g'||c=='G'){sNmer=sNmer.substring(2);sNmer+="10";}
 352						else if(c=='c'||c=='C'){sNmer=sNmer.substring(2);sNmer+="11";}
 353						else break;
 354					
 355					nmer_counts_Y[n_y][Integer.parseInt(sNmer,2)]++;
 356					if(use_complementary){nmer_counts_Y[n_y][Integer.parseInt(giveR_ComplementY(n_y,i),2)]++;}
 357					
 358				}
 359				
 360				sNmer = new String();
 361				
 362			}
 363			for(int nmer_i=0;nmer_i<num_possible_nmers;nmer_i++){w_meanVals_Y[n_y]+=nmer_counts_Y[n_y][nmer_i];}
 364
 365			if(w_meanVals_Y[n_y]<min_num_nmers_in_w){valid_Y[n_y]=true; continue;}
 366			if(w_meanVals_Y[n_y]/i<min_percent_nt_in_w){valid_Y[n_y]=true; continue;}
 367			
 368			w_meanVals_Y[n_y] = w_meanVals_Y[n_y]/num_possible_nmers; 
 369		
 370			pcs.firePropertyChange("progress", null, (w_num_X + n_y)); // progressbar
 371			
 372		}//end of window loop
 373
 374		///Computations-----------X 
 375		for(n_x=0;n_x<w_num_X;n_x++)		// for each window on X axis loop
 376			for(int nmer_i=0;nmer_i<num_possible_nmers;nmer_i++)
 377			{
 378				if(valid_X[n_x]) continue;
 379					nmer_counts_X[n_x][nmer_i]=nmer_counts_X[n_x][nmer_i]-w_meanVals_X[n_x];
 380					X_square[n_x]+=nmer_counts_X[n_x][nmer_i]*nmer_counts_X[n_x][nmer_i];
 381			}
 382
 383		///Computations------------Y
 384		for(n_y=0;n_y<w_num_Y;n_y++)		// for each window on Y axis loop
 385			for(int nmer_i=0;nmer_i<num_possible_nmers;nmer_i++)
 386			{
 387				if(valid_Y[n_y]) continue;
 388					nmer_counts_Y[n_y][nmer_i]=nmer_counts_Y[n_y][nmer_i]-w_meanVals_Y[n_y];
 389					Y_square[n_y]+=nmer_counts_Y[n_y][nmer_i]*nmer_counts_Y[n_y][nmer_i];
 390			}
 391	//Computations------------Score
 392		float minScore=0;
 393		boolean firstTime=true;
 394		for(n_x=0;n_x<w_num_X;n_x++){		// for each window on X axis loop
 395			for(n_y=0;n_y<w_num_Y;n_y++)		// for each window on Y axis loop
 396			{
 397				if(valid_X[n_x]){continue;}
 398				if(valid_Y[n_y]){continue;}
 399
 400				for(int nmer_i=0;nmer_i<num_possible_nmers;nmer_i++)
 401							score[n_x][n_y]+=nmer_counts_X[n_x][nmer_i]*nmer_counts_Y[n_y][nmer_i];
 402
 403				score[n_x][n_y]=score[n_x][n_y]/(float)Math.sqrt((X_square[n_x]*Y_square[n_y]));
 404				
 405				if(firstTime){minScore=score[n_x][n_y]; firstTime=false;}
 406				if(score[n_x][n_y]<minScore){minScore=score[n_x][n_y];}
 407
 408			}
 409			
 410			pcs.firePropertyChange("progress", null, (w_num_X + w_num_Y + n_x)); // progressbar
 411			
 412		}
 413
 414		//-----------------------Clear memory 
 415		valid_X = null;
 416		valid_Y = null;
 417		nmer_counts_X = null;
 418		nmer_counts_Y = null;
 419		w_meanVals_X = null;
 420		w_meanVals_Y = null;
 421		X_square = null;    
 422		Y_square = null;
 423		
 424	}
 425	
 426	public void Prepare_Sequences_var_window_X(String xSequence, String xGenes)
 427	{
 428		int i,j,k,l,m;
 429		boolean overOrigin=false;
 430		
 431		//genes for sequence x
 432		File f_g = new File(xGenes);
 433		BufferedReader in = getReader(f_g);
 434		
 435		String line = getLine(in); //gets the first line
 436		line=getLine(in); //gets the number of genes + word protein
 437		String [] result = line.split(" ");
 438		w_num_X=Integer.parseInt(result[0]);
 439		
 440		int[][] w_pos=new int [w_num_X][2];
 441		X_geneSynonyms = new String [w_num_X];
 442		boolean[] strand=new boolean [w_num_X];
 443		line=getLine(in);	//gets the column headings
 444		for(i=0; i<w_num_X; i++)
 445		{
 446			line=getLine(in);	//gets a gene
 447			j=line.indexOf("."); //location of end of start
 448			k=line.indexOf("\t"); //location of end of end
 449			l=line.indexOf("\t",k+1); 
 450			l=line.indexOf("\t",l+1); 
 451			l=line.indexOf("\t",l+1); 
 452			l=line.indexOf("\t",l+1); 
 453			l=line.indexOf("\t",l+1);
 454			m=line.lastIndexOf("\t",l-1); 
 455			result[0]=line.substring(0,j);
 456			w_pos[i][0]=Integer.parseInt(result[0]);
 457			w_pos[i][0]--;
 458			result[0]=line.substring(j+2,k);
 459			w_pos[i][1]=Integer.parseInt(result[0]);
 460			w_pos[i][1]--;
 461			result[0]=line.substring(k+1,k+2);
 462			if(result[0]=="+") strand[i]=true;
 463			else strand[i]=false;
 464			X_geneSynonyms[i]=line.substring(m+1,l);
 465		}
 466		
 467		//sequence x
 468		File f_s = new File(xSequence);
 469		in = getReader(f_s);
 470		
 471		StringBuilder sb = new StringBuilder();
 472		X_header = getLine(in);
 473		while(line!=null)
 474		{
 475			line=getLine(in);
 476			if(line!=null)
 477			{
 478				len_X += (long)line.length();
 479				sb.append(line);
 480			}
 481		}
 482		StringBuilder sb2 = sb; 
 483		
 484		//set up arrays
 485		seq_inX_w=new char [w_num_X][];
 486
 487		for(i=0; i<w_num_X; i++)
 488		{
 489			if(w_pos[i][1]>=w_pos[i][0])
 490			{
 491				seq_inX_w[i]=new char[(w_pos[i][1]-w_pos[i][0]+2)]; //why add two?
 492				overOrigin=false;
 493			}
 494			else
 495			{
 496				seq_inX_w[i]=new char[(len_X-w_pos[i][0])+w_pos[i][1]+2]; //changed from (length-end)+start to (length-start)+end! -vinnie 
 497				overOrigin=true;
 498			}
 499		}
 500		for(i=0; i<w_num_X; i++)
 501		{
 502			if(strand[i]) //original strand
 503			{
 504				if(overOrigin==false) 
 505				{
 506					for(j=0; j<w_pos[i][1]-w_pos[i][0]+1; j++){
 507						seq_inX_w[i][j]=sb2.charAt(w_pos[i][0]+j);
 508					}
 509					seq_inX_w[i][j]='\0';
 510				}
 511				else
 512				{
 513					k=0;
 514					for(j=w_pos[i][0]; j<len_X; j++)
 515					{
 516						seq_inX_w[i][k]=sb2.charAt(j);
 517						k++;
 518					}
 519					for(j=0; j<=w_pos[i][1]; j++)
 520					{
 521						seq_inX_w[i][k]=sb2.charAt(j);
 522						k++;
 523					}
 524					seq_inX_w[i][k]='\0';
 525				}
 526			}
 527			else //complementary strand
 528			{
 529				if(overOrigin==false)
 530				{
 531					for(j=0; j<w_pos[i][1]-w_pos[i][0]+1; j++)
 532					{
 533						seq_inX_w[i][j]=sb2.charAt(w_pos[i][1]-w_pos[i][0]-j); 
 534						switch(seq_inX_w[i][j]){
 535						case 'a': case 'A': seq_inX_w[i][j]='T'; break;
 536						case 't': case 'T': seq_inX_w[i][j]='A'; break;
 537						case 'g': case 'G': seq_inX_w[i][j]='C'; break;
 538						case 'c': case 'C': seq_inX_w[i][j]='G'; break;
 539						default: seq_inX_w[i][j]='N';
 540						}
 541					}
 542					seq_inX_w[i][j]='\0';
 543				}
 544				else 
 545				{
 546					k=0;
 547					j=w_pos[i][1];
 548					while(j>=0)
 549					{
 550						seq_inX_w[i][k]= sb2.charAt(j);
 551						j--;
 552						switch(seq_inX_w[i][k]){
 553						case 'a': case 'A': seq_inX_w[i][k]='T'; break;
 554						case 't': case 'T': seq_inX_w[i][k]='A'; break;
 555						case 'g': case 'G': seq_inX_w[i][k]='C'; break;
 556						case 'c': case 'C': seq_inX_w[i][k]='G'; break;
 557						default: seq_inX_w[i][k]='N';
 558						}
 559						k++;
 560					}
 561					for(j=len_X-1; j>=w_pos[i][0]; j--)
 562					{
 563						seq_inX_w[i][k]=sb2.charAt(j);
 564						switch(seq_inX_w[i][k]){
 565						case 'a': case 'A': seq_inX_w[i][k]='T'; break;
 566						case 't': case 'T': seq_inX_w[i][k]='A'; break;
 567						case 'g': case 'G': seq_inX_w[i][k]='C'; break;
 568						case 'c': case 'C': seq_inX_w[i][k]='G'; break;
 569						default: seq_inX_w[i][k]='N';
 570						}
 571						k++;
 572					}
 573					seq_inX_w[i][k]='\0';
 574				} 
 575			}
 576		}
 577	}
 578	public void Prepare_Sequences_var_window_Y(String ySequence, String yGenes)
 579	{
 580		int i,j,k,l,m;
 581		boolean overOrigin=false;
 582		
 583		//genes for sequence y
 584		File f_g = new File(yGenes);
 585		BufferedReader in = getReader(f_g);
 586		
 587		String line = getLine(in); //gets the first line
 588		line=getLine(in); //gets the number of genes + word protein
 589		String [] result = line.split(" ");
 590		w_num_Y=Integer.parseInt(result[0]);
 591		
 592		int[][] w_pos=new int [w_num_Y][2];
 593		boolean[] strand=new boolean [w_num_Y];
 594		Y_geneSynonyms = new String [w_num_Y];
 595		
 596		line=getLine(in);	//get the column headings
 597		for(i=0; i<w_num_Y; i++)
 598		{
 599			line=getLine(in);	//gets a gene
 600			j=line.indexOf("."); //location of end of start
 601			k=line.indexOf("\t"); //location of end of end
 602			l=line.indexOf("\t",k+1); 
 603			l=line.indexOf("\t",l+1); 
 604			l=line.indexOf("\t",l+1); 
 605			l=line.indexOf("\t",l+1); 
 606			l=line.indexOf("\t",l+1);
 607			m=line.lastIndexOf("\t",l-1);
 608			result[0]=line.substring(0,j);
 609			w_pos[i][0]=Integer.parseInt(result[0]);
 610			w_pos[i][0]--;
 611			result[0]=line.substring(j+2,k);
 612			w_pos[i][1]=Integer.parseInt(result[0]);
 613			w_pos[i][1]--;
 614			result[0]=line.substring(k+1,k+2);
 615			if(result[0]=="+") strand[i]=true;
 616			else strand[i]=false;
 617			Y_geneSynonyms[i]=line.substring(m+1,l);
 618		}
 619		
 620		//sequence y
 621		File f_s = new File(ySequence);
 622		in = getReader(f_s);
 623		
 624		StringBuilder sb = new StringBuilder();
 625		Y_header = getLine(in);
 626		while(line!=null)
 627		{
 628			line=getLine(in);
 629			if(line!=null)
 630			{
 631				len_Y += (long)line.length();
 632				sb.append(line);
 633			}
 634		}
 635		StringBuilder sb2 = sb; 
 636		
 637		//set up the array ready to read in
 638		seq_inY_w=new char [w_num_Y][];
 639		for(i=0; i<w_num_Y; i++)
 640		{
 641			if(w_pos[i][1]>=w_pos[i][0])
 642			{
 643				seq_inY_w[i]=new char[(w_pos[i][1]-w_pos[i][0]+2)];
 644				overOrigin=false;
 645			}
 646			else
 647			{
 648				seq_inY_w[i]=new char[(len_Y-w_pos[i][0])+w_pos[i][1]+2];
 649				overOrigin=true;
 650			}
 651		}
 652		for(i=0; i<w_num_Y; i++)
 653		{
 654			if(strand[i]) //original strand
 655			{
 656				if(overOrigin==false)
 657				{
 658					for(j=0; j<w_pos[i][1]-w_pos[i][0]+1; j++){
 659					seq_inY_w[i][j]=sb2.charAt(w_pos[i][0]+j);
 660					}
 661					seq_inY_w[i][j]='\0';
 662				}
 663				else
 664				{
 665					k=0;
 666					for(j=w_pos[i][0]; j<len_Y; j++)
 667					{
 668						seq_inY_w[i][k]=sb2.charAt(j);
 669						k++;
 670					}
 671					for(j=0; j<=w_pos[i][1]; j++)
 672					{
 673						seq_inY_w[i][k]=sb2.charAt(j);
 674						k++;
 675					}
 676					seq_inY_w[i][k]='\0';
 677				}
 678			}
 679			else //complementary strand
 680			{
 681				if(overOrigin==false)
 682				{
 683					for(j=0; j<w_pos[i][1]-w_pos[i][0]+1; j++)
 684					{
 685						seq_inY_w[i][j]=sb2.charAt(w_pos[i][1]-w_pos[i][0]-j);
 686						switch(seq_inY_w[i][j]){
 687						case 'a': case 'A': seq_inY_w[i][j]='T'; break;
 688						case 't': case 'T': seq_inY_w[i][j]='A'; break;
 689						case 'g': case 'G': seq_inY_w[i][j]='C'; break;
 690						case 'c': case 'C': seq_inY_w[i][j]='G'; break;
 691						default: seq_inY_w[i][j]='N';
 692						}
 693					}
 694					seq_inY_w[i][j]='\0';
 695				}
 696				else
 697				{
 698					k=0;
 699					j=w_pos[i][1];
 700					
 701					while(j>=0)
 702					{
 703						seq_inY_w[i][k]= sb2.charAt(j);
 704						j--;
 705						switch(seq_inY_w[i][k]){
 706						case 'a': case 'A': seq_inY_w[i][k]='T'; break;
 707						case 't': case 'T': seq_inY_w[i][k]='A'; break;
 708						case 'g': case 'G': seq_inY_w[i][k]='C'; break;
 709						case 'c': case 'C': seq_inY_w[i][k]='G'; break;
 710						default: seq_inY_w[i][k]='N';
 711						}
 712						k++;
 713					}
 714					for(j=len_Y-1; j>=w_pos[i][0]; j--)
 715					{
 716						seq_inY_w[i][k]=sb2.charAt(j);
 717						switch(seq_inY_w[i][k]){
 718						case 'a': case 'A': seq_inY_w[i][k]='T'; break;
 719						case 't': case 'T': seq_inY_w[i][k]='A'; break;
 720						case 'g': case 'G': seq_inY_w[i][k]='C'; break;
 721						case 'c': case 'C': seq_inY_w[i][k]='G'; break;
 722						default: seq_inY_w[i][k]='N';
 723						}
 724						k++;
 725					}
 726					seq_inY_w[i][k]='\0';
 727				} 
 728			}
 729		}
 730	}
 731	public void S_Plot_Correlation_var_windows()
 732	{
 733		int i, j;
 734		int n_x, n_y;
 735		char c;
 736		String sNmer = new String();
 737		boolean okay = true;
 738		
 739		frame.progressBar.setStringPainted(true);
 740		frame.progressBar.setMinimum(0);
 741		frame.progressBar.setMaximum(w_num_Y+w_num_X+w_num_X);
 742		
 743		///---------------------------X
 744		for(n_x=0;n_x<w_num_X;n_x++){
 745			i=-1;
 746			for(;;){
 747				i++;
 748				if(seq_inX_w[n_x][i]=='\0') {break;}
 749				c=seq_inX_w[n_x][i];
 750				if(c=='a'||c=='A'){sNmer+="00";}
 751					else if(c=='t'||c=='T'){sNmer+="01";}
 752					else if(c=='g'||c=='G'){sNmer+="10";}
 753					else if(c=='c'||c=='C'){sNmer+="11";}
 754					else continue;
 755
 756				
 757				for(j=1;j<nmer_size;j++){
 758					i++;
 759					if(seq_inX_w[n_x][i]=='\0'){break;}
 760					c=seq_inX_w[n_x][i];
 761
 762					okay=true;
 763					if(c=='a'||c=='A'){sNmer+="00";}
 764						else if(c=='t'||c=='T'){sNmer+="01";}
 765						else if(c=='g'||c=='G'){sNmer+="10";}
 766						else if(c=='c'||c=='C'){sNmer+="11";}
 767						else okay=false;
 768					
 769					if(!okay){j=nmer_size;}
 770					
 771				} //first nmer found
 772				
 773				if(okay){
 774				nmer_counts_X[n_x][Integer.parseInt(sNmer,2)]++;
 775				}
 776				
 777				if(use_complementary&&okay){nmer_counts_X[n_x][Integer.parseInt(giveR_ComplementX(n_x,i),2)]++;}
 778				
 779				for(;;){
 780					i++;
 781					if(seq_inX_w[n_x][i]=='\0') {
 782						i--;
 783						break; }
 784					
 785					c=seq_inX_w[n_x][i];
 786					if(c=='a'||c=='A'){sNmer=sNmer.substring(2);sNmer+="00";}
 787					else if(c=='t'||c=='T'){sNmer=sNmer.substring(2);sNmer+="01";}
 788					else if(c=='g'||c=='G'){sNmer=sNmer.substring(2);sNmer+="10";}
 789					else if(c=='c'||c=='C'){sNmer=sNmer.substring(2);sNmer+="11";}
 790					else break;
 791					
 792					nmer_counts_X[n_x][Integer.parseInt(sNmer,2)]++;
 793					if(use_complementary){nmer_counts_X[n_x][Integer.parseInt(giveR_ComplementX(n_x,i),2)]++;}	
 794				}
 795				sNmer = new String();
 796			}
 797
 798			//validation checks
 799			for(int nmer_i=0;nmer_i<num_possible_nmers;nmer_i++){w_meanVals_X[n_x]+=nmer_counts_X[n_x][nmer_i];}
 800			if(w_meanVals_X[n_x]<min_num_nmers_in_w) {valid_X[n_x]=true; continue;}
 801			if(w_meanVals_X[n_x]/i<min_percent_nt_in_w) {valid_X[n_x]=true; continue;}
 802			
 803			//take % because other variable window may be significantly different size
 804			w_meanVals_X[n_x]=0;
 805			for(int nmer_i=0;nmer_i<num_possible_nmers;nmer_i++)
 806			{
 807				nmer_counts_X[n_x][nmer_i]=(nmer_counts_X[n_x][nmer_i]/(float)i);
 808				w_meanVals_X[n_x]+=nmer_counts_X[n_x][nmer_i];
 809			}
 810			w_meanVals_X[n_x]=w_meanVals_X[n_x]/num_possible_nmers;
 811		
 812			pcs.firePropertyChange("progress", null, n_x);	// progressbar stuff
 813			
 814		}//end window loop
 815		
 816		///---------------------Y
 817		sNmer = new String();
 818		for(n_y=0;n_y<w_num_Y;n_y++){ 
 819			i=-1;
 820			for(;;){
 821				i++;
 822				if(seq_inY_w[n_y][i]=='\0'){break;}
 823				c=seq_inY_w[n_y][i];
 824				if(c=='a'||c=='A'){sNmer+="00";}
 825					else if(c=='t'||c=='T'){sNmer+="01";}
 826					else if(c=='g'||c=='G'){sNmer+="10";}
 827					else if(c=='c'||c=='C'){sNmer+="11";}
 828					else continue;
 829
 830				
 831				for(j=1;j<nmer_size;j++){
 832					i++;
 833					if(seq_inY_w[n_y][i]=='\0')break;
 834					c=seq_inY_w[n_y][i];
 835
 836					okay=true;
 837					if(c=='a'||c=='A'){sNmer+="00";}
 838						else if(c=='t'||c=='T'){sNmer+="01";}
 839						else if(c=='g'||c=='G'){sNmer+="10";}
 840						else if(c=='c'||c=='C'){sNmer+="11";}
 841						else okay=false;
 842					
 843					if(!okay){j=nmer_size;}
 844					
 845				}//found first nmer
 846				
 847				if(okay){
 848				nmer_counts_Y[n_y][Integer.parseInt(sNmer,2)]++;
 849				}
 850				if(use_complementary&&okay){nmer_counts_Y[n_y][Integer.parseInt(giveR_ComplementY(n_y,i),2)]++;}
 851				
 852				for(;;){
 853					i++;
 854					if(seq_inY_w[n_y][i]=='\0') {
 855						i--;
 856						break; }
 857					
 858					c=seq_inY_w[n_y][i];
 859					if(c=='a'||c=='A'){sNmer=sNmer.substring(2);sNmer+="00";}
 860						else if(c=='t'||c=='T'){sNmer=sNmer.substring(2);sNmer+="01";}
 861						else if(c=='g'||c=='G'){sNmer=sNmer.substring(2);sNmer+="10";}
 862						else if(c=='c'||c=='C'){sNmer=sNmer.substring(2);sNmer+="11";}
 863						else break;
 864					
 865					nmer_counts_Y[n_y][Integer.parseInt(sNmer,2)]++;
 866					if(use_complementary){nmer_counts_Y[n_y][Integer.parseInt(giveR_ComplementY(n_y,i),2)]++;}
 867					
 868				}
 869				
 870				sNmer = new String();
 871				
 872			}
 873			//validation
 874			for(int nmer_i=0;nmer_i<num_possible_nmers;nmer_i++){w_meanVals_Y[n_y]+=nmer_counts_Y[n_y][nmer_i];}
 875			if(w_meanVals_Y[n_y]<min_num_nmers_in_w){valid_Y[n_y]=true; continue;}
 876			if(w_meanVals_Y[n_y]/i<min_percent_nt_in_w){valid_Y[n_y]=true; continue;}
 877
 878			//take % because other variable window may be significantly different size
 879			w_meanVals_Y[n_y]=0;
 880			for(int nmer_i=0;nmer_i<num_possible_nmers;nmer_i++)
 881			{
 882				nmer_counts_Y[n_y][nmer_i]=(nmer_counts_Y[n_y][nmer_i]/(float)i);
 883				w_meanVals_Y[n_y]+=nmer_counts_Y[n_y][nmer_i];
 884			}			
 885			w_meanVals_Y[n_y] = w_meanVals_Y[n_y]/num_possible_nmers;
 886			
 887			pcs.firePropertyChange("progress", null, (w_num_X + n_y)); // progressbar
 888			
 889		}//end of window loop
 890
 891	///Computations-----------X 
 892		for(n_x=0;n_x<w_num_X;n_x++)		// for each window on X axis loop
 893			for(int nmer_i=0;nmer_i<num_possible_nmers;nmer_i++)
 894			{
 895				if(valid_X[n_x]) continue;
 896					nmer_counts_X[n_x][nmer_i]=nmer_counts_X[n_x][nmer_i]-w_meanVals_X[n_x];
 897					X_square[n_x]+=nmer_counts_X[n_x][nmer_i]*nmer_counts_X[n_x][nmer_i];
 898			}
 899		
 900	///Computations------------Y
 901		for(n_y=0;n_y<w_num_Y;n_y++)		// for each window on Y axis loop
 902			for(int nmer_i=0;nmer_i<num_possible_nmers;nmer_i++)
 903			{
 904				if(valid_Y[n_y]) continue;
 905					nmer_counts_Y[n_y][nmer_i]=nmer_counts_Y[n_y][nmer_i]-w_meanVals_Y[n_y];
 906					Y_square[n_y]+=nmer_counts_Y[n_y][nmer_i]*nmer_counts_Y[n_y][nmer_i];
 907			}
 908
 909
 910	//Computations------------Score
 911		for(n_x=0;n_x<w_num_X;n_x++){		// for each window on X axis loop
 912			for(n_y=0;n_y<w_num_Y;n_y++)		// for each window on Y axis loop
 913			{
 914				if(valid_X[n_x]){continue;}
 915				if(valid_Y[n_y]){continue;}
 916
 917				for(int nmer_i=0;nmer_i<num_possible_nmers;nmer_i++)
 918							score[n_x][n_y]+=nmer_counts_X[n_x][nmer_i]*nmer_counts_Y[n_y][nmer_i];
 919
 920				score[n_x][n_y]=score[n_x][n_y]/(float)Math.sqrt((X_square[n_x]*Y_square[n_y]));
 921			}
 922			
 923			pcs.firePropertyChange("progress", null, (w_num_X + w_num_Y + n_x)); // progressbar
 924			
 925		}
 926		
 927	//-----------------------Clear memory 
 928		valid_X = null;
 929		valid_Y = null;
 930		nmer_counts_X = null;
 931		nmer_counts_Y = null;
 932		w_meanVals_X = null;
 933		w_meanVals_Y = null;
 934		X_square = null;    
 935		Y_square = null;
 936
 937	}	
 938
 939	public void writeScoreMatrix(String writeLocation){
 940		String f_score = writeLocation;
 941		File F_score = new File(f_score);
 942		try{
 943			if(F_score.createNewFile()){System.out.println("File F_score was created");}
 944				else{System.out.println("File F_score was not created");}
 945		}
 946		catch(IOException e){System.out.println("I/O Error: writeScoreMatrix");}
 947		
 948		PrintWriter out = openWriter(F_score);
 949		
 950		Calendar cal = Calendar.getInstance();
 951	    DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.MEDIUM);
 952		
 953		out.print("Pearson Correlation Values");
 954		out.println("\t\t\t" + df.format(cal.getTime()));
 955		out.println();
 956		out.println("Sequence X:\t" + X_header);
 957		out.println("Sequence Y:\t" + Y_header);
 958		out.println();
 959		out.println("Window Size:\t" + w_size);
 960		out.println("Nmer Size:\t" + nmer_size);
 961		out.println("Compl. considered:\t" + use_complementary);
 962		out.println();
 963		out.println();
 964		out.println();		
 965		
 966		out.print("\t0");
 967		for(int p=1;p<w_num_Y;p++){out.print("\t"+p);}
 968		out.println();
 969		
 970		for(int k=0; k<w_num_X; k++){
 971			StringBuilder sb2 = new StringBuilder();
 972			sb2.append(k);
 973			for(int l=0;l<w_num_Y;l++){
 974				String v = "\t" + score[k][l];
 975				sb2.append(v);
 976				if(l==(w_num_Y-1)){out.println(sb2);}
 977				}
 978			}
 979		out.close();
 980	}
 981	public void writeGeneMatrix(String writeLocation){
 982		String f_geneMatrix = writeLocation;
 983		File F_geneMatrix = new File(f_geneMatrix);
 984		try{
 985			if(F_geneMatrix.createNewFile()){System.out.println("File F_geneMatrix was created");}
 986				else{System.out.println("File F_geneMatrix was not created");}
 987		}
 988		catch(IOException e){System.out.println("I/O Error: writeGeneMatrix");}
 989		
 990		PrintWriter out = openWriter(F_geneMatrix);
 991		
 992		Calendar cal = Calendar.getInstance();
 993	    DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.MEDIUM);
 994		
 995		out.print("Pearson Correlation Gene Values");
 996		out.println("\t\t\t" + df.format(cal.getTime()));
 997		out.println();
 998		out.println("Sequence X:\t" + X_header);
 999		out.println("Sequence Y:\t" + Y_header);
1000		out.println();
1001		out.println("Nmer Size:\t3");
1002		out.println("Compl. considered:\t" + use_complementary);
1003		out.println();
1004		out.println();
1005		out.println();		
1006		
1007		String syn;
1008		for(int p=0;p<w_num_Y;p++){
1009			 syn = Y_geneSynonyms[p];
1010			 out.print("\t"+syn);
1011			}
1012		out.println();
1013		
1014		for(int k=0; k<w_num_X; k++){
1015			StringBuilder sb2 = new StringBuilder();
1016			syn = X_geneSynonyms[k];
1017			sb2.append(syn);
1018			for(int l=0;l<w_num_Y;l++){
1019				String v = "\t" + score[k][l];
1020				sb2.append(v);
1021				if(l==(w_num_Y-1)){out.println(sb2);}
1022				}
1023			}
1024		out.close();
1025	}	
1026	public void write_Avg_Stdev(String writeLocation){
1027		calcAvg_window_Corr();
1028		stdev_pearCorrX = new float [w_num_X];
1029		stdev_pearCorrY = new float [w_num_Y];
1030		
1031		String f_avg_stdev = writeLocation;
1032		File F_avg_stdev = new File(f_avg_stdev);
1033		try{
1034			if(F_avg_stdev.createNewFile()){System.out.println("File F_avg_stdev was created");}
1035				else{System.out.println("File F_avg_stdev was not created");}
1036		}
1037		catch(IOException e){System.out.println("I/O Error: write_Avg_Stdev");}
1038		
1039		PrintWriter out = openWriter(F_avg_stdev);
1040		
1041		Calendar cal = Calendar.getInstance();
1042	    DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.MEDIUM);
1043		
1044		out.print("Average and Standard Deviations");
1045		out.println("\t\t\t" + df.format(cal.getTime()));
1046		out.println();
1047		out.println("Sequence X:\t" + X_header);
1048		out.println("Sequence Y:\t" + Y_header);
1049		out.println();
1050		out.println("Window Size:\t" + w_size);
1051		out.println("Nmer Size:\t" + nmer_size);
1052		out.println("Compl. considered:\t" + use_complementary);
1053		out.println();
1054		out.println();
1055		out.println();
1056		
1057		out.println("Sequence X:");
1058		out.println("Window\tAvg\tStdev");
1059		
1060		float sum_of_the_difference=0;
1061		for(int i=0;i<w_num_X;i++){
1062			for(int j=0;j<w_num_Y;j++){
1063				sum_of_the_difference+=Math.abs(score[i][j]-avgCorrX[i]);
1064			}
1065			stdev_pearCorrX[i]=sum_of_the_difference/(float)w_num_Y;
1066			sum_of_the_difference=0;
1067		}
1068		
1069		sum_of_the_difference=0;
1070		for(int i=0;i<w_num_Y;i++){
1071			for(int j=0;j<w_num_X;j++){
1072				sum_of_the_difference+=Math.abs(score[j][i]-avgCorrY[i]);
1073			}
1074			stdev_pearCorrY[i]=sum_of_the_difference/(float)w_num_X;
1075			sum_of_the_difference=0;
1076		}
1077		
1078		for(int i=0;i<w_num_X;i++){
1079			out.println(i+"\t"+avgCorrX[i]+"\t"+stdev_pearCorrX[i]);
1080		}
1081		
1082		out.println();
1083		out.println();
1084		out.println("Sequence Y:");
1085		out.println("Window\tAvg\tStdev");
1086		for(int i=0;i<w_num_Y;i++){
1087			out.println(i+"\t"+avgCorrY[i]+"\t"+stdev_pearCorrY[i]);
1088		}
1089
1090		avgCorrX = null;
1091		avgCorrY = null;
1092		stdev_pearCorrX = null;
1093		stdev_pearCorrY = null;
1094		out.close();
1095	}
1096	public void write_Gene_Avg_Stdev(String writeLocation){
1097		calcAvg_window_Corr();
1098		String f_gene_avg_stdev = writeLocation;
1099		File F_gene_avg_stdev = new File(f_gene_avg_stdev);
1100		try{
1101			if(F_gene_avg_stdev.createNewFile()){System.out.println("File F_gene_avg_stdev was created");}
1102				else{System.out.println("File F_gene_avg_stdev was not created");}
1103		}
1104		catch(IOException e){System.out.println("I/O Error: write_Gene_Avg_Stdev");}
1105		
1106		PrintWriter out = openWriter(F_gene_avg_stdev);
1107		
1108		Calendar cal = Calendar.getInstance();
1109	    DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.MEDIUM);
1110		
1111		out.print("Gene Average and Standard Deviations");
1112		out.println("\t\t\t" + df.format(cal.getTime()));
1113		out.println();
1114		out.println("Sequence X:\t" + X_header);
1115		out.println("Sequence Y:\t" + Y_header);
1116		out.println();
1117		out.println("Nmer Size:\t" + 3);
1118		out.println("Compl. considered:\t" + use_complementary);
1119		out.println();
1120		out.println();
1121		out.println();
1122		
1123		out.println("Sequence X:");
1124		out.println("Gene\tAvg\tStdev");
1125		
1126		//finding stdev of each window in Sequence X 
1127		float sum_of_the_difference=0;
1128		for(int i=0;i<w_num_X;i++){
1129			for(int j=0;j<w_num_Y;i++){
1130				sum_of_the_difference+=Math.abs(score[i][j]-avgCorrX[i]);
1131			}
1132			stdev_pearCorrX[i]=sum_of_the_difference/(float)w_num_Y;
1133			sum_of_the_difference=0;
1134		}
1135		
1136		//finding stdev of each window in Sequence Y
1137		sum_of_the_difference=0;
1138		for(int i=0;i<w_num_Y;i++){
1139			for(int j=0;j<w_num_X;i++){
1140				sum_of_the_difference+=Math.abs(score[j][i]-avgCorrY[i]);
1141			}
1142			stdev_pearCorrY[i]=sum_of_the_difference/(float)w_num_X;
1143			sum_of_the_difference=0;
1144		}
1145		
1146		//writing out avg and stdev for each window in sequence X
1147		for(int i=0;i<w_num_X;i++){
1148			out.println(X_geneSynonyms[i]+"\t"+avgCorrX[i]+"\t"+stdev_pearCorrX[i]);
1149		}
1150		
1151		out.println();
1152		out.println();
1153		out.println("Sequence Y:");
1154		out.println("Gene\tAvg\tStdev");
1155		
1156		//writing out avg and stdev for each window in sequence Y
1157		for(int i=0;i<w_num_Y;i++){
1158			out.println(Y_geneSynonyms[i]+"\t"+avgCorrY[i]+"\t"+stdev_pearCorrY[i]);
1159		}
1160		out.println();
1161		
1162		avgCorrX = null;
1163		avgCorrY = null;
1164		stdev_pearCorrX = null;
1165		stdev_pearCorrY = null;
1166		out.close();
1167	}
1168	public void write_GC_w_content(String writeLocation){
1169		String f_w_GC_content = writeLocation;
1170		File F_w_GC_content = new File(f_w_GC_content);
1171		try{
1172			if(F_w_GC_content.createNewFile()){System.out.println("File F_w_GC_content was created");}
1173				else{System.out.println("File F_w_GC_content was not created");}
1174		}
1175		catch(IOException e){System.out.println("I/O Error: write_GC_w_content");}
1176		
1177		PrintWriter out = openWriter(F_w_GC_content);
1178		
1179		Calendar cal = Calendar.getInstance();
1180	    DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.MEDIUM);
1181		
1182		out.print("G+C window content");
1183		out.println("\t\t\t" + df.format(cal.getTime()));
1184		out.println();
1185		out.println("Sequence X:\t" + X_header);
1186		out.println("Sequence Y:\t" + Y_header);
1187		out.println();
1188		out.println("Window size:\t"+w_size);
1189		out.println("Nmer Size:\t" + nmer_size);
1190		out.println("Compl. considered:\t" + use_complementary);
1191		out.println();
1192		out.println();
1193		out.println();
1194		out.println("Sequence X:");
1195		out.println("Window\tG+C");
1196		
1197		//writing out the GC content of each window in sequence X
1198		for(int i=0;i<w_num_X;i++){
1199			out.println(i+"\t"+calcGC(i,true));
1200		}
1201		
1202		out.println();
1203		out.println();
1204		out.println("Sequence Y:");
1205		out.println("Window\tG+C");
1206		
1207		//writing out the GC content of each window in sequence Y
1208		for(int i=0;i<w_num_Y;i++){
1209			out.println(i+"\t"+calcGC(i,false));
1210		}
1211		out.println();
1212		out.close();
1213	}
1214	public void write_GC_gene_content(String writeLocation){
1215		
1216		String f_gene_GC_content = writeLocation;
1217		File F_gene_GC_content = new File(f_gene_GC_content);
1218		
1219		try{
1220			if(F_gene_GC_content.createNewFile()){System.out.println("File F_gene_GC_content was created");}
1221				else{System.out.println("File F_gene_GC_content was not created");}
1222		}
1223		catch(IOException e){System.out.println("I/O Error: write_GC_gene_content");}
1224		
1225		PrintWriter out = openWriter(F_gene_GC_content);
1226		
1227		Calendar cal = Calendar.getInstance();
1228	    DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.MEDIUM);
1229		
1230		out.print("G+C gene content");
1231		out.println("\t\t\t" + df.format(cal.getTime()));
1232		out.println();
1233		out.println("Sequence X:\t" + X_header);
1234		out.println("Sequence Y:\t" + Y_header);
1235		out.println();
1236		out.println("Nmer Size:\t" + 3);
1237		out.println("Compl. considered:\t" + use_complementary);
1238		out.println();
1239		out.println();
1240		out.println();
1241		out.println("Sequence X:");
1242		out.println("Gene\tG+C");
1243		
1244		//writing out the GC content of each gene in sequence X
1245		for(int i=0;i<w_num_X;i++){
1246			out.println(X_geneSynonyms[i]+"\t"+calcGC(i,true));
1247		}
1248		
1249		out.println();
1250		out.println();
1251		out.println("Sequence Y:");
1252		out.println("Gene\tG+C");
1253		
1254		//writing out the GC content of each gene in sequence Y
1255		for(int i=0;i<w_num_Y;i++){
1256			out.println(Y_geneSynonyms[i]+"\t"+calcGC(i,false));
1257		}
1258		out.println();
1259		out.close();
1260	}
1261	public void write_max_w_Corr(String writeLocation){
1262		String f_maxCorrs = writeLocation;
1263		File F_maxCorrs = new File(f_maxCorrs);
1264		try{
1265			if(F_maxCorrs.createNewFile()){System.out.println("File F_maxCorrs was created");}
1266				else{System.out.println("File F_maxCorrs was not created");}
1267		}
1268		catch(IOException e){System.out.println("I/O Error: writeScoreMatrix");}
1269		
1270		PrintWriter out = openWriter(F_maxCorrs);
1271		
1272		Calendar cal = Calendar.getInstance();
1273	    DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.MEDIUM);
1274		
1275		out.print("Highest Correlated Windows");
1276		out.println("\t\t\t" + df.format(cal.getTime()));
1277		out.println();
1278		out.println("Sequence X:\t" + X_header);
1279		out.println("Sequence Y:\t" + Y_header);
1280		out.println();
1281		out.println("Window Size:\t" + w_size);
1282		out.println("Nmer Size:\t" + nmer_size);
1283		out.println("Compl. considered:\t" + use_complementary);
1284		out.println();
1285		out.println();
1286		out.println();
1287		
1288		float maxScore=score[0][0];
1289		int max_Ypos=0,max_Xpos=0;
1290		
1291		//writing out the highest correlated window in Y for every window in X   
1292		out.println("Sequence X:");
1293		out.println("window in X\tValue\twindow in Y");
1294		for(int k=0; k<w_num_X; k++){
1295			for(int l=0;l<w_num_Y;l++){
1296				if(score[k][l]>maxScore){
1297					maxScore=score[k][l];
1298					max_Ypos=l;
1299					}
1300				}
1301			out.println(k+"\t"+score[k][max_Ypos]+"\t"+max_Ypos);
1302			if((k+1)!=w_num_X){maxScore=score[k+1][0];}
1303		}
1304		maxScore = score[0][0];
1305		
1306		out.println();
1307		out.println();
1308		
1309		//writing out the highest correlated window in X for every window in Y
1310		out.println("Sequence Y:");
1311		out.println("window in Y\tValue\twindow in X");
1312		for(int k=0; k<w_num_Y; k++){
1313			for(int l=0;l<w_num_X;l++){
1314				if(score[l][k]>maxScore){
1315					maxScore=score[l][k];
1316					max_Xpos=l;
1317					}
1318				}
1319			out.println(k+"\t"+score[max_Xpos][k]+"\t"+max_Xpos);
1320			if((k+1)!=w_num_Y){maxScore=score[0][k+1];}
1321		}
1322		out.close();
1323		
1324	}
1325	public void write_max_gene_Corr(String writeLocation){
1326		String f_maxCorrs = writeLocation;
1327		File F_maxCorrs = new File(f_maxCorrs);
1328		try{
1329			if(F_maxCorrs.createNewFile()){System.out.println("File F_maxCorrs was created");}
1330				else{System.out.println("File F_maxCorrs was not created");}
1331		}
1332		catch(IOException e){System.out.println("I/O Error: writeScoreMatrix");}
1333		
1334		PrintWriter out = openWriter(F_maxCorrs);
1335		
1336		Calendar cal = Calendar.getInstance();
1337	    DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.MEDIUM);
1338		
1339		out.print("Highest Correlated Genes");
1340		out.println("\t\t\t" + df.format(cal.getTime()));
1341		out.println();
1342		out.println("Sequence X:\t" + X_header);
1343		out.println("Sequence Y:\t" + Y_header);
1344		out.println();
1345		out.println("Nmer Size:\t" + 3);
1346		out.println("Compl. considered:\t" + use_complementary);
1347		out.println();
1348		out.println();
1349		out.println();
1350		
1351		float maxScore=score[0][0];
1352		int max_Ypos=0,max_Xpos=0;
1353		
1354		//writing out the highest correlated window in Y for every window in X   
1355		out.println("Sequence X:");
1356		out.println("window in X\tValue\twindow in Y");
1357		for(int k=0; k<w_num_X; k++){
1358			for(int l=0;l<w_num_Y;l++){
1359				if(score[k][l]>maxScore){
1360					maxScore=score[k][l];
1361					max_Ypos=l;
1362					}
1363				}
1364			out.println(X_geneSynonyms[k]+"\t"+score[k][max_Ypos]+"\t"+Y_geneSynonyms[max_Ypos]);
1365			if((k+1)!=w_num_X){maxScore=score[k+1][0];}
1366		}
1367		maxScore = score[0][0];
1368		
1369		out.println();
1370		out.println();
1371	
1372		//writing out the highest correlated window in X for every window in Y
1373		out.println("Sequence Y:");
1374		out.println("window in Y\tValue\twindow in X");
1375		for(int k=0; k<w_num_Y; k++){
1376			for(int l=0;l<w_num_X;l++){
1377				if(score[l][k]>maxScore){
1378					maxScore=score[l][k];
1379					max_Xpos=l;
1380					}
1381				}
1382			out.println(Y_geneSynonyms[k]+"\t"+score[max_Xpos][k]+"\t"+max_Xpos);
1383			if((k+1)!=w_num_Y){maxScore=score[0][k+1];}
1384		}
1385		
1386		out.close();
1387		X_geneSynonyms = null;
1388		Y_geneSynonyms = null;		
1389	}
1390	
1391	
1392	public void calcAvg_window_Corr(){
1393		float numerator = 0;
1394		avgCorrX = new float [w_num_X];
1395		avgCorrY = new float [w_num_Y];
1396		
1397		//Calculating averages for the X sequence
1398		for(int k=0; k<w_num_X; k++){
1399			for(int l=0;l<w_num_Y;l++){
1400				numerator = score[k][l] + numerator;
1401			}
1402			avgCorrX[k] = numerator/(float)w_num_Y; 
1403			numerator = 0;
1404		}
1405		
1406		//Calculating averages for the Y sequence
1407		for(int k=0; k<w_num_Y; k++){
1408			for(int l=0;l<w_num_X;l++){
1409				numerator = score[l][k] + numerator;
1410			}
1411			avgCorrY[k] = numerator/(float)w_num_X; 
1412			numerator = 0;
1413		}
1414	}
1415	public float calcGC(int w_num, boolean XorY)
1416	{
1417		int gc=0;
1418		int i=-1;
1419		float perGC=0;
1420		
1421		if(XorY){	//XorY=true means your looking in the X sequence 
1422			do{
1423				i++;
1424				if((seq_inX_w[w_num][i]=='c')||(seq_inX_w[w_num][i]=='C')||
1425						(seq_inX_w[w_num][i]=='g')||(seq_inX_w[w_num][i]=='G')) {gc++;}
1426			
1427			}while(seq_inX_w[w_num][i]!='\0');
1428			
1429			perGC = 100*((float)gc/(float)i);
1430		}//end if
1431		
1432		if(!XorY){	//XorY=false means your looking in the Y sequence 
1433			do{
1434				i++;
1435				if((seq_inY_w[w_num][i]=='c')||(seq_inY_w[w_num][i]=='C')||
1436						(seq_inY_w[w_num][i]=='g')||(seq_inY_w[w_num][i]=='G')) {gc++;}
1437			
1438			}while(seq_inY_w[w_num][i]!='\0');
1439			
1440			perGC = 100*((float)gc/(float)i);
1441		}//end if
1442		
1443		return perGC;
1444	}
1445	
1446	
1447	/*public static void hisPlot(){
1448		int index;
1449		float maxScore=score[0][0];
1450		
1451		for(int k=0; k<w_num_X; k++){
1452			for(int l=0;l<w_num_Y;l++){
1453				if(score[k][l]>maxScore){maxScore=score[k][l];}
1454				}
1455			
1456			index=(int)((10-(maxScore*10))*2);
1457			hisPlot[index]++;
1458			//System.out.println((int)((10-(maxScore*10))*2));
1459			if((k+1)!=w_num_X){maxScore=score[k+1][0];}
1460		}
1461		
1462		System.out.println();
1463		System.out.println();
1464		for(int i=0;i<hisPlot.length;i++){
1465			System.out.println(hisPlot[i]);
1466		}
1467	}
1468	*/
1469	
1470	public void alignMax(){
1471		int max_Ypos=0;
1472		float Xgc,Ygc;
1473		float maxScore=score[0][0];
1474		
1475		String path4_test_writeOut = "C:\\Documents and Settings\\NTUser\\Desktop\\FileTests\\Maxes&GC.txt";
1476		File writeOut_X_Y = new File(path4_test_writeOut);
1477		try{
1478			if(writeOut_X_Y.createNewFile()){System.out.println("Maxes&GC was created");}
1479				else{System.out.println("File Maxes&GC was not created");}
1480		}
1481		catch(IOException e){System.out.println("I/O Error");}
1482		
1483		writeGC = openWriter(writeOut_X_Y);
1484		writeGC.print("\t\t\t");
1485		//write accession 
1486		writeGC.print("\n");
1487		
1488		for(int k=0; k<w_num_X; k++){
1489			for(int l=0;l<w_num_Y;l++){
1490				if(score[k][l]>maxScore){
1491					maxScore=score[k][l];
1492					max_Ypos=l;
1493					}
1494				}
1495			Xgc = calcGC(k,true);
1496			Ygc = calcGC(max_Ypos,false);
1497			writeWindowGC_Max(Xgc,Ygc,k,max_Ypos,maxScore);
1498			if((k+1)!=w_num_X){maxScore=score[k+1][0];}
1499		}
1500		
1501		System.out.println();
1502		System.out.println();
1503		for(int i=0;i<hisPlot.length;i++){
1504			System.out.println(hisPlot[i]);
1505		}
1506		writeGC.close();
1507	}
1508
1509	
1510	public void writeWindowGC_Max(float GC_X, float GC_Y, int windowX, int windowY, float max){
1511		
1512	    writeGC.print(GC_X+"\t"+windowX+"\t"+max+"\t"+windowY+"\t"+GC_Y+"\t\n");
1513	}
1514	
1515	
1516	public String giveR_ComplementX(int window, int nt){ 
1517		
1518		String reverseCNmer = new String();
1519		char c;
1520		int endNmerIndex = nt-nmer_size;
1521		
1522		for(int q=nt;q>endNmerIndex;q--){
1523			c=seq_inX_w[window][q];
1524			if(c=='a'||c=='A'){reverseCNmer+="01";}
1525				else if(c=='t'||c=='T'){reverseCNmer+="00";}
1526				else if(c=='g'||c=='G'){reverseCNmer+="11";}
1527				else if(c=='c'||c=='C'){reverseCNmer+="10";}
1528		}
1529		return reverseCNmer;
1530	}
1531	
1532	public String giveR_ComplementY(int window, int nt){ 
1533		
1534		String reverseCNmer = new String();
1535		char c;
1536		int endNmerIndex = nt-nmer_size;
1537		
1538		for(int q=nt;q>endNmerIndex;q--){
1539			c=seq_inY_w[window][q];
1540			if(c=='a'||c=='A'){reverseCNmer+="01";}
1541				else if(c=='t'||c=='T'){reverseCNmer+="00";}
1542				else if(c=='g'||c=='G'){reverseCNmer+="11";}
1543				else if(c=='c'||c=='C'){reverseCNmer+="10";}
1544		}
1545		return reverseCNmer;
1546	}	
1547	
1548	public PrintWriter openWriter(File name){ //probably don't need this method
1549		try{
1550			PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(name)), true); 
1551			return out;
1552		}
1553		catch(IOException e){
1554			System.out.println("PrintWriter could not find parsed_f_X");
1555			System.exit(0);
1556		}
1557		return null;
1558	}	
1559	public BufferedReader getReader(File file){
1560		BufferedReader in = null;
1561		try{
1562			in = new BufferedReader(new FileReader(file));
1563		}
1564		catch(IOException e){
1565			JOptionPane.showMessageDialog(frame.displayPanel,
1566					"BufferedReader I/O Error or coundn't find the file.", "Error",
1567				    JOptionPane.ERROR_MESSAGE);
1568			process = true;
1569		}
1570		return in;
1571		
1572	}	
1573	public String getLine(BufferedReader in){
1574		String line = null;
1575		try{line = in.readLine();}
1576		catch(IOException e){
1577			JOptionPane.showMessageDialog(frame.displayPanel,
1578					"bReader couldn't read next line.", "Error",
1579				    JOptionPane.ERROR_MESSAGE);
1580			process = true;
1581		}
1582		if(line==null){return null;}
1583			else{return line;}
1584	}	
1585	public void writeOutNmerCounts(){
1586		
1587		String path4_test_writeOut = "C:\\Documents and Settings\\NTUser\\Desktop\\FileTests\\NmerCounts.txt";
1588		File writeOutNmerCounts = new File(path4_test_writeOut);
1589		try{
1590			if(writeOutNmerCounts.createNewFile()){System.out.println("writeOutNmerCounts was created");}
1591				else{System.out.println("File writeOut_X_Y was not created");}
1592		}
1593		catch(IOException e){System.out.println("I/O Error");}
1594		
1595		PrintWriter out = openWriter(writeOutNmerCounts);
1596		
1597		for(int k=0; k<w_num_X; k++){
1598			StringBuilder sb2 = new StringBuilder();
1599			sb2.append(k);
1600			for(int l=0;l<num_possible_nmers;l++){
1601				String v = "\t" + nmer_counts_X[k][l];
1602				sb2.append(v);
1603				if(l==(num_possible_nmers-1)){out.println(sb2);}
1604				}
1605			}
1606		out.close();
1607	}
1608	
1609	//This method should be executed only when the entire genome is being looked at. It will make one tab-delimited file containing all the windows of both genomes.
1610	public void write_windows(String writeLocation){
1611        String f_wind_contents = writeLocation;
1612        File F_wind_contents = new File(f_wind_contents);
1613        try{
1614            if(F_wind_contents.createNewFile()){System.out.println("File F_wind_contents was created");}
1615                else{System.out.println("File F_wind_contents was not created");}
1616        }
1617        catch(IOException e){System.out.println("I/O Error: write_windows");}
1618       
1619        PrintWriter out = openWriter(F_wind_contents);
1620       
1621        Calendar cal = Calendar.getInstance();
1622        DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.MEDIUM);
1623       
1624        out.print("Sequence partitions");
1625        out.println("\t\t\t" + df.format(cal.getTime()));
1626        out.println();
1627        out.println("Sequence X:\t" + X_header);
1628        out.println("Sequence Y:\t" + Y_header);
1629        out.println();
1630        out.println("Window size:\t" + w_size);
1631        out.println("Nmer Size:\t" + nmer_size);
1632        out.println("Compl. considered:\t" + use_complementary);
1633        out.println();
1634        out.println();
1635        out.println();
1636       
1637        out.println("Sequence X window partitions: ");
1638        int i,j=0;
1639        for(i=0;i<w_num_X;i++){
1640            out.println("> " +i);
1641            for(j=0;j<w_size;j++){
1642                out.print(seq_inX_w[i][j]);
1643            }
1644            out.println();
1645        }
1646       
1647        out.println();
1648        out.println();
1649        out.println("Sequence Y window partitions: ");
1650       
1651        for(i=0;i<w_num_Y;i++){
1652            out.println("> " +i);
1653            for(j=0;j<w_size;j++){
1654                out.print(seq_inY_w[i][j]);
1655            }
1656            out.println();
1657        }
1658       
1659    }
1660
1661	//This method should only be executed when only the gene are being looked at. It will make one tab-delimited file containing all the gene sequences for both genomes.
1662    public void write_GeneWindows(String writeLocation){
1663        String f_gene_contents = writeLocation;
1664        File F_gene_contents = new File(f_gene_contents);
1665        try{
1666            if(F_gene_contents.createNewFile()){System.out.println("File F_gene_contents was created");}
1667                else{System.out.printl

Large files files are truncated, but you can click here to view the full file