Install old Java version for running PGDSpider on mac

2 minute read

Published:

PGDSpider is a very popular data conversion tool to prepare files for population genetic and phylogenetic programs. However, it did’t work anymore after I updated my mac (macOS 13.6, intel 2018). Today I finally figured installing an old Java version will do the job.

Install old Java version on mac

Step 1. Download PGDSpider. Double-click PGDSpider2.jar in the folder to see if it will run. If not, do step 2.

Step 2. Open your terminal and check your Java versions on your mac:

/usr/libexec/java_home -V

This is the output:

Matching Java Virtual Machines (3):
    20.0.2 (x86_64) "Oracle Corporation" - "Java SE 20.0.2" /Library/Java/JavaVirtualMachines/jdk-20.jdk/Contents/Home
    14.0.2 (x86_64) "Oracle Corporation" - "Java SE 14.0.2" /Library/Java/JavaVirtualMachines/jdk-14.0.2.jdk/Contents/Home
    1.8.333.02 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
/Library/Java/JavaVirtualMachines/jdk-20.jdk/Contents/Home

You can see the default Java version 20.0.2 is higher than JAVA7 and JAVA8 on PGDSpider website. But I do have an old JAVA8 version and the path to use this version is printed behind it: /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home. (Note there is a space in the middle of the path, use \ to escape space.)

You can test whether this old version runs PGDSpider:

/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java -Xmx1024m -Xms512m -jar /Applications/PGDSpider_2.1.1.5/PGDSpider2.jar
# Basically you copy and paste the path and add `/bin/java` after it. You need to modify the path to the folder you downloaded your `PGDSpider`. Mine is in folder `Applications`. 

If it runs, prefect! If not, you need a different version of Java. Follow step 3.

Step 3. Download an older version of Java. Here are the command to download JAVA 8.

brew tap adoptopenjdk/openjdk
brew install --cask adoptopenjdk8

After installing Java 8, check the path:

/usr/libexec/java_home -V

Now the output is:

Matching Java Virtual Machines (4):
    20.0.2 (x86_64) "Oracle Corporation" - "Java SE 20.0.2" /Library/Java/JavaVirtualMachines/jdk-20.jdk/Contents/Home
    14.0.2 (x86_64) "Oracle Corporation" - "Java SE 14.0.2" /Library/Java/JavaVirtualMachines/jdk-14.0.2.jdk/Contents/Home
    1.8.333.02 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
    1.8.0_292 (x86_64) "AdoptOpenJDK" - "AdoptOpenJDK 8" /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/jdk-20.jdk/Contents/Home

Copy and paste the path of newly-installed Java 8 to run PGDSpider:

/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/bin/java -Xmx1024m -Xms512m -jar /Applications/PGDSpider_2.1.1.5/PGDSpider2.jar 

I hope PGDSpider is working for you now! :)

Alternative ways to convert vcf to structure

  • R package radiator function genomic_converter
  • plink 1.9 recode.
    plink --vcf [vcf filename] --recode structure --out <base name>