1 # Copyright (C) The Lightning Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
18 phenotype_cat1_column,
19 phenotype_cat2_column,
22 X = numpy.load(input_path)
29 with open(samples_file, 'rt', newline='') as samplelist:
30 for row in csv.reader(samplelist):
34 samples.append(sampleid)
35 phenotype_cat2_column = int(phenotype_cat2_column)
36 phenotype_cat1_column = int(phenotype_cat1_column)
37 if os.path.isdir(phenotype_path):
38 phenotype_files = os.scandir(phenotype_path)
40 phenotype_files = [phenotype_path]
41 for phenotype_file in phenotype_files:
42 with open(phenotype_file, 'rt', newline='') as phenotype:
43 dialect = csv.Sniffer().sniff(phenotype.read(1024))
45 for row in csv.reader(phenotype, dialect):
47 label = row[phenotype_cat1_column]
48 for sampleid in samples:
50 labels[sampleid] = label
51 if phenotype_cat2_column >= 0 and row[phenotype_cat2_column] != '0':
52 category[sampleid] = True
53 unknown_color = 'grey'
88 for sampleid in samples:
89 if (sampleid in labels) and (labels[sampleid] in labelcolors):
90 colors.append(labelcolors[labels[sampleid]])
92 colors.append(unknown_color)
94 from matplotlib.figure import Figure
95 from matplotlib.patches import Polygon
96 from matplotlib.backends.backend_agg import FigureCanvasAgg
98 ax = fig.add_subplot(111)
99 for marker in ['o', 'x']:
104 for unknownfirst in [True, False]:
105 for i, sampleid in enumerate(samples):
106 if ((colors[i] == unknown_color) == unknownfirst and
107 category.get(sampleid, False) == (marker == 'x')):
108 x.append(X[i,int(x_component)-1])
109 y.append(X[i,int(y_component)-1])
114 x = X[:,int(x_component)-1]
115 y = X[:,int(y_component)-1]
117 ax.scatter(x, y, c=c, s=60, marker=marker, alpha=0.5)
118 canvas = FigureCanvasAgg(fig)
119 canvas.print_figure(output_path, dpi=80)