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):
32 samples.append(sampleid)
33 phenotype_cat2_column = int(phenotype_cat2_column)
34 phenotype_cat1_column = int(phenotype_cat1_column)
35 if os.path.isdir(phenotype_path):
36 phenotype_files = os.scandir(phenotype_path)
38 phenotype_files = [phenotype_path]
39 for phenotype_file in phenotype_files:
40 with open(phenotype_file, 'rt', newline='') as phenotype:
41 dialect = csv.Sniffer().sniff(phenotype.read(1024))
43 for row in csv.reader(phenotype, dialect):
45 label = row[phenotype_cat1_column]
46 for sampleid in samples:
48 labels[sampleid] = label
49 if phenotype_cat2_column >= 0 and row[phenotype_cat2_column] != '0':
50 category[sampleid] = True
51 unknown_color = 'grey'
86 for sampleid in samples:
87 if (sampleid in labels) and (labels[sampleid] in labelcolors):
88 colors.append(labelcolors[labels[sampleid]])
90 colors.append(unknown_color)
92 from matplotlib.figure import Figure
93 from matplotlib.patches import Polygon
94 from matplotlib.backends.backend_agg import FigureCanvasAgg
96 ax = fig.add_subplot(111)
97 for marker in ['o', 'x']:
102 for unknownfirst in [True, False]:
103 for i, sampleid in enumerate(samples):
104 if ((colors[i] == unknown_color) == unknownfirst and
105 category.get(sampleid, False) == (marker == 'x')):
106 x.append(X[i,int(x_component)-1])
107 y.append(X[i,int(y_component)-1])
112 x = X[:,int(x_component)-1]
113 y = X[:,int(y_component)-1]
115 ax.scatter(x, y, c=c, s=60, marker=marker, alpha=0.5)
116 canvas = FigureCanvasAgg(fig)
117 canvas.print_figure(output_path, dpi=80)