From 85e09455620b2c7ff8acd1b679f16a2917e5510d Mon Sep 17 00:00:00 2001
From: worku005 <dirk-jan.vanworkum@wur.nl>
Date: Fri, 6 Jan 2023 17:46:19 +0100
Subject: [PATCH] removed global pantools_path from pantools code base

---
 .../nl/wur/bif/pantools/cli/AddFunctions.java |   5 +-
 .../pangenome/FunctionalAnnotations.java      | 170 +++++++++---------
 .../nl/wur/bif/pantools/utils/Globals.java    |  23 ---
 .../java/nl/wur/bif/pantools/utils/Utils.java |  15 +-
 4 files changed, 100 insertions(+), 113 deletions(-)

diff --git a/src/main/java/nl/wur/bif/pantools/cli/AddFunctions.java b/src/main/java/nl/wur/bif/pantools/cli/AddFunctions.java
index d69aad969..498d1f462 100644
--- a/src/main/java/nl/wur/bif/pantools/cli/AddFunctions.java
+++ b/src/main/java/nl/wur/bif/pantools/cli/AddFunctions.java
@@ -38,6 +38,9 @@ public class AddFunctions implements Callable<Integer> {
     @Option(names = "--function")
     String function;
 
+    @Option(names = "--functional-databases-directory")
+    Path functionalDatabasesPath;
+
     @Override
     public Integer call() throws IOException {
         pantools.createLogger(spec);
@@ -46,7 +49,7 @@ public class AddFunctions implements Callable<Integer> {
         pantools.setPangenomeGraph();
         setGlobalParameters(); //TODO: use local parameters instead
 
-        functionalAnnotations.add_functional_annotations();
+        functionalAnnotations.add_functional_annotations(functionalDatabasesPath);
         return 0;
     }
 
diff --git a/src/main/java/nl/wur/bif/pantools/pangenome/FunctionalAnnotations.java b/src/main/java/nl/wur/bif/pantools/pangenome/FunctionalAnnotations.java
index 3c6b80904..8f7c1eb97 100644
--- a/src/main/java/nl/wur/bif/pantools/pangenome/FunctionalAnnotations.java
+++ b/src/main/java/nl/wur/bif/pantools/pangenome/FunctionalAnnotations.java
@@ -11,6 +11,7 @@ import java.io.File;
 import java.io.FileReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
+import java.nio.file.Path;
 import java.text.DecimalFormat;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -3547,7 +3548,7 @@ public class FunctionalAnnotations {
      * --label
      * --annotations-file
      */
-    public void add_functional_annotations() {
+    public void add_functional_annotations(Path functionalDatabasesPath) {
         System.out.println("\nIncluding functional annotations into the pangenome\n");
         check_if_graphDb_is_available(); // starts up the graph database if needed
         if (INPUT_FILE == null || !check_if_file_exists(INPUT_FILE)) {
@@ -3572,8 +3573,8 @@ public class FunctionalAnnotations {
         try (Transaction tx = GRAPH_DB.beginTx()) {
             int total_go = (int) count_nodes(go_label); // count nodes with a specific label
             if (total_go == 0) {
-                checkIfDatabasesInputExists(log_builder);
-                includeFunctionalDatabases();
+                checkIfDatabasesInputExists(log_builder, functionalDatabasesPath);
+                includeFunctionalDatabases(functionalDatabasesPath);
             }
             annotation_node_map = find_all_F_annotation_nodes();
             tx.success();
@@ -4072,8 +4073,8 @@ public class FunctionalAnnotations {
      *
      * @param tigrId_GO
      */
-    public static void read_tigrfams_go_link(HashMap<String, ArrayList<String>> tigrId_GO) {
-        try (BufferedReader in = new BufferedReader(new FileReader(pantools_path + "/addons/tigrfam/TIGRFAMS_GO_LINK"))) {
+    private void read_tigrfams_go_link(HashMap<String, ArrayList<String>> tigrId_GO, Path tigrfamPath) {
+        try (BufferedReader in = new BufferedReader(new FileReader(tigrfamPath.resolve("TIGRFAMS_GO_LINK").toFile()))) {
             while (in.ready()) {
                 String line = in.readLine().trim();
                 if (line.equals("")) {
@@ -4088,10 +4089,8 @@ public class FunctionalAnnotations {
                 }
                 try_incr_AL_hashmap(tigrId_GO, line_array[0], line_array[1] + "#" + relation);
             }
-            in.close();
         } catch (IOException ioe) {
-            System.out.println("Unable to read: " + pantools_path + "/addons/tigrfam/TIGRFAMS_GO_LINK");
-            System.exit(1);
+            throw new RuntimeException("Unable to read " + tigrfamPath.resolve("TIGRFAMS_GO_LINK").toFile().getAbsolutePath(), ioe);
         }
     }
 
@@ -4099,8 +4098,8 @@ public class FunctionalAnnotations {
      *
      * @param tigrfam_roleId
      */
-    public static void read_tigrfams_role_link(HashMap<String, String> tigrfam_roleId) {
-        try (BufferedReader in = new BufferedReader(new FileReader(pantools_path + "/addons/tigrfam/TIGRFAMS_ROLE_LINK"))) {
+    public static void read_tigrfams_role_link(HashMap<String, String> tigrfam_roleId, Path tigrfamPath) {
+        try (BufferedReader in = new BufferedReader(new FileReader(tigrfamPath.resolve("TIGRFAMS_ROLE_LINK").toFile()))) {
             while (in.ready()) {
                 String line = in.readLine().trim();
                 if (line.equals("")) {
@@ -4110,9 +4109,8 @@ public class FunctionalAnnotations {
                 tigrfam_roleId.put(line_array[0], line_array[1]);
             }
             in.close();
-        } catch (IOException e) {
-            System.out.println("\nUnable to read: " + pantools_path + "/addons/tigrfam/TIGRFAMS_ROLE_LINK\n");
-            System.exit(1);
+        } catch (IOException ioe) {
+            throw new RuntimeException("Unable to read " + tigrfamPath.resolve("TIGRFAMS_ROLE_LINK").toFile().getAbsolutePath(), ioe);
         }
     }
 
@@ -4120,27 +4118,29 @@ public class FunctionalAnnotations {
      *
      * @param go_id_node_id
      */
-    public static void include_pfam(HashMap<String, Node> go_id_node_id) {
-        boolean pfamExistsA = check_if_file_exists(pantools_path + "addons/Pfam-A.clans.tsv");
-        boolean pfamExistsB = check_if_file_exists(pantools_path + "addons/gene_ontology.txt");
+    public static void include_pfam(HashMap<String, Node> go_id_node_id, Path functionalDatabasesPath) {
+        Path pfamPath = functionalDatabasesPath.resolve("Pfam-A.clans.tsv");
+        Path gene_ontologyPath = functionalDatabasesPath.resolve("gene_ontology.txt");
+
+        boolean pfamExistsA = check_if_file_exists(pfamPath.toFile());
+        boolean pfamExistsB = check_if_file_exists(gene_ontologyPath.toFile());
         if (!pfamExistsA || !pfamExistsB) {
             return; // one of the input files does not exist
         }
 
         HashMap<String, ArrayList<String>> pfam_go_map = new HashMap<>();
-        try (BufferedReader in = new BufferedReader(new FileReader(pantools_path + "/addons/gene_ontology.txt"))) {
+        try (BufferedReader in = new BufferedReader(new FileReader(gene_ontologyPath.toFile()))) {
             for (int c = 0; in.ready();) {
                 String line = in.readLine().trim();
                 String[] line_array = line.split("\t");
                 try_incr_AL_hashmap(pfam_go_map, line_array[0], line_array[1]);
             }
         } catch (IOException ioe) {
-            System.out.println("Unable to read: " + pantools_path + "/addons/gene_ontology.txt\n");
-            System.exit(1);
+            throw new RuntimeException("Unable to read " + gene_ontologyPath.toFile().getAbsolutePath(), ioe);
         }
 
         int counter = 0, go_counter = 0;
-        try (BufferedReader in = new BufferedReader(new FileReader(pantools_path + "/addons/Pfam-A.clans.tsv"))) {
+        try (BufferedReader in = new BufferedReader(new FileReader(pfamPath.toFile()))) {
             for (int c = 0; in.ready();) {
                 counter ++;
                 Node pfam_node = GRAPH_DB.createNode(pfam_label);
@@ -4164,8 +4164,7 @@ public class FunctionalAnnotations {
                 }
             }
         } catch (IOException ioe) {
-            System.out.println("Unable to read: " + pantools_path + "/addons/Pfam-A.clans.tsv\n");
-            System.exit(1);
+            throw new RuntimeException("Unable to read " + pfamPath.toFile().getAbsolutePath(), ioe);
         }
         System.out.println("Created " + counter + " 'pfam' nodes and connected them to " + go_counter + " 'GO' nodes");
     }
@@ -4174,12 +4173,13 @@ public class FunctionalAnnotations {
      * TIGRFAMs_15.0_INFO.tar.gz TIGRFAMS_GO_LINK TIGRFAMS_ROLE_LINK TIGR_ROLE_NAMES
      * @param go_id_node_id
      */
-    public void include_tigrfam(HashMap<String, Node> go_id_node_id) {
-        boolean tigrfamExistsA = check_if_file_exists(pantools_path + "addons/tigrfam/TIGRFAMS_GO_LINK");
-        boolean tigrfamExistsB = check_if_file_exists(pantools_path + "addons/tigrfam/TIGRFAMS_ROLE_LINK");
-        boolean tigrfamExistsC = check_if_file_exists(pantools_path + "addons/tigrfam/TIGR_ROLE_NAMES");
-        boolean tigrfamExistsD = check_if_file_exists(pantools_path + "addons/tigrfam/TIGR00001.INFO");
-        boolean tigrfamExistsE = check_if_file_exists(pantools_path + "addons/tigrfam/COMBINED_INFO_FILES");
+    public void include_tigrfam(HashMap<String, Node> go_id_node_id, Path functionalDatabasesPath) {
+        Path tigrfamPath = functionalDatabasesPath.resolve("tigrfam");
+        boolean tigrfamExistsA = check_if_file_exists(tigrfamPath.resolve("TIGRFAMS_GO_LINK").toFile());
+        boolean tigrfamExistsB = check_if_file_exists(tigrfamPath.resolve("TIGRFAMS_ROLE_LINK").toFile());
+        boolean tigrfamExistsC = check_if_file_exists(tigrfamPath.resolve("TIGR_ROLE_NAMES").toFile());
+        boolean tigrfamExistsD = check_if_file_exists(tigrfamPath.resolve("TIGR00001.INFO").toFile());
+        boolean tigrfamExistsE = check_if_file_exists(tigrfamPath.resolve("COMBINED_INFO_FILES").toFile());
         if (!tigrfamExistsA || !tigrfamExistsB || !tigrfamExistsC ) {
             return;
         }
@@ -4192,27 +4192,25 @@ public class FunctionalAnnotations {
         HashMap<String, Node> tigrfam_nodeId = new HashMap<>();
         HashMap<String, String> tigrfam_role_name = new HashMap<>();
         HashMap<String, ArrayList<String>> tigrfam_go = new HashMap<>();
-        File folder = new File(pantools_path + "/addons/tigrfam/");
-        String[] files = folder.list();
         boolean first_info_file = true;
-        for (String file : files) {
+        for (String file : tigrfamPath.toFile().list()) {
             if (file.contains("TIGRFAMS_GO_LINK")) { // the go terms have either NULL or contributes_to. for NULL I use is similar_to
-                read_tigrfams_go_link(tigrfam_go);
+                read_tigrfams_go_link(tigrfam_go, tigrfamPath);
             } else if (file.contains("TIGRFAMS_ROLE_LINK")) {
-                read_tigrfams_role_link(tigrfam_roleId);
+                read_tigrfams_role_link(tigrfam_roleId, tigrfamPath);
             } else if (file.contains("TIGR_ROLE_NAMES")) {
-                read_tigrfam_role_names(tigrfam_role_name);
+                read_tigrfam_role_names(tigrfam_role_name, tigrfamPath);
             } else if (file.contains(".INFO")) {
                 if (first_info_file) { // when .info files are found, a new COMBINED_INFO_FILES is made
-                    delete_file_full_path(pantools_path + "/addons/tigrfam/COMBINED_INFO_FILES");
+                    delete_file_full_path(tigrfamPath.resolve("COMBINED_INFO_FILES").toFile().getAbsolutePath());
                     System.out.println("New TIGRFAM .INFO files are found. Combining all of them into a single file.");
                     first_info_file = false;
                 }
-                read_tigrfam_info(file, tigrfam_nodeId);
+                read_tigrfam_info(file, tigrfam_nodeId, tigrfamPath);
             }
         }
 
-        int tigrfam_nodes = create_tigrfam_nodes(tigrfam_nodeId, tigrfam_roleId, tigrfam_role_name);
+        int tigrfam_nodes = create_tigrfam_nodes(tigrfam_nodeId, tigrfam_roleId, tigrfam_role_name, tigrfamPath);
         int created_relations = create_tigrfam_relations_to_go(tigrfam_nodeId, tigrfam_go, go_id_node_id);
         System.out.println("Created " + tigrfam_nodes + " 'tigrfam' nodes and connected them to " + created_relations + " 'GO' nodes\n");
     }
@@ -4255,11 +4253,13 @@ public class FunctionalAnnotations {
      * @param tigrfam_nodeId
      * @param tigrfam_roleId
      * @param tigrfam_role_name
+     * @param tigrfamPath
      * @return
      */
-    public static int create_tigrfam_nodes(HashMap<String, Node> tigrfam_nodeId, HashMap<String, String> tigrfam_roleId, HashMap<String, String> tigrfam_role_name) {
+    public static int create_tigrfam_nodes(HashMap<String, Node> tigrfam_nodeId, HashMap<String, String> tigrfam_roleId,
+                                           HashMap<String, String> tigrfam_role_name, Path tigrfamPath) {
         int total_nodes = 0;
-        try (BufferedReader in = new BufferedReader(new FileReader(pantools_path + "/addons/tigrfam/COMBINED_INFO_FILES"))) {
+        try (BufferedReader in = new BufferedReader(new FileReader(tigrfamPath.resolve("COMBINED_INFO_FILES").toFile()))) {
             Node tigrfam_node = GRAPH_DB.getNodeById(0);
             while (in.ready()) {
                 String line = in.readLine().trim();
@@ -4293,10 +4293,9 @@ public class FunctionalAnnotations {
                     tigrfam_node.setProperty("description", line);
                 }
             }
-        } catch (IOException e) {
-            System.out.println(pantools_path + "/addons/tigrfam/COMBINED_INFO does not exists. Did u replace the tigrfam files? "
-                    + "If so, check the manual for the correct way to this");
-            System.exit(1);
+        } catch (IOException ioe) {
+            throw new RuntimeException("Could not read " + tigrfamPath.resolve("COMBINED_INFO_FILES").toFile() +
+                    "Did u replace the tigrfam files? If so, check the manual for t he correct to this", ioe);
         }
         return total_nodes;
     }
@@ -4367,8 +4366,9 @@ public class FunctionalAnnotations {
      *
      * @param go_id_node_id
      */
-    public static void include_interpro(HashMap<String, Node> go_id_node_id) {
-        if (!check_if_file_exists(pantools_path + "addons/interpro.xml")) {
+    public static void include_interpro(HashMap<String, Node> go_id_node_id, Path functionalDatabasesPath) {
+        Path interproPath = functionalDatabasesPath.resolve("interpro.xml");
+        if (!check_if_file_exists(interproPath.toFile())) {
             return;
         }
         HashMap<Node, ArrayList<String>> interpro_GO = new HashMap<>();
@@ -4377,7 +4377,7 @@ public class FunctionalAnnotations {
         boolean name_line = false, abstract_line = false, skip_line = false;
         String description = "", interpro_term = "", interpro_type = "", interpro_name = "";
         Node interpro_node = GRAPH_DB.getNodeById(0);
-        try (BufferedReader in2 = new BufferedReader(new FileReader(pantools_path + "/addons/interpro.xml"))) {
+        try (BufferedReader in2 = new BufferedReader(new FileReader(interproPath.toFile()))) {
             for (int c = 0; in2.ready();) {
                 String line = in2.readLine().trim();
                 if (line.equals("")) {
@@ -4448,8 +4448,7 @@ public class FunctionalAnnotations {
                 }
             }
         } catch (IOException ioe) {
-            System.out.println("\nFailed to read: " + pantools_path + "/addons/interpro.xml" );
-            System.exit(1);
+            throw new RuntimeException("Could not read file " + interproPath.toFile().getAbsolutePath(), ioe);
         }
         System.out.println("Created " + interpro_counter + " 'interpro' nodes and connected them to " + go_counter + " 'GO' nodes");
         for (Node interpro_node1 : interpro_GO.keySet()) {
@@ -4468,13 +4467,14 @@ public class FunctionalAnnotations {
      *
      * @param go_id_node_id
      */
-    public static void build_go_hierarchy(HashMap<String, Node> go_id_node_id) {
-        if (!check_if_file_exists(pantools_path + "addons/go-basic.obo")){
+    public static void build_go_hierarchy(HashMap<String, Node> go_id_node_id, Path functionalDatabasesPath) {
+        Path goPath = functionalDatabasesPath.resolve("go-basic.obo");
+        if (!check_if_file_exists(goPath.toFile())) {
             return;
         }
         HashMap<String, ArrayList<String>> go_relations = new HashMap<>();
         int go_count = 0;
-        try (BufferedReader in2 = new BufferedReader(new FileReader(pantools_path + "addons/go-basic.obo"))) {
+        try (BufferedReader in2 = new BufferedReader(new FileReader(goPath.toFile()))) {
             Node go_node = GRAPH_DB.getNodeById(0);
             String go_str = "a";
             for (int c = 0; in2.ready();) {
@@ -4531,8 +4531,7 @@ public class FunctionalAnnotations {
                 }
             }
         } catch (IOException ioe) {
-            System.out.println("Unable to read: " + pantools_path + "addons/go-basic.obo\n");
-            System.exit(1);
+            throw new RuntimeException("Could not read file " + goPath.toFile().getAbsolutePath(), ioe);
         }
 
         // loop is used to count the number of relations between GO nodes
@@ -4676,8 +4675,8 @@ public class FunctionalAnnotations {
      *
      * @param tigrfam_role_name
      */
-    public static void read_tigrfam_role_names(HashMap<String, String> tigrfam_role_name) {
-        try (BufferedReader in = new BufferedReader(new FileReader(pantools_path + "/addons/tigrfam/TIGR_ROLE_NAMES"))) {
+    public static void read_tigrfam_role_names(HashMap<String, String> tigrfam_role_name, Path tigrfamPath) {
+        try (BufferedReader in = new BufferedReader(new FileReader(tigrfamPath.resolve("TIGR_ROLE_NAMES").toFile()))) {
             boolean mainrole = true;
             String both_roles = "";
             while (in.ready()) {
@@ -4697,9 +4696,8 @@ public class FunctionalAnnotations {
                 }
             }
             in.close();
-        } catch (IOException e) {
-            System.out.println("Unable to read: " + pantools_path + "/addons/tigrfam/TIGR_ROLE_NAMES\n");
-            System.exit(1);
+        } catch (IOException ioe) {
+            throw new RuntimeException("Unable to read " + tigrfamPath.resolve("TIGR_ROLE_NAMES").toFile().getAbsolutePath(), ioe);
         }
     }
 
@@ -4708,13 +4706,13 @@ public class FunctionalAnnotations {
      * four databases, stop if none of them exist
      * @param logBuilder
      */
-    public void checkIfDatabasesInputExists(StringBuilder logBuilder) {
+    public void checkIfDatabasesInputExists(StringBuilder logBuilder, Path functionalDatabasesPath) {
         int correctCount = 0;
         StringBuilder correct = new StringBuilder("Based on PanTools's .jar file the input directory was determined: "
-                + pantools_path + "addons/\nCorrect  : ");
+                + functionalDatabasesPath + "addons/\nCorrect  : ");
         StringBuilder incorrect = new StringBuilder("Incorrect: ");
-        StringBuilder downloadBuilder = new StringBuilder(" cd " + pantools_path + "addons/\n");
-        boolean goExists = check_if_file_exists(pantools_path + "addons/go-basic.obo");
+        StringBuilder downloadBuilder = new StringBuilder(" cd " + functionalDatabasesPath + "addons/\n");
+        boolean goExists = check_if_file_exists(functionalDatabasesPath + "addons/go-basic.obo");
         if (goExists) {
             correctCount++;
             correct.append("GO, ");
@@ -4722,8 +4720,8 @@ public class FunctionalAnnotations {
             downloadBuilder.append(" wget http://purl.obolibrary.org/obo/go/go-basic.obo\n");
             incorrect.append("GO, ");
         }
-        boolean pfamExistsA = check_if_file_exists(pantools_path + "addons/Pfam-A.clans.tsv");
-        boolean pfamExistsB = check_if_file_exists(pantools_path + "addons/gene_ontology.txt");
+        boolean pfamExistsA = check_if_file_exists(functionalDatabasesPath + "addons/Pfam-A.clans.tsv");
+        boolean pfamExistsB = check_if_file_exists(functionalDatabasesPath + "addons/gene_ontology.txt");
         if (pfamExistsA && pfamExistsB) {
             correctCount++;
             correct.append("Pfam, ");
@@ -4736,7 +4734,7 @@ public class FunctionalAnnotations {
             }
             incorrect.append("Pfam, ");
         }
-        boolean interproExists = check_if_file_exists(pantools_path + "addons/interpro.xml");
+        boolean interproExists = check_if_file_exists(functionalDatabasesPath + "addons/interpro.xml");
         if (interproExists) {
             correctCount++;
             correct.append("InterPro, ");
@@ -4745,17 +4743,17 @@ public class FunctionalAnnotations {
             incorrect.append("InterPro, ");
         }
 
-        boolean tigrfamExistsA = check_if_file_exists(pantools_path + "addons/tigrfam/TIGRFAMS_GO_LINK");
-        boolean tigrfamExistsB = check_if_file_exists(pantools_path + "addons/tigrfam/TIGRFAMS_ROLE_LINK");
-        boolean tigrfamExistsC = check_if_file_exists(pantools_path + "addons/tigrfam/TIGR_ROLE_NAMES");
-        boolean tigrfamExistsD = check_if_file_exists(pantools_path + "addons/tigrfam/TIGR00001.INFO");
-        boolean tigrfamExistsE = check_if_file_exists(pantools_path + "addons/tigrfam/COMBINED_INFO_FILES");
+        boolean tigrfamExistsA = check_if_file_exists(functionalDatabasesPath + "addons/tigrfam/TIGRFAMS_GO_LINK");
+        boolean tigrfamExistsB = check_if_file_exists(functionalDatabasesPath + "addons/tigrfam/TIGRFAMS_ROLE_LINK");
+        boolean tigrfamExistsC = check_if_file_exists(functionalDatabasesPath + "addons/tigrfam/TIGR_ROLE_NAMES");
+        boolean tigrfamExistsD = check_if_file_exists(functionalDatabasesPath + "addons/tigrfam/TIGR00001.INFO");
+        boolean tigrfamExistsE = check_if_file_exists(functionalDatabasesPath + "addons/tigrfam/COMBINED_INFO_FILES");
         if (tigrfamExistsA && tigrfamExistsB && tigrfamExistsC && ( tigrfamExistsD || tigrfamExistsE)) {
             correctCount++;
             correct.append("TIGRGAM");
         } else {
             incorrect.append("TIGRGAM");
-            downloadBuilder.append(" cd ").append(pantools_path).append("addons/tigrfam/\n");
+            downloadBuilder.append(" cd ").append(functionalDatabasesPath).append("addons/tigrfam/\n");
             if (!tigrfamExistsA) {
                 downloadBuilder.append(" wget https://ftp.ncbi.nlm.nih.gov/hmm/TIGRFAMs/release_15.0/TIGRFAMS_GO_LINK\n");
             }
@@ -4777,7 +4775,7 @@ public class FunctionalAnnotations {
         System.out.println("\r" + correct);
         System.out.println(incorrect);
 
-        if (!check_if_file_exists(pantools_path + "addons/interpro.xml")) {
+        if (!check_if_file_exists(functionalDatabasesPath + "addons/interpro.xml")) {
             String info = "If you want these databases to be included. This is how to proceed.\n"
                     + "\n"
                     + "1. Make sure there are no functions in the pangenome.\n"
@@ -4798,12 +4796,12 @@ public class FunctionalAnnotations {
         }
     }
 
-    /* Only needs to be run once per database
-
-     Requires files in addons directory release 15 of tigrfam
-     TIGRFAMS_GO_LINK, TIGRFAMS_ROLE_LINK, TIGR_ROLE_NAMES and the .info file
-    */
-    public void includeFunctionalDatabases() {
+    /** Only needs to be run once per database
+     * Requires files in addons directory release 15 of tigrfam
+     * TIGRFAMS_GO_LINK, TIGRFAMS_ROLE_LINK, TIGR_ROLE_NAMES and the .info file
+     * @param functionalDatabasesPath path to the directory that contains the functional databases
+     */
+    public void includeFunctionalDatabases(Path functionalDatabasesPath) {
         System.out.println("\rFirst time running this function. Including PFAM, InterPro annotations and TIGRFAM and building the GO hierarchy\n");
         HashMap<String, Node> go_id_node_id = new HashMap<>();
         int total_pfam_nodes = (int) count_nodes(pfam_label); // count nodes with a specific label
@@ -4826,10 +4824,10 @@ public class FunctionalAnnotations {
             System.out.println("InterPro nodes are already present");
             System.exit(1);
         }
-        build_go_hierarchy(go_id_node_id);
-        include_interpro(go_id_node_id);
-        include_pfam(go_id_node_id);
-        include_tigrfam(go_id_node_id);
+        build_go_hierarchy(go_id_node_id, functionalDatabasesPath);
+        include_interpro(go_id_node_id, functionalDatabasesPath);
+        include_pfam(go_id_node_id, functionalDatabasesPath);
+        include_tigrfam(go_id_node_id, functionalDatabasesPath);
     }
 
     /**
@@ -4837,9 +4835,9 @@ public class FunctionalAnnotations {
      * @param file
      * @param tigrId_nodeId
      */
-    public static void read_tigrfam_info(String file, HashMap<String, Node> tigrId_nodeId) {
+    public static void read_tigrfam_info(String file, HashMap<String, Node> tigrId_nodeId, Path tigrfamPath) {
         StringBuilder file_builder = new StringBuilder();
-        try (BufferedReader in = new BufferedReader(new FileReader(pantools_path + "/addons/tigrfam/" + file))) {
+        try (BufferedReader in = new BufferedReader(new FileReader(tigrfamPath.resolve(file).toFile()))) {
             while (in.ready()) {
                 String line = in.readLine().trim();
                 file_builder.append(line).append("\n");
@@ -4849,8 +4847,8 @@ public class FunctionalAnnotations {
             System.exit(1);
         }
         file_builder.append("\n");
-        append_SB_to_file_full_path(file_builder, pantools_path + "/addons/tigrfam/COMBINED_INFO_FILES");
-        delete_file_full_path(pantools_path + "/addons/tigrfam/" + file);
+        append_SB_to_file_full_path(file_builder, tigrfamPath.resolve("COMBINED_INFO_FILES").toFile().getAbsolutePath());
+        delete_file_full_path(tigrfamPath.resolve(file).toFile().getAbsolutePath());
     }
 
     /**
diff --git a/src/main/java/nl/wur/bif/pantools/utils/Globals.java b/src/main/java/nl/wur/bif/pantools/utils/Globals.java
index 636f835fa..48a30502c 100644
--- a/src/main/java/nl/wur/bif/pantools/utils/Globals.java
+++ b/src/main/java/nl/wur/bif/pantools/utils/Globals.java
@@ -136,7 +136,6 @@ public class Globals {
     public static String Mode = "0";
     public static String NODE_ID;
     public static Long NODE_ID_long;
-    public static String pantools_path; // the directory of /dist/pantools.jar
     public static String current_path;
     public static String SELECTED_NAME;
     public static String target_genome;
@@ -223,7 +222,6 @@ public class Globals {
     public static FunctionalAnnotations functionalAnnotations;
 
     public static void setGlobals(Pantools pantools) {
-        find_pantools_path();
         Path currentRelativePath = Paths.get("");
         current_path = currentRelativePath.toAbsolutePath() + "/";
 
@@ -270,25 +268,4 @@ public class Globals {
         if (selectGenomes.getInclude() != null) target_genome = selectGenomes.getInclude().stream().map(String::valueOf)
                 .collect(Collectors.joining(","));
     }
-
-    /**
-     * Determine the location of PanTools' GIT repository.
-     */
-    private static void find_pantools_path() {
-        String full_path = Pantools.class.getProtectionDomain().getCodeSource().getLocation().getPath();
-        String[] path_array;
-        if (full_path.contains("/target/")) { // .jar location when compiled with Maven
-            path_array = full_path.split("/target/");
-        } else if (full_path.contains("/dist/")) {  // .jar location when compiled with Ant
-            path_array = full_path.split("/dist/");
-        } else {
-            //path_array = new String[0];
-            throw new RuntimeException("No .jar file found in " + full_path + "dist/ or " + full_path + "target/");
-        }
-
-        if (!path_array[0].endsWith("/pantools")) {
-            throw new RuntimeException("PanTools' .jar file must be located inside the pantools/dist/ or pantools/target/ directories.");
-        }
-        pantools_path = path_array[0] + "/";
-    }
 }
diff --git a/src/main/java/nl/wur/bif/pantools/utils/Utils.java b/src/main/java/nl/wur/bif/pantools/utils/Utils.java
index 8138726c2..a66775dc1 100644
--- a/src/main/java/nl/wur/bif/pantools/utils/Utils.java
+++ b/src/main/java/nl/wur/bif/pantools/utils/Utils.java
@@ -599,9 +599,9 @@ public class Utils {
     }
 
     /**
-     * Returns the size of a file
-     * @param path
-     * @return
+     * Returns whether the file exists or not
+     * @param path Path to the file (String)
+     * @return True if file exists, False otherwise
      */
     public static boolean check_if_file_exists(String path) {
         Pantools.logger.debug("Checking existence of: {}", path);
@@ -615,6 +615,15 @@ public class Utils {
         return exists;
     }
 
+    /**
+     * Returns whether the file exists or not
+     * @param path Path to the file (File)
+     * @return True if file exists, False otherwise
+     */
+    public static boolean check_if_file_exists(File path) {
+        return check_if_file_exists(path.getAbsolutePath());
+    }
+
     /**
      *
      * @param target_node
-- 
GitLab