/* Author: Amay Agrawal
 * Project: Bacteria Cloud
 * Mentor: Prof. Manish K Gupta
 */
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.Arc2D;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
import java.io.*;

import javax.swing.JFrame;
import javax.swing.JPanel;

import java.awt.Color;
import java.awt.Container;
import java.awt.Font;
import java.awt.event.*;

public class Circle3 extends JFrame
{
	static int start;
	static int end;
	static int totallength;
	static String final3;
	static int ghj = 0;
	static String final1;
	static String finalstring;
	//int arr[] = {24,29,187,229,233,375,410,566,626,651,716,832,939,974,1359,1369,1425,1426,1446,1581,1664,1672,2002,2066,2117,2220,2227,2246,2296,2357,2473,2889,3366,3538,3611,3736,3846,4170,4286}; 
    //String arr1[] = {"ClaI","HindIII","EcoRV","NheI","BmtI","BamHI","SgrAI","SphI","EcoNI","SalI","PshAI","BpmI","EagI","NruI",
    	//	          "BsmI","StyI","BsoBI","BmeT110I","MscI","Bpu10I","BspEI","BsaBI","BpmI","PvuII","PfoI","PflFI","BsaAI","BstZ17I","NdeI","BspQI","AflIII","AlwNI","AhdI","AseI","PstI","PvuI","ScaI","SspI","ZraI"};
	//int length = arr.length;
	
	public Circle3(int x,int y,int z,String ab,String cd,String ef)
	{
		start = x;
		end = y;
		totallength = z;
		final3 = ab;
		final1 = cd;
		finalstring = ef;
	}
	int count=0;
	int counter5=0;
	int counter6=0;
	int counter7=0;
	public void Circle31()
	{
		
		 this.getContentPane().setBackground(Color.black);
		setTitle("Bacteria Plasmid Storage System");
		setSize(1400,1200);
		setVisible(true);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		
	}
	
	
	//@Override
	public void paint(Graphics gg)
	{
		        System.out.println("Inside Paint");
		        if(ghj<=1){
		        	ghj++;
		        super.paint(gg);
		        }
				String line1 = "";
				String plasmidname = "";
				String plasmidseq = "";
				int plasmidno=0;
				String plasmidname1 = "";
				String plasmidseq1 = "";
				int plasmidno1=0;
				BufferedReader br = null;
		        try {
					br = new BufferedReader(new FileReader("Plasmids/output8.txt"));
				} catch (FileNotFoundException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}    
		
		        try {
					while ((line1 = br.readLine()) != null){
						String parts[] = line1.split(" ");
						int ab = Integer.parseInt(parts[0]);
						if(ab==start){
							plasmidname = parts[1];
							plasmidseq = parts[3];
							plasmidno = Integer.parseInt(parts[2]);
						}
						else if(ab==end){
							plasmidname1 = parts[1];
							plasmidseq1 = parts[3];
							plasmidno1 = Integer.parseInt(parts[2]);
						}
						else{
							continue;
						}
					}
				} catch (IOException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
		        
		        
				System.out.println("Are bhai please chal jana");
				System.out.println(plasmidname+" "+plasmidseq+" "+plasmidno+" "+plasmidname1+" "+plasmidseq1+" "+plasmidno1);
				//counter6++;
				//System.out.println("sdjkjk "+counter6);
				Graphics2D g = (Graphics2D) gg;
				
				String plasmidsub = plasmidseq.substring(0, plasmidno);
				String plasmidsub1 = plasmidseq.substring(plasmidno,plasmidseq.length());
				String plasmidsub2 = plasmidseq1.substring(0, plasmidno1);
				String plasmidsub3 = plasmidseq1.substring(plasmidno1,plasmidseq1.length());
				
				Gel g1 = new Gel(plasmidname,plasmidname1,plasmidsub,plasmidsub1,plasmidsub2,plasmidsub3);
				
				g.setColor(Color.yellow);
				int length67 = plasmidsub.length();
				int length68 = plasmidsub2.length();
				int length69 = length67*9;
				int length70 = length68*9;
				g.drawString(plasmidname+" ( "+start+" )", 1055, 130 );
				g.drawString(plasmidname1+" ( "+end+" )", 1190, 130 );
				g.drawString("Forward Restriction enzyme ( "+plasmidname+" )  = ", 875, 625 );
				g.drawString(plasmidsub, 1100, 625 );
				g.drawString(plasmidsub1, 1100+length69+20, 625 );
				g.drawString("Reverse Restriction enzyme ( "+plasmidname1+" )  = ", 875, 670 );
				g.drawString(plasmidsub2, 1100, 670 );
				g.drawString(plasmidsub3, 1100+length70+20, 670 );
				g.drawString(complement(plasmidsub1), 1085, 265 );
				g.drawString(complement(plasmidsub3), 1185, 265 );
				g.drawString("N = A,G,T or C", 1120, 90);
			    g.setColor(Color.WHITE);
			    g.setFont(new Font("Times new Roman", Font.PLAIN, 30));
			    g.drawString("Cloned Plasmid", 525, 70 );
			    g.drawString("Ready To Clone!!", 1055, 450);
				g.setColor(Color.YELLOW);
				g.setFont(new Font("Dialog", Font.PLAIN, 12));
				System.out.println("klklklklklklkl "+plasmidsub3);
				
				for(int j=0;j<20;j++){
					Rectangle2D.Double shape1 = new Rectangle2D.Double(1100+length69+10, 610+j, 1, 1);
					//Ellipse2D.Double shape = new Ellipse2D.Double(120+j, 50, 20, 20);
					g.draw(shape1);
					g.fill(shape1);
					//g.drawString(check1,600+ a, 400+b);
					this.validate();
				}
				
				for(int j=0;j<20;j++){
					Rectangle2D.Double shape1 = new Rectangle2D.Double(1100+length70+10, 655+j, 1, 1);
					//Ellipse2D.Double shape = new Ellipse2D.Double(120+j, 50, 20, 20);
					g.draw(shape1);
					g.fill(shape1);
					//g.drawString(check1,600+ a, 400+b);
					this.validate();
				}
				
				int i=0;
				
				/* Enable anti-aliasing and pure stroke */
				//g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
				//g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
				for(i=-10;i<=210;i++){
					
						//System.out.println(i);
						//g.setBackground(Color.YELLOW);
						g.setColor(Color.CYAN);
						//String check = Integer.toString(arr[i]);
						//String check1 = arr1[i]+" ("+check+")";
						//double z = arr[i];
						//double x = 300*Math.cos(Math.toRadians((i/360)*360));
						//double y = 300*Math.sin(Math.toRadians((i/360)*360));
						//System.out.println(x+" "+y);
						//float a = (float) x;
						//float b = (float) y;
						
						/* Construct a shape and draw it */
						Ellipse2D.Double shape = new Ellipse2D.Double(1050+i, 200, 5, 5);
						g.draw(shape);
						g.fill(shape);
						//g.drawString(check1,600+ a, 400+b);
						revalidate();
						repaint();
					
					
				}
				int j=i;
				for(j=i;j>=-10;j--){
					if(j>=50 && j<=150)
						continue;
					//System.out.println(i);
					//g.setBackground(Color.YELLOW);
					g.setColor(Color.cyan);
					//String check = Integer.toString(arr[i]);
					//String check1 = arr1[i]+" ("+check+")";
					//double z = arr[i];
					//double x = 300*Math.cos(Math.toRadians((i/360)*360));
					//double y = 300*Math.sin(Math.toRadians((i/360)*360));
					//System.out.println(x+" "+y);
					//float a = (float) x;
					//float b = (float) y;
					
					/* Construct a shape and draw it */
					Ellipse2D.Double shape = new Ellipse2D.Double(1050+j, 145, 5, 5);
					g.draw(shape);
					g.fill(shape);
					//g.drawString(check1,600+ a, 400+b);
					revalidate();
					repaint();
				
				
			      }
				
				g.draw(new Arc2D.Double(1025,145, 60, 60, 115, 135,Arc2D.OPEN));
				g.draw(new Arc2D.Double(1220,145, 60, 60, -70, 135,Arc2D.OPEN));
				
				for(int gh=50;gh<=150;gh++){
					g.setColor(Color.red);
					Ellipse2D.Double shape = new Ellipse2D.Double(1050+gh, 275, 5, 5);
					g.draw(shape);
					g.fill(shape);
				}
				
				int ib=0;
				
				/* Enable anti-aliasing and pure stroke */
				//g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
				//g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
				for(ib=-10;ib<=210;ib++){
					
						//System.out.println(i);
						//g.setBackground(Color.YELLOW);
						g.setColor(Color.CYAN);
						//String check = Integer.toString(arr[i]);
						//String check1 = arr1[i]+" ("+check+")";
						//double z = arr[i];
						//double x = 300*Math.cos(Math.toRadians((i/360)*360));
						//double y = 300*Math.sin(Math.toRadians((i/360)*360));
						//System.out.println(x+" "+y);
						//float a = (float) x;
						//float b = (float) y;
						
						/* Construct a shape and draw it */
						Ellipse2D.Double shape = new Ellipse2D.Double(1050+ib, 400, 5, 5);
						g.draw(shape);
						g.fill(shape);
						//g.drawString(check1,600+ a, 400+b);
						revalidate();
						repaint();
					
					
				}
				int jb=ib;
				for(jb=i;jb>=-10;jb--){
					if(jb>=50 && jb<=150)
						g.setColor(Color.red);
					else
						g.setColor(Color.cyan);
					//System.out.println(i);
					//g.setBackground(Color.YELLOW);
					//g.setColor(Color.cyan);
					//String check = Integer.toString(arr[i]);
					//String check1 = arr1[i]+" ("+check+")";
					//double z = arr[i];
					//double x = 300*Math.cos(Math.toRadians((i/360)*360));
					//double y = 300*Math.sin(Math.toRadians((i/360)*360));
					//System.out.println(x+" "+y);
					//float a = (float) x;
					//float b = (float) y;
					
					/* Construct a shape and draw it */
					Ellipse2D.Double shape = new Ellipse2D.Double(1050+jb, 345, 5, 5);
					g.draw(shape);
					g.fill(shape);
					//g.drawString(check1,600+ a, 400+b);
					revalidate();
					repaint();
				
				
			      }
				
				g.draw(new Arc2D.Double(1025,345, 60, 60, 115, 135,Arc2D.OPEN));
				g.draw(new Arc2D.Double(1220,345, 60, 60, -70, 135,Arc2D.OPEN));
				
				String line10 = final1;
				BufferedReader bufferedReader = null;
				String[] parts =line10.split("/");
				System.out.println(parts[1]);
				String line11 ="";
				for(int id=0;id<parts[1].length();id++){
					if(parts[1].charAt(id)=='.'){
						break;
					}
					else{
						line11+=parts[1].charAt(id);
					}
				}
				try {
					bufferedReader = new BufferedReader(new FileReader(line10));
				} catch (FileNotFoundException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				String line;
				int tocount1=0;
				int tocount2=0;
				int tocount3=0;
				int tocount4=0;
				int tocount5=0;
				int tocount6=0;
				System.out.println("ddd "+final1);
				System.out.println(finalstring);
				String parts5[] = finalstring.split(" ");
				if(parts5.length==6){
					tocount1=Integer.parseInt(parts5[1]);
					tocount2=Integer.parseInt(parts5[2]);
					tocount3=Integer.parseInt(parts5[4]);
					tocount4=Integer.parseInt(parts5[5]);
				}
				else{
					tocount1=Integer.parseInt(parts5[1]);
					tocount2=Integer.parseInt(parts5[2]);
					tocount3=Integer.parseInt(parts5[4]);
					tocount4=Integer.parseInt(parts5[5]);
					tocount5=Integer.parseInt(parts5[7]);
					tocount6=Integer.parseInt(parts5[8]);
				}
				try {
					while ((line = bufferedReader.readLine()) != null){
						counter6++;
						//System.out.println("sdjkjk "+counter6);
						//Graphics2D g = (Graphics2D) gg;
						g.setColor(Color.white);
						g.setFont(new Font("Times new Roman",Font.PLAIN,18));
						g.drawString("Cloned Data",550,350);
						g.drawString("Plasmid ("+line11+") ",550,375);
						g.drawString("length ("+line.length()+") bp",550,400);
						double u = 300*Math.cos(Math.toRadians((1/line.length())*360));
						double v = 300*Math.sin(Math.toRadians((1/line.length())*360));

						float w = (float) u;
						float e = (float) v;
		 
						g.drawString("start", 625+w, 400+e );
						if(parts5.length==6){
							g.setColor(Color.red);
							g.drawString("red = Cloned data",550,425);
							g.setColor(Color.cyan);
							g.drawString("cyan = "+parts5[0],550,450);
							g.setColor(Color.yellow);
							g.drawString("yellow = "+parts5[3],550,475);
							g.setColor(Color.blue);
							g.drawString("blue = other",550,500);
						}
						else if (parts5.length==9){
							g.setColor(Color.red);
							g.drawString("red = Cloned data",550,425);
							g.setColor(Color.cyan);
							g.drawString("cyan = "+parts5[0],550,450);
							g.setColor(Color.yellow);
							g.drawString("yellow = "+parts5[3],550,475);
							g.setColor(Color.blue);
							g.drawString("blue = "+parts5[6],550,500);
							g.setColor(Color.white);
							g.drawString("white = other ",550,525);
						}
						for(int id=0;id<line.length();id++){
							if(parts5.length==6){
							counter5++;
							char abcd = line.charAt(i);
							
							if(counter5>=start && counter5<=end){
								//g.setBackground(Color.YELLOW);
								g.setColor(Color.red);
								//String check = Integer.toString(arr[i]);
								String check1 = Character.toString(abcd);
								double z = counter5;
								double x = 300*Math.cos(Math.toRadians((z/line.length())*360));
								double y = 300*Math.sin(Math.toRadians((z/line.length())*360));

								float a = (float) x;
								float b = (float) y;
								
								/* Construct a shape and draw it */
								Ellipse2D.Double shape = new Ellipse2D.Double(600+x, 400+y, 5, 5);
								g.draw(shape);
								//g.fill(shape);
								//g.drawString(check1,600+ a, 400+b);
								
							}
							
							else if(counter5>=tocount1 && counter5<=tocount2){
								//g.setBackground(Color.YELLOW);
								g.setColor(Color.CYAN);
								//String check = Integer.toString(arr[i]);
								String check1 = Character.toString(abcd);
								double z = counter5;
								double x = 300*Math.cos(Math.toRadians((z/line.length())*360));
								double y = 300*Math.sin(Math.toRadians((z/line.length())*360));

								float a = (float) x;
								float b = (float) y;
								
								/* Construct a shape and draw it */
								Ellipse2D.Double shape = new Ellipse2D.Double(600+x, 400+y, 5, 5);
								g.draw(shape);
								//g.fill(shape);
								//g.drawString(check1,600+ a, 400+b);
								
							}
							
							else if(counter5 >= tocount3 && counter5 <= tocount4){
								//g.setBackground(Color.YELLOW);
								g.setColor(Color.yellow);
								//String check = Integer.toString(arr[i]);
								String check1 = Character.toString(abcd);
								double z = counter5;
								double x = 300*Math.cos(Math.toRadians((z/line.length())*360));
								double y = 300*Math.sin(Math.toRadians((z/line.length())*360));
								
								float a = (float) x;
								float b = (float) y;

								/* Construct a shape and draw it */
								Ellipse2D.Double shape = new Ellipse2D.Double(600+x, 400+y, 5, 5);
								g.draw(shape);
								//g.fill(shape);
								//g.drawString(check1,600+ a, 400+b);
							}
							
							else {
								//g.setBackground(Color.YELLOW);
								g.setColor(Color.blue);
								//String check = Integer.toString(arr[i]);
								String check1 = Character.toString(abcd);
								double z = counter5;
								double x = 300*Math.cos(Math.toRadians((z/line.length())*360));
								double y = 300*Math.sin(Math.toRadians((z/line.length())*360));
								
								float a = (float) x;
								float b = (float) y;

								/* Construct a shape and draw it */
								Ellipse2D.Double shape = new Ellipse2D.Double(600+x, 400+y, 5, 5);
								g.draw(shape);
								//g.fill(shape);
								//g.drawString(check1,600+ a, 400+b);
							}
							
						}
						else if(parts5.length==9){
							counter5++;
							char abcd = line.charAt(i);
							
							if(counter5>=start && counter5 <=end){
								//g.setBackground(Color.YELLOW);
								g.setColor(Color.red);
								//String check = Integer.toString(arr[i]);
								String check1 = Character.toString(abcd);
								double z = counter5;
								double x = 300*Math.cos(Math.toRadians((z/line.length())*360));
								double y = 300*Math.sin(Math.toRadians((z/line.length())*360));

								float a = (float) x;
								float b = (float) y;
								
								/* Construct a shape and draw it */
								Ellipse2D.Double shape = new Ellipse2D.Double(600+x, 400+y, 5, 5);
								g.draw(shape);
								//g.fill(shape);
								//g.drawString(check1,600+ a, 400+b);
								
							}

							
							else if(counter5>=tocount1 && counter5 <=tocount2){
								//g.setBackground(Color.YELLOW);
								g.setColor(Color.CYAN);
								//String check = Integer.toString(arr[i]);
								String check1 = Character.toString(abcd);
								double z = counter5;
								double x = 300*Math.cos(Math.toRadians((z/line.length())*360));
								double y = 300*Math.sin(Math.toRadians((z/line.length())*360));

								float a = (float) x;
								float b = (float) y;
								
								/* Construct a shape and draw it */
								Ellipse2D.Double shape = new Ellipse2D.Double(600+x, 400+y, 5, 5);
								g.draw(shape);
								//g.fill(shape);
								//g.drawString(check1,600+ a, 400+b);
								
							}
							
							else if(counter5 >= tocount3 && counter5 <= tocount4){
								//g.setBackground(Color.YELLOW);
								g.setColor(Color.yellow);
								//String check = Integer.toString(arr[i]);
								String check1 = Character.toString(abcd);
								double z = counter5;
								double x = 300*Math.cos(Math.toRadians((z/line.length())*360));
								double y = 300*Math.sin(Math.toRadians((z/line.length())*360));
								
								float a = (float) x;
								float b = (float) y;

								/* Construct a shape and draw it */
								Ellipse2D.Double shape = new Ellipse2D.Double(600+x, 400+y, 5, 5);
								g.draw(shape);
								//g.fill(shape);
								//g.drawString(check1,600+ a, 400+b);
							}
							
							else if(counter5>=tocount5 && counter5<=tocount6){
								//g.setBackground(Color.YELLOW);
								g.setColor(Color.blue);
								//String check = Integer.toString(arr[i]);
								String check1 = Character.toString(abcd);
								double z = counter5;
								double x = 300*Math.cos(Math.toRadians((z/line.length())*360));
								double y = 300*Math.sin(Math.toRadians((z/line.length())*360));
								
								float a = (float) x;
								float b = (float) y;

								/* Construct a shape and draw it */
								Ellipse2D.Double shape = new Ellipse2D.Double(600+x, 400+y, 5, 5);
								g.draw(shape);
								//g.fill(shape);
								//g.drawString(check1,600+ a, 400+b);
							}
							else{
								//g.setBackground(Color.YELLOW);
								g.setColor(Color.WHITE);
								//String check = Integer.toString(arr[i]);
								String check1 = Character.toString(abcd);
								double z = counter5;
								double x = 300*Math.cos(Math.toRadians((z/line.length())*360));
								double y = 300*Math.sin(Math.toRadians((z/line.length())*360));
								
								float a = (float) x;
								float b = (float) y;

								/* Construct a shape and draw it */
								Ellipse2D.Double shape = new Ellipse2D.Double(600+x, 400+y, 5, 5);
								g.draw(shape);
								//g.fill(shape);
								//g.drawString(check1,600+ a, 400+b);
							}
						}
						}
						counter5=0;
						if(counter6 >= 1)
							break;
					}
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

			}
		
		
		
		
		
	/* Enable anti-aliasing and pure stroke */
	//g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
	//g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);


	public String complement(String ab){
		String bc = "";
		for(int i=0;i<ab.length();i++){
			if(ab.charAt(i)=='A'){
				bc+='T';
			}
			else if(ab.charAt(i)=='C'){
				bc+='G';
			}
			else if(ab.charAt(i)=='G'){
				bc+='C';
			}
			else if(ab.charAt(i)=='T'){
				bc+='A';
			}
			else if(ab.charAt(i)=='N'){
				bc+='N';
			}
		}
		return bc;
	}
	
	

	public  void amay()
	{
		
//		Circle3 t = new Circle3();
		Circle31();
		this.paint(null);
		
	}
}