rajanil / fastStructure

A variational framework for inferring population structure from SNP genotype data.
MIT License
134 stars 50 forks source link

distruct.py fails without X display (workaround included) #36

Open draeath opened 6 years ago

draeath commented 6 years ago

I found that the usage of matplotlib in distruct.py fails if X is not present:

  File "{snip}/python/pyenv/versions/2.7.14/lib/python2.7/lib-tk/Tkinter.py", line 1819, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable

To work around this, the following two lines should be included prior to import matplotlib.pyplot as plot:

import matplotlib as mpl 
mpl.use('svg')

For example, the top of the file looks like this:

import numpy as np
import matplotlib as mpl 
mpl.use('svg')
import matplotlib.pyplot as plot
import colorsys
import getopt
import sys, pdb 

def plot_admixture(admixture, population_indices, population_labels, title)

I have tested this solution and was able to generate an svg file from a headless node.

draeath commented 6 years ago

alternatively it could be configured in the users' context instead of in code, but this may be undesirable as it would effect other invocations of matplotlib by that user. This can be accomplished by setting backend : svg in the user's matplotlibrc