/* Author: Amay Agrawal
 * Project: Bacteria Cloud
 * Mentor: Prof. Manish K Gupta
 */
import java.util.*;
import java.io.*;

public class Data_Insertion {
	int arr[] = new int[200];
	int length=0;
	int check=0;
	String finalstring = null;
	File file = new File("C:\\Users\\HP\\Desktop\\Plasmids\\final_output.txt");
	BufferedWriter bw = null;
	public Data_Insertion(int a[]){
		arr=a;
	}
	
	public void insertsequence() throws IOException{
		FileWriter fw = new FileWriter(file);
		  bw = new BufferedWriter(fw);
		BufferedReader bufferedReader = new BufferedReader(new FileReader("C:\\Users\\HP\\Desktop\\Plasmids\\encoded.txt"));
		BufferedReader bufferedReader1 = new BufferedReader(new FileReader("C:\\Users\\HP\\Desktop\\Plasmids\\output.txt"));
		BufferedReader bufferedReader2 = new BufferedReader(new FileReader("C:\\Users\\HP\\Desktop\\Plasmids\\pBR322.txt"));
		String line = null;
		String line1 = "CGAT";
		String line2 = null;
		String line10 = null;
		String parts[];
		while ((line = bufferedReader.readLine()) != null){
			line1+=line;
			length = 27 + line.length();
			for(int j=0;j<70;j++){
				if(arr[j]>length){
					check=arr[j];
					break;
				}
			}
			System.out.println("kkkkk"+check);
			while ((line2 = bufferedReader1.readLine()) != null){
				parts = line2.split(" ");
				int ab = Integer.parseInt(parts[0]);
				if(ab == check){
					int length1 = line1.length();
					int bc = check-length1;
					for(int y=0;y<bc;y++){
						line1+='A';
					}
					int abc = Integer.parseInt(parts[2]);
					int length2 = parts[3].length();
					String line5 = parts[3].substring(abc, length2);
					line1+=line5;
					while ((line10 = bufferedReader2.readLine()) != null){
						finalstring = line10.substring(0, 24);
						finalstring +=line1;
						int length10 =line10.length();
						int length15 = finalstring.length();
						String testing = line10.substring(length15, length10);
						finalstring += testing;
					}
					bw.write(finalstring);
				}
			}
		}
		try {
			bw.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
