Skip to content

Commit c32a2ae

Browse files
author
Michael P Schroeder
committed
Matrix Text file import: Add row annotations
1 parent 865ebdb commit c32a2ae

File tree

4 files changed

+73
-11
lines changed

4 files changed

+73
-11
lines changed

org.gitools.ui.app/src/main/java/org/gitools/ui/app/fileimport/wizard/text/SelectMatrixColumnsPage.form

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@
1414
<rowspec value="center:max(d;4px):noGrow"/>
1515
<rowspec value="top:4dlu:noGrow"/>
1616
<rowspec value="center:max(d;4px):noGrow"/>
17-
<rowspec value="top:5dlu:noGrow"/>
17+
<rowspec value="top:6dlu:noGrow"/>
18+
<rowspec value="center:max(d;4px):grow"/>
1819
<rowspec value="top:10dlu:noGrow"/>
1920
<rowspec value="center:max(d;4px):noGrow"/>
2021
<rowspec value="top:4dlu:noGrow"/>
2122
<rowspec value="center:max(d;4px):noGrow"/>
2223
<rowspec value="top:4dlu:noGrow"/>
2324
<rowspec value="fill:d:grow"/>
25+
<rowspec value="top:4dlu:noGrow"/>
26+
<rowspec value="center:max(d;4px):noGrow"/>
2427
<colspec value="fill:max(d;4px):noGrow"/>
2528
<colspec value="left:4dlu:noGrow"/>
2629
<colspec value="fill:158px:grow"/>
@@ -33,14 +36,14 @@
3336
<colspec value="left:4dlu:noGrow"/>
3437
<colspec value="fill:max(d;4px):noGrow"/>
3538
<constraints>
36-
<xy x="20" y="20" width="713" height="381"/>
39+
<xy x="20" y="20" width="766" height="546"/>
3740
</constraints>
3841
<properties/>
3942
<border type="none"/>
4043
<children>
4144
<scrollpane id="1250">
4245
<constraints>
43-
<grid row="19" column="2" row-span="1" col-span="3" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
46+
<grid row="20" column="2" row-span="1" col-span="3" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
4447
<forms defaultalign-horz="false" defaultalign-vert="false"/>
4548
</constraints>
4649
<properties/>
@@ -54,7 +57,7 @@
5457
</scrollpane>
5558
<scrollpane id="72341">
5659
<constraints>
57-
<grid row="4" column="6" row-span="16" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
60+
<grid row="4" column="6" row-span="11" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
5861
<forms defaultalign-horz="false" defaultalign-vert="false"/>
5962
</constraints>
6063
<properties/>
@@ -100,7 +103,7 @@
100103
</component>
101104
<component id="14136" class="javax.swing.JLabel">
102105
<constraints>
103-
<grid row="15" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="9" fill="0" indent="0" use-parent-layout="false"/>
106+
<grid row="16" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="9" fill="0" indent="0" use-parent-layout="false"/>
104107
<forms top="0" left="5" bottom="0" right="0" defaultalign-vert="false"/>
105108
</constraints>
106109
<properties>
@@ -110,7 +113,7 @@
110113
</component>
111114
<scrollpane id="ad9ce">
112115
<constraints>
113-
<grid row="4" column="8" row-span="16" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
116+
<grid row="4" column="8" row-span="17" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
114117
<forms defaultalign-horz="false" defaultalign-vert="false"/>
115118
</constraints>
116119
<properties/>
@@ -220,14 +223,48 @@
220223
</component>
221224
<component id="a6d33" class="javax.swing.JLabel">
222225
<constraints>
223-
<grid row="17" column="2" row-span="1" col-span="3" vsize-policy="0" hsize-policy="0" anchor="9" fill="0" indent="0" use-parent-layout="false"/>
226+
<grid row="18" column="2" row-span="1" col-span="3" vsize-policy="0" hsize-policy="0" anchor="9" fill="0" indent="0" use-parent-layout="false"/>
224227
<forms top="0" left="5" bottom="0" right="0" defaultalign-vert="false"/>
225228
</constraints>
226229
<properties>
227230
<font/>
228231
<text value="Not to be loaded into heatmap"/>
229232
</properties>
230233
</component>
234+
<scrollpane id="476da">
235+
<constraints>
236+
<grid row="20" column="6" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
237+
<forms/>
238+
</constraints>
239+
<properties/>
240+
<border type="none"/>
241+
<children>
242+
<component id="c108b" class="javax.swing.JList" binding="rowAnnList">
243+
<constraints/>
244+
<properties/>
245+
</component>
246+
</children>
247+
</scrollpane>
248+
<component id="f0c19" class="javax.swing.JLabel">
249+
<constraints>
250+
<grid row="16" column="6" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="9" fill="0" indent="0" use-parent-layout="false"/>
251+
<forms defaultalign-vert="false"/>
252+
</constraints>
253+
<properties>
254+
<font style="1"/>
255+
<text value="Row annotation"/>
256+
</properties>
257+
</component>
258+
<component id="a8919" class="javax.swing.JLabel">
259+
<constraints>
260+
<grid row="18" column="6" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="9" fill="0" indent="0" use-parent-layout="false"/>
261+
<forms defaultalign-vert="false"/>
262+
</constraints>
263+
<properties>
264+
<font/>
265+
<text value="Metainfo related to the rows"/>
266+
</properties>
267+
</component>
231268
</children>
232269
</grid>
233270
</form>

org.gitools.ui.app/src/main/java/org/gitools/ui/app/fileimport/wizard/text/SelectMatrixColumnsPage.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public class SelectMatrixColumnsPage extends AbstractWizardPage implements IFile
5151
private JButton previewColumnIdsButton;
5252
private JFormattedTextField valueNameBox;
5353
private JLabel previewLabel;
54+
private JList rowAnnList;
5455
private List<FileHeader> allheaders;
5556
private List<List<FileField>> preview;
5657
private FileHeader lastSelected;
@@ -325,6 +326,8 @@ private void fillComponents() {
325326

326327
DefaultListModel<FileHeader> values = new DefaultListModel<FileHeader>();
327328
DefaultListModel<FileHeader> ignored = new DefaultListModel<FileHeader>();
329+
DefaultListModel<FileHeader> rowAnnotation = new DefaultListModel<FileHeader>();
330+
328331

329332
for (FileHeader header : allheaders) {
330333
if (header.getPos() != (int) rowIdsSpinner.getValue() - 1) {
@@ -339,6 +342,8 @@ private void fillComponents() {
339342

340343
initJList(valuesHeaderList, transferHandler, values, false, false);
341344
initJList(ignoredHeaderList, transferHandler, ignored, false, true);
345+
initJList(rowAnnList, transferHandler, rowAnnotation, false, false);
346+
342347
}
343348
}
344349

@@ -351,6 +356,7 @@ public void finish() throws ReaderProfileValidationException {
351356
profile.setColumnIdsPosition((int) columnIdsSpinner.getValue() - 1);
352357
profile.setValueColumns(getPositions(valuesHeaderList));
353358
profile.setIgnoredColumns(getPositions(ignoredHeaderList));
359+
profile.setRowAnnotationColumns(getPositions(rowAnnList));
354360
profile.setDataName(valueNameBox.getText());
355361
reader.getReaderProfile().validate(allheaders);
356362
}

org.gitools.ui.app/src/main/java/org/gitools/ui/app/fileimport/wizard/text/reader/MatrixReaderAssistant.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ public class MatrixReaderAssistant extends ReaderAssistant {
3636
private MatrixReaderProfile profile;
3737
private String currentRowId;
3838
private String[] currentFields;
39+
private String[] rowAnnFieldNames;
40+
private String[] rowAnnFields;
3941

4042
public MatrixReaderAssistant(FlatTextImporter reader) {
4143
super(reader);
@@ -48,12 +50,19 @@ public void fillMatrixAndAnnotations(IMatrix matrix, AnnotationMatrix rowAnnMatr
4850
Double value = DoubleTranslator.get().stringToValue(currentFields[i]);
4951
matrix.set(heatmapLayers[0], value, currentRowId, columnHeaders[i]);
5052
}
53+
if (hasRowAnnotation()) {
54+
for (int i = 0; i < rowAnnFields.length; i++) {
55+
rowAnnMatrix.setAnnotation(currentRowId, rowAnnFieldNames[i], rowAnnFields[i]);
56+
}
57+
}
5158
}
5259

5360
private void processLine() {
5461
String[] currentLine = reader.getCurrentLine();
5562
currentFields = extractFields(currentLine, profile.getValueColumns());
5663
currentRowId = currentLine[profile.getRowIdsPosition()];
64+
this.rowAnnFields = extractFields(currentLine, profile.getRowAnnotationColumns());
65+
5766
}
5867

5968
private String[] extractFields(String[] fields, int[] indices) {
@@ -74,21 +83,29 @@ public void update() {
7483
this.profile = (MatrixReaderProfile) reader.getReaderProfile();
7584
this.heatmapLayers = createHeatmapLayers();
7685
this.columnHeaders = getColumnHeaders();
86+
updateAnnotationNames();
7787
}
7888

7989
@Override
80-
public boolean hasColAnnotation() {
81-
return false;
90+
public boolean hasRowAnnotation() {
91+
return profile.getRowAnnotationColumns().length > 0;
8292
}
8393

8494
@Override
85-
public boolean hasRowAnnotation() {
95+
public boolean hasColAnnotation() {
8696
return false;
8797
}
8898

8999
@Override
90100
public void updateAnnotationNames() {
91-
//TODO
101+
List<FileHeader> fileHeaders = reader.getFileHeaders();
102+
if (hasRowAnnotation()) {
103+
int[] idx = profile.getRowAnnotationColumns();
104+
this.rowAnnFieldNames = new String[idx.length];
105+
for (int i = 0; i < idx.length; i++) {
106+
rowAnnFieldNames[i] = fileHeaders.get(idx[i]).toString();
107+
}
108+
}
92109
}
93110

94111
private String[] getColumnHeaders() {

org.gitools.utils/src/main/java/org/gitools/utils/readers/MatrixReaderProfile.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public static MatrixReaderProfile fromProfile(ReaderProfile profile) {
4747
MatrixReaderProfile newProfile = new MatrixReaderProfile();
4848
newProfile.setCommentChar(profile.getCommentChar());
4949
newProfile.setIgnoredColumns(profile.getIgnoredColumns());
50+
newProfile.setColumnAnnotationColumns(profile.getColumnAnnotationColumns());
51+
newProfile.setRowAnnotationColumns(profile.getRowAnnotationColumns());
5052
newProfile.setSeparator(profile.getSeparator());
5153
newProfile.setSkipLines(profile.getSkipLines());
5254
return newProfile;

0 commit comments

Comments
 (0)