Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/dereneaton/ipyrad
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacovercast committed Jul 10, 2018
2 parents fbf408f + 92c4ee9 commit f3f15b8
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion ipyrad/analysis/pca.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ def remove_samples(self, samps):
flt = (ac.max_allele() == 1) & (ac[:, :2].min(axis=1) > 1)
self.genotypes = self.genotypes.compress(flt, axis=0)

if len(self.samples_vcforder) < self.ncomponents:
self.ncomponents = len(self.samples_vcforder)
print(" INFO: Number of PCs may not exceed the number of samples.\n Setting number of PCs = {}".format(self.ncomponents))


def plot(self, pcs=[1, 2], ax=None, cmap=None, cdict=None, legend=True, title=None, outfile=None):
"""
Expand Down Expand Up @@ -287,7 +291,11 @@ def plot(self, pcs=[1, 2], ax=None, cmap=None, cdict=None, legend=True, title=No
allele_counts = self.genotypes.to_n_alt()

## Actually do the pca
if self.ncomponents > len(self.samples_vcforder):
self.ncomponents = len(self.samples_vcforder)
print(" INFO: # PCs < # samples. Forcing # PCs = {}".format(self.ncomponents))
coords, model = allel.stats.pca(allele_counts, n_components=self.ncomponents, scaler='patterson')

self.pcs = pd.DataFrame(coords,
index=self.samples_vcforder,
columns=["PC{}".format(x) for x in range(1,self.ncomponents+1)])
Expand All @@ -301,7 +309,8 @@ def plot(self, pcs=[1, 2], ax=None, cmap=None, cdict=None, legend=True, title=No


if not cmap and not cdict:
print("Using default cmap: Spectral")
if not self.quiet:
print(" Using default cmap: Spectral")
cmap = cm.get_cmap('Spectral')

if cmap:
Expand Down

0 comments on commit f3f15b8

Please sign in to comment.