package bicat.GO;

/**
 *
 * @author Hamed
 * /**
 
 * For its execution, a batch file called getGenemerge  is needed.
 * 
 */



import javax.swing.JOptionPane;
import bicat.gui.BicatGui;
import bicat.run_machine.SwingWorker;
import java.io.File;
import bicat.run_machine.RunMachine;

public class GeneMerge extends RunMachine {

	static BicatGui owner;
        
        
        
        
        public static String GENE_ASSOCIARION_FILE="S_cerevisiae.BP";
        public static String DESCRIPTION_FILE="GO.BP.use";
        public static String GENE_MERGE_DIRECTORY=owner.currentDirectoryPath+"//genemerge";
        public static String POPULATION_FILE_PATH;//=owner.POPULATION_FILE_PATH;
        
        
        
        
	public GeneMerge(BicatGui o) {
		owner = o;
	}

public  native void run_GeneMerge();

	static {
		
            try { 
             
             //  Runtime.getRuntime().exec(new String [] {"cmd" ,"/c", "start","getgenemerge",GENE_ASSOCIARION_FILE,DESCRIPTION_FILE,POPULATION_FILE_PATH,owner.EXPORTED_CLUSTER_FILE_PATH,owner.GO_CLUSTER_FILE_PATH},null,new File(GENE_MERGE_DIRECTORY));//,"genemerge/S_cerevisiae.BP","genemerge/GO.BP.use","genemerge/pop.txt","genemerge/testc.txt","genemerge/testout.out"});
//                Runtime.getRuntime().exec(new String [] {GENE_MERGE_DIRECTORY+"//getGeneMerge.exe",GENE_ASSOCIARION_FILE,DESCRIPTION_FILE,POPULATION_FILE_PATH,owner.EXPORTED_CLUSTER_FILE_PATH,owner.GO_CLUSTER_FILE_PATH},null,new File(GENE_MERGE_DIRECTORY));
                             
            }catch(Exception ex)
            {
                ex.printStackTrace();
                
            }
            System.out.println("GeneMerge batch is running...");
	
        }

        
public synchronized void getGeneMergeFile() {

		final SwingWorker worker = new SwingWorker() {

			public Object construct() {
				if (BicatGui.debug)
                                    System.out.println("genemerge process is running... ");
				
				run_GeneMerge();

				if (owner.debug) {
					System.out.println("Started genemerge in a new thread!\n");
				}

				return null;
			}

	public void finished() {
	JOptionPane.showMessageDialog(null,"GeneMerge Calculations finished.\nThe results can be found in the bicluster results section of the current dataset.");
			}
		};
		worker.start();
	}

public void setGeneMergeConfigurations(String organism,String GoType)
{
     /* set here the  geneassociation files and the description file according to the 
     * organisms and the go type.
     */
    
    
}


public static Process  testrun_GeneMerge(){

	Process proc=null;
            try { 
             
              // Runtime.getRuntime().exec(new String [] {"cmd" ,"/c", "start","getgenemerge",GENE_ASSOCIARION_FILE,DESCRIPTION_FILE,POPULATION_FILE_PATH,owner.EXPORTED_CLUSTER_FILE_PATH,owner.GO_CLUSTER_FILE_PATH},null,new File(GENE_MERGE_DIRECTORY));
       //     proc= Runtime.getRuntime().exec(new String [] {GENE_MERGE_DIRECTORY+"//getGeneMerge.exe",GENE_ASSOCIARION_FILE,DESCRIPTION_FILE,POPULATION_FILE_PATH,owner.EXPORTED_CLUSTER_FILE_PATH,owner.GO_CLUSTER_FILE_PATH},null,new File(GENE_MERGE_DIRECTORY));
            //proc= Runtime.getRuntime().exec(new String [] {"perl ",GENE_MERGE_DIRECTORY+"//GeneMerge1.2.pl",GENE_ASSOCIARION_FILE,DESCRIPTION_FILE,POPULATION_FILE_PATH,owner.EXPORTED_CLUSTER_FILE_PATH,owner.GO_CLUSTER_FILE_PATH},null,new File(GENE_MERGE_DIRECTORY));
                
             //  int exitvalue=proc.waitFor();
            
            
            Thread needle =new Thread();
            needle.sleep(((120/120)*1500+15000));
            
            
            
            //String cmd="perl "+GENE_MERGE_DIRECTORY+"//GeneMerge1.2.pl "+GENE_MERGE_DIRECTORY+"//"+GENE_ASSOCIARION_FILE +" "+GENE_MERGE_DIRECTORY+"//"+DESCRIPTION_FILE+" "+POPULATION_FILE_PATH +" "+owner.EXPORTED_CLUSTER_FILE_PATH+" "+owner.GO_CLUSTER_FILE_PATH;
             //proc= Runtime.getRuntime().exec(cmd);
            //System.out.println("exitvalue >>>>"+exitvalue);
            
            }catch(Exception ex)
            {
                ex.printStackTrace();
                
            }
         
            System.out.println("GeneMerge  is running here in the method...");
	return proc;
                  
}




}





    
