Skip to content

Commit 24567df

Browse files
committed
Add calculated field to mGAP table
1 parent 4bc3464 commit 24567df

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

mGAP/src/org/labkey/mgap/query/mGAPUserSchema.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,35 @@
11
package org.labkey.mgap.query;
22

3+
import org.apache.logging.log4j.Logger;
34
import org.jetbrains.annotations.NotNull;
45
import org.jetbrains.annotations.Nullable;
6+
import org.labkey.api.data.AbstractTableInfo;
57
import org.labkey.api.data.Container;
68
import org.labkey.api.data.ContainerFilter;
79
import org.labkey.api.data.DbSchema;
810
import org.labkey.api.data.DbSchemaType;
11+
import org.labkey.api.data.JdbcType;
12+
import org.labkey.api.data.SQLFragment;
913
import org.labkey.api.data.TableInfo;
14+
import org.labkey.api.gwt.client.FacetingBehaviorType;
1015
import org.labkey.api.ldk.table.ContainerScopedTable;
1116
import org.labkey.api.module.Module;
1217
import org.labkey.api.query.DefaultSchema;
18+
import org.labkey.api.query.DetailsURL;
19+
import org.labkey.api.query.ExprColumn;
1320
import org.labkey.api.query.QuerySchema;
1421
import org.labkey.api.query.SimpleUserSchema;
1522
import org.labkey.api.security.User;
23+
import org.labkey.api.util.logging.LogHelper;
1624
import org.labkey.mgap.mGAPSchema;
1725

1826
/**
1927
* Created by bimber on 3/28/2017.
2028
*/
2129
public class mGAPUserSchema extends SimpleUserSchema
2230
{
31+
private static final Logger _log = LogHelper.getLogger(mGAPUserSchema.class, "mGAP User Schema");
32+
2333
private mGAPUserSchema(User user, Container container, DbSchema schema)
2434
{
2535
super(mGAPSchema.NAME, null, user, container, schema);
@@ -56,6 +66,10 @@ else if (mGAPSchema.TABLE_VARIANT_CATALOG_RELEASES.equalsIgnoreCase(name))
5666
{
5767
return createWrappedVariantTable(name, sourceTable, cf);
5868
}
69+
else if (mGAPSchema.TABLE_RELEASE_TRACKS.equalsIgnoreCase(name))
70+
{
71+
return(customizeReleaseTracks(name, sourceTable, cf));
72+
}
5973

6074
return super.createWrappedTable(name, sourceTable, cf);
6175
}
@@ -64,4 +78,30 @@ private TableInfo createWrappedVariantTable(String name, TableInfo sourceTable,
6478
{
6579
return super.createWrappedTable(name, sourceTable, cf);
6680
}
81+
82+
private TableInfo customizeReleaseTracks(String name, TableInfo sourceTable, ContainerFilter cf)
83+
{
84+
if (sourceTable instanceof AbstractTableInfo ati)
85+
{
86+
String fieldName = "totalSamples";
87+
if (ati.getColumn(fieldName) == null)
88+
{
89+
SQLFragment sql = new SQLFragment("(SELECT count(distinct t.subjectId) as total FROM " + mGAPSchema.NAME + "." + mGAPSchema.TABLE_RELEASE_TRACK_SUBSETS + " t WHERE t.trackName = " + ExprColumn.STR_TABLE_ALIAS + ".trackName)");
90+
ExprColumn col = new ExprColumn(ati, name, sql, JdbcType.INTEGER, ati.getColumn("trackName"));
91+
col.setLabel("# Samples");
92+
col.setFacetingBehaviorType(FacetingBehaviorType.ALWAYS_OFF);
93+
col.setDescription("This column shows the total number of registered subject IDs for this track");
94+
col.setURL(DetailsURL.fromString("/query/executeQuery.view?schemaName=mgap&query.queryName=releaseTrackSubsets&query.trackName~eq=${trackName}", getContainer()));
95+
ati.addColumn(col);
96+
}
97+
98+
return createWrappedTable(name, ati, cf);
99+
}
100+
else
101+
{
102+
_log.error("mGapUserSchema.customizeReleaseTracks was passed a TableInfo that wasnt a AbstractTableInfo. Was: " + sourceTable.getClass().getName());
103+
}
104+
105+
return createWrappedTable(name, sourceTable, cf);
106+
}
67107
}

0 commit comments

Comments
 (0)