4665 |
31 Jan 18 |
nicklas |
1 |
package net.sf.basedb.reggie.dao; |
4665 |
31 Jan 18 |
nicklas |
2 |
|
6041 |
11 Nov 20 |
nicklas |
3 |
import java.lang.reflect.Field; |
4673 |
08 Feb 18 |
nicklas |
4 |
import java.util.List; |
4673 |
08 Feb 18 |
nicklas |
5 |
|
4667 |
01 Feb 18 |
nicklas |
6 |
import net.sf.basedb.core.DbControl; |
4673 |
08 Feb 18 |
nicklas |
7 |
import net.sf.basedb.core.Include; |
4667 |
01 Feb 18 |
nicklas |
8 |
import net.sf.basedb.core.ItemQuery; |
4673 |
08 Feb 18 |
nicklas |
9 |
import net.sf.basedb.core.Platform; |
4667 |
01 Feb 18 |
nicklas |
10 |
import net.sf.basedb.core.PlatformVariant; |
4667 |
01 Feb 18 |
nicklas |
11 |
import net.sf.basedb.core.RawBioAssay; |
4667 |
01 Feb 18 |
nicklas |
12 |
import net.sf.basedb.core.RawDataType; |
4667 |
01 Feb 18 |
nicklas |
13 |
import net.sf.basedb.core.RawDataTypes; |
4673 |
08 Feb 18 |
nicklas |
14 |
import net.sf.basedb.core.Type; |
4667 |
01 Feb 18 |
nicklas |
15 |
import net.sf.basedb.core.query.Expressions; |
4667 |
01 Feb 18 |
nicklas |
16 |
import net.sf.basedb.core.query.Hql; |
4687 |
26 Feb 18 |
nicklas |
17 |
import net.sf.basedb.core.query.Restriction; |
4667 |
01 Feb 18 |
nicklas |
18 |
import net.sf.basedb.core.query.Restrictions; |
4667 |
01 Feb 18 |
nicklas |
19 |
|
4665 |
31 Jan 18 |
nicklas |
20 |
/** |
4665 |
31 Jan 18 |
nicklas |
Used to define raw data types. This class is temporary to solve |
4665 |
31 Jan 18 |
nicklas |
problems with existing code while implementing support for the |
4665 |
31 Jan 18 |
nicklas |
StringTie pipeline. |
4665 |
31 Jan 18 |
nicklas |
24 |
|
4665 |
31 Jan 18 |
nicklas |
@author nicklas |
4665 |
31 Jan 18 |
nicklas |
@since 4.15 |
4665 |
31 Jan 18 |
nicklas |
27 |
*/ |
4665 |
31 Jan 18 |
nicklas |
28 |
public class Rawdatatype |
4665 |
31 Jan 18 |
nicklas |
29 |
{ |
4665 |
31 Jan 18 |
nicklas |
30 |
|
4665 |
31 Jan 18 |
nicklas |
31 |
/** |
4665 |
31 Jan 18 |
nicklas |
The Cufflinks raw data type. |
4665 |
31 Jan 18 |
nicklas |
33 |
*/ |
6538 |
13 Jan 22 |
nicklas |
34 |
public static final Rawdatatype CUFFLINKS = new Rawdatatype("Cufflinks", "cufflinks", "Sequencing", Platform.SEQUENCING, PlatformVariant.SEQUENCING_EXPRESSION, "t"); |
4665 |
31 Jan 18 |
nicklas |
35 |
|
4667 |
01 Feb 18 |
nicklas |
36 |
/** |
4667 |
01 Feb 18 |
nicklas |
The StringTie raw data type. |
4667 |
01 Feb 18 |
nicklas |
38 |
*/ |
6538 |
13 Jan 22 |
nicklas |
39 |
public static final Rawdatatype STRINGTIE = new Rawdatatype("StringTie", "variant.sequencing.stringtie", "Sequencing", Platform.SEQUENCING, "sequencing.stringtie", "t"); |
5706 |
07 Nov 19 |
nicklas |
40 |
|
5706 |
07 Nov 19 |
nicklas |
41 |
/** |
5706 |
07 Nov 19 |
nicklas |
The VariantCall raw data type. |
5706 |
07 Nov 19 |
nicklas |
@since 4.24 |
5706 |
07 Nov 19 |
nicklas |
44 |
*/ |
6538 |
13 Jan 22 |
nicklas |
45 |
public static final Rawdatatype VARIANT_CALL = new Rawdatatype("VariantCall", "variant.sequencing.variant-call", "Sequencing", Platform.SEQUENCING, "sequencing.variant-call", "v"); |
5706 |
07 Nov 19 |
nicklas |
46 |
|
6041 |
11 Nov 20 |
nicklas |
47 |
/** |
6538 |
13 Jan 22 |
nicklas |
The OncoArray500K genotyping raw data type. |
6538 |
13 Jan 22 |
nicklas |
@since 4.35 |
6538 |
13 Jan 22 |
nicklas |
50 |
*/ |
6538 |
13 Jan 22 |
nicklas |
51 |
public static final Rawdatatype ONCOARRAY500K = new Rawdatatype("OncoArray500K", "variant.genotyping.oncoarray500K", "Genotyping", "genotyping", "genotyping.oncoarray500K", "v"); |
6538 |
13 Jan 22 |
nicklas |
52 |
|
6538 |
13 Jan 22 |
nicklas |
53 |
/** |
6041 |
11 Nov 20 |
nicklas |
Get the rawdata type by name of the static constant defined in this class. |
6041 |
11 Nov 20 |
nicklas |
55 |
|
6041 |
11 Nov 20 |
nicklas |
@param cName The name of the static constant |
6041 |
11 Nov 20 |
nicklas |
@return A rawdatatype object or null if not found |
6041 |
11 Nov 20 |
nicklas |
@since 4.28 |
6041 |
11 Nov 20 |
nicklas |
59 |
*/ |
6041 |
11 Nov 20 |
nicklas |
60 |
public static Rawdatatype getByCName(String cName) |
6041 |
11 Nov 20 |
nicklas |
61 |
{ |
6041 |
11 Nov 20 |
nicklas |
62 |
if (cName == null) return null; |
6041 |
11 Nov 20 |
nicklas |
63 |
Rawdatatype subtype = null; |
6041 |
11 Nov 20 |
nicklas |
64 |
try |
6041 |
11 Nov 20 |
nicklas |
65 |
{ |
6041 |
11 Nov 20 |
nicklas |
66 |
Field f = Rawdatatype.class.getDeclaredField(cName); |
6041 |
11 Nov 20 |
nicklas |
67 |
subtype = (Rawdatatype)f.get(null); |
6041 |
11 Nov 20 |
nicklas |
68 |
} |
6041 |
11 Nov 20 |
nicklas |
69 |
catch (NoSuchFieldException ex) |
6041 |
11 Nov 20 |
nicklas |
70 |
{} |
6041 |
11 Nov 20 |
nicklas |
71 |
catch (IllegalAccessException ex) |
6041 |
11 Nov 20 |
nicklas |
72 |
{} |
6041 |
11 Nov 20 |
nicklas |
73 |
catch (ClassCastException ex) |
6041 |
11 Nov 20 |
nicklas |
74 |
{} |
6041 |
11 Nov 20 |
nicklas |
75 |
return subtype; |
6041 |
11 Nov 20 |
nicklas |
76 |
} |
6041 |
11 Nov 20 |
nicklas |
77 |
|
6817 |
26 Aug 22 |
nicklas |
78 |
/** |
6817 |
26 Aug 22 |
nicklas |
Add a filter to the given query to only return items of a specfic |
6817 |
26 Aug 22 |
nicklas |
raw data type. The raw data type must be specified by setting the |
6817 |
26 Aug 22 |
nicklas |
"rawDataType" parameter on the query. |
6817 |
26 Aug 22 |
nicklas |
@since 4.40 |
6817 |
26 Aug 22 |
nicklas |
83 |
*/ |
6817 |
26 Aug 22 |
nicklas |
84 |
public static void createFilterParameter(DbControl dc, ItemQuery<?> query) |
6817 |
26 Aug 22 |
nicklas |
85 |
{ |
6817 |
26 Aug 22 |
nicklas |
86 |
createFilterParameter(dc, query, null); |
6817 |
26 Aug 22 |
nicklas |
87 |
} |
4667 |
01 Feb 18 |
nicklas |
88 |
|
6817 |
26 Aug 22 |
nicklas |
89 |
/** |
6817 |
26 Aug 22 |
nicklas |
Add a filter to the given query to only return items of a specfic |
6817 |
26 Aug 22 |
nicklas |
raw data type. The raw data type must be specified by setting the |
6817 |
26 Aug 22 |
nicklas |
"rawDataType" parameter on the query. |
6817 |
26 Aug 22 |
nicklas |
@since 4.40 |
6817 |
26 Aug 22 |
nicklas |
94 |
*/ |
6817 |
26 Aug 22 |
nicklas |
95 |
public static void createFilterParameter(DbControl dc, ItemQuery<?> query, String alias) |
6817 |
26 Aug 22 |
nicklas |
96 |
{ |
6817 |
26 Aug 22 |
nicklas |
97 |
query.restrict(Restrictions.eq(Hql.property(alias, "rawDataType"), Expressions.parameter("rawDataType", Type.STRING))); |
6817 |
26 Aug 22 |
nicklas |
98 |
} |
6817 |
26 Aug 22 |
nicklas |
99 |
|
6041 |
11 Nov 20 |
nicklas |
100 |
|
4667 |
01 Feb 18 |
nicklas |
101 |
private final String rawDataTypeId; |
4673 |
08 Feb 18 |
nicklas |
102 |
private final String platformExternalId; |
4667 |
01 Feb 18 |
nicklas |
103 |
private final String variantExternalId; |
5705 |
06 Nov 19 |
nicklas |
104 |
private final String itemSuffix; |
4667 |
01 Feb 18 |
nicklas |
105 |
|
4673 |
08 Feb 18 |
nicklas |
106 |
private final String name; |
6538 |
13 Jan 22 |
nicklas |
107 |
private final String platformName; |
4673 |
08 Feb 18 |
nicklas |
108 |
|
4673 |
08 Feb 18 |
nicklas |
109 |
private int platformId; |
4667 |
01 Feb 18 |
nicklas |
110 |
private int variantId; |
4667 |
01 Feb 18 |
nicklas |
111 |
|
6538 |
13 Jan 22 |
nicklas |
112 |
private Rawdatatype(String name, String id, String platformName, String platformId, String variantId, String itemSuffix) |
4667 |
01 Feb 18 |
nicklas |
113 |
{ |
4673 |
08 Feb 18 |
nicklas |
114 |
this.name = name; |
4667 |
01 Feb 18 |
nicklas |
115 |
this.rawDataTypeId = id; |
6538 |
13 Jan 22 |
nicklas |
116 |
this.platformName = platformName; |
4673 |
08 Feb 18 |
nicklas |
117 |
this.platformExternalId = platformId; |
4667 |
01 Feb 18 |
nicklas |
118 |
this.variantExternalId = variantId; |
5705 |
06 Nov 19 |
nicklas |
119 |
this.itemSuffix = itemSuffix; |
4667 |
01 Feb 18 |
nicklas |
120 |
} |
4665 |
31 Jan 18 |
nicklas |
121 |
|
4673 |
08 Feb 18 |
nicklas |
122 |
public String getName() |
4673 |
08 Feb 18 |
nicklas |
123 |
{ |
4673 |
08 Feb 18 |
nicklas |
124 |
return name; |
4673 |
08 Feb 18 |
nicklas |
125 |
} |
4667 |
01 Feb 18 |
nicklas |
126 |
|
4667 |
01 Feb 18 |
nicklas |
127 |
public String getId() |
4667 |
01 Feb 18 |
nicklas |
128 |
{ |
4667 |
01 Feb 18 |
nicklas |
129 |
return rawDataTypeId; |
4667 |
01 Feb 18 |
nicklas |
130 |
} |
4667 |
01 Feb 18 |
nicklas |
131 |
|
6538 |
13 Jan 22 |
nicklas |
132 |
public String getPlatformName() |
6538 |
13 Jan 22 |
nicklas |
133 |
{ |
6538 |
13 Jan 22 |
nicklas |
134 |
return platformName; |
6538 |
13 Jan 22 |
nicklas |
135 |
} |
6538 |
13 Jan 22 |
nicklas |
136 |
|
4673 |
08 Feb 18 |
nicklas |
137 |
public String getPlatformId() |
4673 |
08 Feb 18 |
nicklas |
138 |
{ |
4673 |
08 Feb 18 |
nicklas |
139 |
return platformExternalId; |
4673 |
08 Feb 18 |
nicklas |
140 |
} |
4673 |
08 Feb 18 |
nicklas |
141 |
|
4667 |
01 Feb 18 |
nicklas |
142 |
public String getVariantId() |
4667 |
01 Feb 18 |
nicklas |
143 |
{ |
4667 |
01 Feb 18 |
nicklas |
144 |
return variantExternalId; |
4667 |
01 Feb 18 |
nicklas |
145 |
} |
4667 |
01 Feb 18 |
nicklas |
146 |
|
5705 |
06 Nov 19 |
nicklas |
147 |
/** |
5705 |
06 Nov 19 |
nicklas |
Get the suffix to use for items of this type. |
5705 |
06 Nov 19 |
nicklas |
Null if no suffix is used. |
5705 |
06 Nov 19 |
nicklas |
@since 4.24 |
5705 |
06 Nov 19 |
nicklas |
151 |
*/ |
5705 |
06 Nov 19 |
nicklas |
152 |
public String getItemSuffix() |
5705 |
06 Nov 19 |
nicklas |
153 |
{ |
5705 |
06 Nov 19 |
nicklas |
154 |
return itemSuffix; |
5705 |
06 Nov 19 |
nicklas |
155 |
} |
5705 |
06 Nov 19 |
nicklas |
156 |
|
5705 |
06 Nov 19 |
nicklas |
157 |
|
4667 |
01 Feb 18 |
nicklas |
158 |
public RawDataType getRawDataType() |
4667 |
01 Feb 18 |
nicklas |
159 |
{ |
4667 |
01 Feb 18 |
nicklas |
160 |
return RawDataTypes.getSafeRawDataType(rawDataTypeId); |
4667 |
01 Feb 18 |
nicklas |
161 |
} |
4667 |
01 Feb 18 |
nicklas |
162 |
|
4673 |
08 Feb 18 |
nicklas |
163 |
public Platform getPlatform(DbControl dc) |
4673 |
08 Feb 18 |
nicklas |
164 |
{ |
4673 |
08 Feb 18 |
nicklas |
165 |
Platform p = null; |
4673 |
08 Feb 18 |
nicklas |
166 |
if (platformId == 0) |
4673 |
08 Feb 18 |
nicklas |
167 |
{ |
4673 |
08 Feb 18 |
nicklas |
168 |
p = Platform.getByExternalId(dc, platformExternalId); |
4673 |
08 Feb 18 |
nicklas |
169 |
platformId = p.getId(); |
4673 |
08 Feb 18 |
nicklas |
170 |
} |
4673 |
08 Feb 18 |
nicklas |
171 |
else |
4673 |
08 Feb 18 |
nicklas |
172 |
{ |
4673 |
08 Feb 18 |
nicklas |
173 |
p = Platform.getById(dc, platformId); |
4673 |
08 Feb 18 |
nicklas |
174 |
} |
4673 |
08 Feb 18 |
nicklas |
175 |
return p; |
4673 |
08 Feb 18 |
nicklas |
176 |
} |
4673 |
08 Feb 18 |
nicklas |
177 |
|
4667 |
01 Feb 18 |
nicklas |
178 |
public PlatformVariant getVariant(DbControl dc) |
4667 |
01 Feb 18 |
nicklas |
179 |
{ |
4667 |
01 Feb 18 |
nicklas |
180 |
PlatformVariant v = null; |
4667 |
01 Feb 18 |
nicklas |
181 |
if (variantId == 0) |
4667 |
01 Feb 18 |
nicklas |
182 |
{ |
4667 |
01 Feb 18 |
nicklas |
183 |
v = PlatformVariant.getByExternalId(dc, variantExternalId); |
4667 |
01 Feb 18 |
nicklas |
184 |
variantId = v.getId(); |
4667 |
01 Feb 18 |
nicklas |
185 |
} |
4667 |
01 Feb 18 |
nicklas |
186 |
else |
4667 |
01 Feb 18 |
nicklas |
187 |
{ |
4667 |
01 Feb 18 |
nicklas |
188 |
v = PlatformVariant.getById(dc, variantId); |
4667 |
01 Feb 18 |
nicklas |
189 |
} |
4667 |
01 Feb 18 |
nicklas |
190 |
return v; |
4667 |
01 Feb 18 |
nicklas |
191 |
} |
4667 |
01 Feb 18 |
nicklas |
192 |
|
4673 |
08 Feb 18 |
nicklas |
193 |
/** |
4673 |
08 Feb 18 |
nicklas |
List all platform variants registered in BASE with an external id matching this |
4673 |
08 Feb 18 |
nicklas |
definition. Normally, only a single item should be returned. |
4673 |
08 Feb 18 |
nicklas |
196 |
*/ |
4673 |
08 Feb 18 |
nicklas |
197 |
public List<PlatformVariant> list(DbControl dc) |
4673 |
08 Feb 18 |
nicklas |
198 |
{ |
4673 |
08 Feb 18 |
nicklas |
199 |
ItemQuery<PlatformVariant> query = PlatformVariant.getQuery(); |
4673 |
08 Feb 18 |
nicklas |
200 |
query.restrict( |
4673 |
08 Feb 18 |
nicklas |
201 |
Restrictions.eq( |
4673 |
08 Feb 18 |
nicklas |
202 |
Hql.property("externalId"), |
4673 |
08 Feb 18 |
nicklas |
203 |
Expressions.parameter("eid", getVariantId(), Type.STRING) |
4673 |
08 Feb 18 |
nicklas |
204 |
)); |
4673 |
08 Feb 18 |
nicklas |
205 |
query.include(Include.ALL); |
4673 |
08 Feb 18 |
nicklas |
206 |
return query.list(dc); |
4673 |
08 Feb 18 |
nicklas |
207 |
} |
4665 |
31 Jan 18 |
nicklas |
208 |
|
4667 |
01 Feb 18 |
nicklas |
209 |
public RawBioAssay createRawBioAssay(DbControl dc) |
4667 |
01 Feb 18 |
nicklas |
210 |
{ |
4667 |
01 Feb 18 |
nicklas |
211 |
return RawBioAssay.getNew(dc, getVariant(dc), getRawDataType()); |
4667 |
01 Feb 18 |
nicklas |
212 |
} |
4667 |
01 Feb 18 |
nicklas |
213 |
|
4667 |
01 Feb 18 |
nicklas |
214 |
/** |
4667 |
01 Feb 18 |
nicklas |
Add a filter restriction the given query so that it |
4667 |
01 Feb 18 |
nicklas |
only return items of this raw data type |
4667 |
01 Feb 18 |
nicklas |
217 |
|
4667 |
01 Feb 18 |
nicklas |
@param query The query to filter |
4667 |
01 Feb 18 |
nicklas |
219 |
*/ |
4667 |
01 Feb 18 |
nicklas |
220 |
public void addFilter(DbControl dc, ItemQuery<RawBioAssay> query) |
4667 |
01 Feb 18 |
nicklas |
221 |
{ |
4687 |
26 Feb 18 |
nicklas |
222 |
query.restrict(restriction(dc, null)); |
4667 |
01 Feb 18 |
nicklas |
223 |
} |
4667 |
01 Feb 18 |
nicklas |
224 |
|
4687 |
26 Feb 18 |
nicklas |
225 |
public Restriction restriction(DbControl dc, String alias) |
4687 |
26 Feb 18 |
nicklas |
226 |
{ |
4687 |
26 Feb 18 |
nicklas |
227 |
return Restrictions.eq(Hql.property(alias, "rawDataType"), Expressions.string(rawDataTypeId)); |
4687 |
26 Feb 18 |
nicklas |
228 |
} |
4687 |
26 Feb 18 |
nicklas |
229 |
|
4665 |
31 Jan 18 |
nicklas |
230 |
} |