subprocess is the good module for running external programs from python (much better than the older os.system.

subprocess.check_call is a simple function for running an external program and checking that it worked.

In [1]:
from subprocess import check_call

Here's a unix-specific command to find where I installed cluster

In [2]:
!which cluster
/home/mvoorhie/bin//cluster

Simply invoke the program with no arguments.

  • The return value of 0 indicates that cluster thinks no arguments is fine.
  • Many programs would return non-zero in this situation, causeing check_call to throw an exception.
In [3]:
check_call(("/home/mvoorhie/bin/cluster"))
Out[3]:
0

Cluster the example data, using pearson distances (-g 1) and maximum linkage clustering (-m m), generating output cdt and gtr files prefixed with "test"

In [4]:
check_call(("/home/mvoorhie/bin/cluster",
            "-f","supp2data.cdt",
            "-u","test",
            "-m","m",
            "-g","1"))
Out[4]:
0

Here's where cluster3 is expected to live on OS X and Windows:

  • /Applications/Cluster.app/Contents/MacOS/Cluster
  • /Program Files/Stanford University/Cluster3/Cluster.com
  • /Program Files (x86)/Stanford University/Cluster3/Cluster.com

Unix-specific command to look at the most recent files in my working directory. I see that test.cdt and test.gtr have been created with non-zero sizes, implying that my clustering run worked.

Note that these output files are now linked on the website:

In [6]:
!ls -lrth | tail
-rw------- 1 mvoorhie mvoorhie  27K May 15 22:15 Day4.ipynb
-rw-rw-r-- 1 mvoorhie mvoorhie 220K May 15 22:15 Day4.html
-rw-rw-r-- 1 mvoorhie mvoorhie  86M May 18 10:04 eucliddistmatrix.txt
-rw-rw-r-- 1 mvoorhie mvoorhie 5.6K May 18 10:05 temp.ipynb
-rw------- 1 mvoorhie mvoorhie 3.0K May 18 10:44 Untitled3.ipynb
-rw-rw-r-- 1 mvoorhie mvoorhie 1.0M May 18 13:57 PCA_example.html
-rw------- 1 mvoorhie mvoorhie 974K May 18 15:17 PCA_example.ipynb
-rw-rw-r-- 1 mvoorhie mvoorhie  91K May 18 15:33 test.gtr
-rw-rw-r-- 1 mvoorhie mvoorhie 2.0M May 18 15:33 test.cdt
-rw------- 1 mvoorhie mvoorhie 7.1K May 18 15:39 Untitled4.ipynb

At this point, I opened the output files in JavaTreeView by selecting test.cdt from File->Open

In []: