Package Test

Source Code of Test.GalaxyTestSuite

package Test;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

import CLInterface.ConverterConfig;
import Galaxy.Toolbox.GalaxyToolDatabase;
import Galaxy.Tree.Tool.Tool;
import Galaxy.Tree.Workflow.Workflow;
import Galaxy.Visitor.Local.GalaxyToLoniWorkflowConverter;
import LONI.tree.workflow.Pipeline;
import LONI.visitor.LoniToGalaxyConverter;
import Specification.GalaxySpecification;
import Specification.LoniSpecification;

public class GalaxyTestSuite {
  static final String TEST_DIR="data/Galaxy/test";
  //Input and Output Dirs
 
  static final String TEST_G2L_IN_DIR=TEST_DIR + "/g2l/src";
  static final String TEST_G2L_OUT_DIR=TEST_DIR + "/g2l/output";
 
  static final String TEST_G2L_GAL_L_IN_DIR=TEST_G2L_IN_DIR+"/local-workflow";
  static final String TEST_G2L_GAL_W_IN_DIR=TEST_G2L_IN_DIR+"/web-workflow";
  static final String TEST_G2L_GAL_TOOL_IN_DIR=TEST_G2L_IN_DIR+"/tool/";
  static final String TEST_G2L_GAL_L_OUT_DIR=TEST_G2L_OUT_DIR+"/local-workflow";
  static final String TEST_G2L_GAL_W_OUT_DIR=TEST_G2L_OUT_DIR+"/web-workflow";
  static final String TEST_G2L_GAL_TOOL_OUT_DIR=TEST_G2L_OUT_DIR+"/tool/";
  static final String TEST_G2L_LONI_L_OUT_DIR=TEST_G2L_OUT_DIR+"/local-pipeline";
  static final String TEST_G2L_LONI_W_OUT_DIR=TEST_G2L_OUT_DIR+"/web-pipeline";
 
  static final String TEST_L2G_IN_DIR=TEST_DIR+ "/l2g/src";
  static final String TEST_L2G_OUT_DIR=TEST_DIR+"/l2g/output";
 
  static final String TEST_L2G_LONI_IN_DIR =TEST_L2G_IN_DIR+ "/pipeline";
  static final String TEST_L2G_GAL_OUT_DIR = TEST_L2G_OUT_DIR+"/workflow/";
  static final String TEST_L2G_LONI_OUT_DIR = TEST_L2G_OUT_DIR+"/pipeline/";
 
 
 
  static GalaxyToolDatabase TEST_TOOLDB;
 
  public static void TestLocalG2L(){
    ConverterConfig.GALAXY_INPUT_DIR = TEST_G2L_GAL_TOOL_IN_DIR;
    ConverterConfig.GALAXY_OUTPUT_DIR = TEST_G2L_LONI_L_OUT_DIR;
   
    System.out.println("====================");
    System.out.println("LOCAL Galaxy to Loni Conversion Tests");
    System.out.println("====================");
    File dir = new File(TEST_G2L_GAL_L_IN_DIR);

    String[] children = dir.list();
    if (children == null) {
        // Either dir does not exist or is not a directory
    } else {
        for (int i=0; i<children.length; i++) {
            // Get filename of file or directory
            String filename = children[i];
            if(filename.endsWith(".ga")){
              String in_path = TEST_G2L_GAL_L_IN_DIR + "/"+filename;
              String out_filename = filename.replace(".ga", ".pipe");
              String out_path = ConverterConfig.GALAXY_OUTPUT_DIR + "/"+out_filename;
              LocalGalaxyToLoni(in_path, out_path);
            }
        }
    }
   
   
  }
  public static void TestWebG2L(){
    ConverterConfig.GALAXY_INPUT_DIR=null;
    ConverterConfig.GALAXY_OUTPUT_DIR = TEST_G2L_LONI_W_OUT_DIR;
   
    System.out.println("====================");
    System.out.println("WEB Galaxy to Loni Conversion Tests");
    System.out.println("====================");
   
    File dir = new File(TEST_G2L_GAL_W_IN_DIR);

    String[] children = dir.list();
    if (children == null) {
        // Either dir does not exist or is not a directory
    } else {
        for (int i=0; i<children.length; i++) {
            // Get filename of file or directory
            String filename = children[i];
            if(filename.endsWith(".ga")){
              String in_path = TEST_G2L_GAL_W_IN_DIR + "/"+filename;
              String out_filename = filename.replace(".ga", ".pipe");
              String out_path = ConverterConfig.GALAXY_OUTPUT_DIR + "/"+out_filename;
              WebGalaxyToLoni(in_path, out_path);
            }
        }
    }
   
  }
 
  public static void TestLocalG2G(){
   
    System.out.println("====================");
    System.out.println("LOCAL Galaxy to Galaxy Conversion Tests");
    System.out.println("====================");
   
    ConverterConfig.GALAXY_INPUT_DIR = TEST_G2L_GAL_TOOL_IN_DIR;
    ConverterConfig.GALAXY_OUTPUT_DIR = TEST_G2L_GAL_L_OUT_DIR;
   
    File dir = new File(TEST_G2L_GAL_L_IN_DIR);
   
    String[] children = dir.list();
    if (children == null) {
        // Either dir does not exist or is not a directory
    } else {
        for (int i=0; i<children.length; i++) {
            // Get filename of file or directory
            String filename = children[i];
            if(filename.endsWith(".ga")){
              String in_path = TEST_G2L_GAL_L_IN_DIR + "/"+filename;
              String out_path = ConverterConfig.GALAXY_OUTPUT_DIR + "/"+filename;
              GalaxyToGalaxy(in_path, out_path);
            }
        }
    }
   
  }
 
  public static void TestL2G(){
    ConverterConfig.GALAXY_INPUT_DIR = null;
    ConverterConfig.GALAXY_OUTPUT_DIR = TEST_L2G_GAL_OUT_DIR;
   
    GalaxySpecification.getDatabase().clear();
    System.out.println("====================");
    System.out.println("Loni To Galaxy");
    System.out.println("====================");

    File dir = new File(TEST_L2G_LONI_IN_DIR);
   
    String[] children = dir.list();
    if (children == null) {
        // Either dir does not exist or is not a directory
    } else {
        for (int i=0; i<children.length; i++) {
            // Get filename of file or directory
            String filename = children[i];
            if(filename.endsWith(".pipe")){
              String in_path = TEST_L2G_LONI_IN_DIR + "/"+filename;
              String out_path = TEST_L2G_GAL_OUT_DIR + "/"+filename.replace(".pipe", ".ga");
              LoniToGalaxy(in_path, out_path);
            }
        }
    }
    GalaxySpecification.database.dumpDatabase();
   
   
  }
 
  public static void TestL2L(){
    ConverterConfig.GALAXY_INPUT_DIR = null;
    ConverterConfig.GALAXY_OUTPUT_DIR = TEST_L2G_LONI_OUT_DIR;
   
    GalaxySpecification.getDatabase().clear();
    System.out.println("====================");
    System.out.println("   Loni To Loni");
    System.out.println("====================");

    File dir = new File(TEST_L2G_LONI_IN_DIR);
   
    String[] children = dir.list();
    if (children == null) {
        // Either dir does not exist or is not a directory
    } else {
        for (int i=0; i<children.length; i++) {
            // Get filename of file or directory
            String filename = children[i];
            if(filename.endsWith(".pipe")){
              String in_path = TEST_L2G_LONI_IN_DIR + "/"+filename;
              String out_path = TEST_L2G_LONI_OUT_DIR + "/"+filename;
              LoniToLoni(in_path, out_path);
            }
        }
    }
   
   
  }
 
  public static void TestWebG2G(){
    ConverterConfig.GALAXY_INPUT_DIR = null;
    ConverterConfig.GALAXY_OUTPUT_DIR = TEST_G2L_GAL_W_OUT_DIR;
   
    System.out.println("====================");
    System.out.println("WEB Galaxy to Galaxy Conversion Tests");
    System.out.println("====================");

    File dir = new File(TEST_G2L_GAL_W_IN_DIR);
   
    String[] children = dir.list();
    if (children == null) {
        // Either dir does not exist or is not a directory
    } else {
        for (int i=0; i<children.length; i++) {
            // Get filename of file or directory
            String filename = children[i];
            if(filename.endsWith(".ga")){
              String in_path = TEST_G2L_GAL_W_IN_DIR + "/"+filename;
              String out_path = ConverterConfig.GALAXY_OUTPUT_DIR + "/"+filename;
              GalaxyToGalaxy(in_path, out_path);
            }
        }
    }
   
   
  }
  public static void TestTools(){
    ConverterConfig.GALAXY_INPUT_DIR = TEST_G2L_GAL_TOOL_IN_DIR;
    ConverterConfig.GALAXY_OUTPUT_DIR = TEST_G2L_GAL_TOOL_OUT_DIR;
    TEST_TOOLDB = new GalaxyToolDatabase();
    System.out.println("====================");
    System.out.println("Tool Parsing Tests");
    System.out.println("Number Tools: "+TEST_TOOLDB.getTools().size());
    System.out.println("====================");
   
    int count=0;
    for(String nm : TEST_TOOLDB.getTools()){
     
      try{
        System.out.println(nm + ":"+TEST_TOOLDB.getDirectory(nm));
        Tool tool = TEST_TOOLDB.getTool(nm);
       
      }catch(Exception e){
        //System.err.println(e.getMessage());
      }
     
    }
    System.out.println("====================");
    System.out.println("Tool Generation Tests");
    System.out.println("====================");
    try{
      TEST_TOOLDB.dumpDatabase();
    } catch(Exception e){
      //System.err.println("ERROR");
      //System.err.println(e.getMessage());
      //e.printStackTrace();
    }
  }
 
  public static void GalaxyToGalaxy(String path, String output){
    System.out.println(path);
    System.out.println("> "+output);
   
    Workflow G;
    try {
      G = GalaxySpecification.getJSONParser().parse(new File(path));
      //GalaxySpecification.populateTools(G);
     
      try {
        GalaxySpecification.getJSONGenerator().generate(G, output);
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
   
    } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
   
  }
 
 
  public static void LocalGalaxyToLoni(String path, String output){
    System.out.println(path);
    System.out.println("> "+output);
    Workflow G;
    try {
      Galaxy.Visitor.Local.GalaxyToLoniWorkflowConverter glc;
      glc = new Galaxy.Visitor.Local.GalaxyToLoniWorkflowConverter();
     
      G = GalaxySpecification.getJSONParser().parse(new File(path));
      Pipeline pipeline = (Pipeline) glc.visit(G);
     
      try {
        LoniSpecification.getXMLGenerator().generate(pipeline, output);
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
   
    } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
   
  }

 
  public static void WebGalaxyToLoni(String path, String output){
    System.out.println(path);
    System.out.println("> "+output);
    Workflow G;
    try {
      Galaxy.Visitor.Webservice.GalaxyToLoniWorkflowConverter glc;
      glc = new Galaxy.Visitor.Webservice.GalaxyToLoniWorkflowConverter();
     
      G = GalaxySpecification.getJSONParser().parse(new File(path));
      Pipeline pipeline = (Pipeline) glc.visit(G);
     
      try {
        LoniSpecification.getXMLGenerator().generate(pipeline, output);
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
   
    } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
   
  }
 
  public static void LoniToGalaxy(String path, String output){
    System.out.println(path);
    System.out.println("> "+output);
    Pipeline P;
    try {
      LoniToGalaxyConverter glc;
      glc = new LoniToGalaxyConverter();
     
      P = LoniSpecification.getXMLParser().parse(new File(path));
      Workflow W = (Workflow) glc.visit(P);
     
      try {
        GalaxySpecification.getJSONGenerator().generate(W, output);
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
   
    } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
   
  }
 
  public static void LoniToLoni(String path, String output){
    System.out.println(path);
    System.out.println("> "+output);
    Pipeline P;
    try {
      P = LoniSpecification.getXMLParser().parse(new File(path));
     
     
      try {
        LoniSpecification.getXMLGenerator().generate(P, output);
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
   
    } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
   
  }
 
 
 
 
  public static void main(String[] args){
    TestL2L();
    TestL2G();
   
    //TestLocalG2G();
    //TestWebG2G();
    //TestWebG2L();
    //TestLocalG2L();
   
    //TestTools();
   
   
  }
 
 
}
TOP

Related Classes of Test.GalaxyTestSuite

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.