4575 |
15 Sep 17 |
nicklas |
1 |
package net.sf.basedb.relax.dao; |
4575 |
15 Sep 17 |
nicklas |
2 |
|
4575 |
15 Sep 17 |
nicklas |
3 |
import java.lang.reflect.Field; |
4575 |
15 Sep 17 |
nicklas |
4 |
import java.util.List; |
4575 |
15 Sep 17 |
nicklas |
5 |
|
4575 |
15 Sep 17 |
nicklas |
6 |
import net.sf.basedb.core.DataFileType; |
4575 |
15 Sep 17 |
nicklas |
7 |
import net.sf.basedb.core.DbControl; |
4575 |
15 Sep 17 |
nicklas |
8 |
import net.sf.basedb.core.Include; |
4575 |
15 Sep 17 |
nicklas |
9 |
import net.sf.basedb.core.InvalidDataException; |
4575 |
15 Sep 17 |
nicklas |
10 |
import net.sf.basedb.core.Item; |
4575 |
15 Sep 17 |
nicklas |
11 |
import net.sf.basedb.core.ItemNotFoundException; |
4575 |
15 Sep 17 |
nicklas |
12 |
import net.sf.basedb.core.ItemQuery; |
4575 |
15 Sep 17 |
nicklas |
13 |
import net.sf.basedb.core.Type; |
4575 |
15 Sep 17 |
nicklas |
14 |
import net.sf.basedb.core.query.Expressions; |
4575 |
15 Sep 17 |
nicklas |
15 |
import net.sf.basedb.core.query.Hql; |
4575 |
15 Sep 17 |
nicklas |
16 |
import net.sf.basedb.core.query.Restrictions; |
4575 |
15 Sep 17 |
nicklas |
17 |
|
4575 |
15 Sep 17 |
nicklas |
18 |
/** |
4575 |
15 Sep 17 |
nicklas |
Used to define file types for data files. |
4575 |
15 Sep 17 |
nicklas |
20 |
|
4575 |
15 Sep 17 |
nicklas |
@author nicklas |
4575 |
15 Sep 17 |
nicklas |
@since 1.1 |
4575 |
15 Sep 17 |
nicklas |
23 |
*/ |
4575 |
15 Sep 17 |
nicklas |
24 |
public class Datafiletype |
4575 |
15 Sep 17 |
nicklas |
25 |
{ |
4575 |
15 Sep 17 |
nicklas |
26 |
|
4575 |
15 Sep 17 |
nicklas |
27 |
/** |
4575 |
15 Sep 17 |
nicklas |
File type for Cufflinks fpkm_tracking files. |
4575 |
15 Sep 17 |
nicklas |
29 |
*/ |
4575 |
15 Sep 17 |
nicklas |
30 |
public static final Datafiletype FPKM = |
4575 |
15 Sep 17 |
nicklas |
31 |
new Datafiletype("FPKM tracking file", "sequencing.fpkm_tracking", |
4575 |
15 Sep 17 |
nicklas |
32 |
Item.RAWBIOASSAY, "fpkm_tracking", Subtype.RAW_DATA, |
4575 |
15 Sep 17 |
nicklas |
33 |
true, false, |
4575 |
15 Sep 17 |
nicklas |
34 |
"Gene- or isoform expression levels in Fragments Per Kilobase of exon model per Million mapped fragments."); |
4737 |
05 Apr 18 |
nicklas |
35 |
|
4737 |
05 Apr 18 |
nicklas |
36 |
/** |
4737 |
05 Apr 18 |
nicklas |
Generic raw data file. Is defined by BASE core. |
4737 |
05 Apr 18 |
nicklas |
@since 1.2 |
4737 |
05 Apr 18 |
nicklas |
39 |
*/ |
4737 |
05 Apr 18 |
nicklas |
40 |
public static final Datafiletype GENERIC_RAWDATA = |
4737 |
05 Apr 18 |
nicklas |
41 |
new Datafiletype("Generic raw data", "generic.rawdata", |
4737 |
05 Apr 18 |
nicklas |
42 |
Item.RAWBIOASSAY, null, Subtype.RAW_DATA, |
4737 |
05 Apr 18 |
nicklas |
43 |
false, true, null); |
5874 |
23 Mar 20 |
nicklas |
44 |
|
4575 |
15 Sep 17 |
nicklas |
45 |
/** |
5874 |
23 Mar 20 |
nicklas |
VCF file type. |
5874 |
23 Mar 20 |
nicklas |
@since 1.6 |
5874 |
23 Mar 20 |
nicklas |
48 |
*/ |
5874 |
23 Mar 20 |
nicklas |
49 |
public static final Datafiletype VCF = |
5874 |
23 Mar 20 |
nicklas |
50 |
new Datafiletype("VCF", "net.sf.basedb.reggie.vcf", |
5874 |
23 Mar 20 |
nicklas |
51 |
Item.RAWBIOASSAY, "vcf", Subtype.VARIANT_CALL_FORMAT, |
5874 |
23 Mar 20 |
nicklas |
52 |
true, true, "Variant call file"); |
5874 |
23 Mar 20 |
nicklas |
53 |
|
5874 |
23 Mar 20 |
nicklas |
54 |
|
5874 |
23 Mar 20 |
nicklas |
55 |
/** |
4575 |
15 Sep 17 |
nicklas |
Get the file type by name of the static constant defined in this class. |
4575 |
15 Sep 17 |
nicklas |
57 |
|
4575 |
15 Sep 17 |
nicklas |
@param cName The name of the static constant |
4575 |
15 Sep 17 |
nicklas |
@return A bioplate type object or null if not found |
4575 |
15 Sep 17 |
nicklas |
60 |
*/ |
4575 |
15 Sep 17 |
nicklas |
61 |
public static Datafiletype getByCName(String cName) |
4575 |
15 Sep 17 |
nicklas |
62 |
{ |
4575 |
15 Sep 17 |
nicklas |
63 |
if (cName == null) return null; |
4575 |
15 Sep 17 |
nicklas |
64 |
Datafiletype fs = null; |
4575 |
15 Sep 17 |
nicklas |
65 |
try |
4575 |
15 Sep 17 |
nicklas |
66 |
{ |
4575 |
15 Sep 17 |
nicklas |
67 |
Field f = Datafiletype.class.getDeclaredField(cName); |
4575 |
15 Sep 17 |
nicklas |
68 |
fs = (Datafiletype)f.get(null); |
4575 |
15 Sep 17 |
nicklas |
69 |
} |
4575 |
15 Sep 17 |
nicklas |
70 |
catch (NoSuchFieldException ex) |
4575 |
15 Sep 17 |
nicklas |
71 |
{} |
4575 |
15 Sep 17 |
nicklas |
72 |
catch (IllegalAccessException ex) |
4575 |
15 Sep 17 |
nicklas |
73 |
{} |
4575 |
15 Sep 17 |
nicklas |
74 |
catch (ClassCastException ex) |
4575 |
15 Sep 17 |
nicklas |
75 |
{} |
4575 |
15 Sep 17 |
nicklas |
76 |
return fs; |
4575 |
15 Sep 17 |
nicklas |
77 |
} |
4575 |
15 Sep 17 |
nicklas |
78 |
|
4575 |
15 Sep 17 |
nicklas |
79 |
private final String name; |
4575 |
15 Sep 17 |
nicklas |
80 |
private final String externalId; |
4575 |
15 Sep 17 |
nicklas |
81 |
private final Item itemType; |
4575 |
15 Sep 17 |
nicklas |
82 |
private final String fileExtension; |
4575 |
15 Sep 17 |
nicklas |
83 |
private final Subtype subtype; |
4575 |
15 Sep 17 |
nicklas |
84 |
private final boolean required; |
4575 |
15 Sep 17 |
nicklas |
85 |
private final boolean allowMultiple; |
4575 |
15 Sep 17 |
nicklas |
86 |
private final String description; |
4575 |
15 Sep 17 |
nicklas |
87 |
private int id; |
4575 |
15 Sep 17 |
nicklas |
88 |
|
4575 |
15 Sep 17 |
nicklas |
89 |
/** |
4575 |
15 Sep 17 |
nicklas |
Create a new definition |
4575 |
15 Sep 17 |
nicklas |
91 |
*/ |
4575 |
15 Sep 17 |
nicklas |
92 |
private Datafiletype(String name, String externalId, Item itemType, String fileExtension, Subtype subtype, boolean required, boolean allowMultiple, String description) |
4575 |
15 Sep 17 |
nicklas |
93 |
{ |
4575 |
15 Sep 17 |
nicklas |
94 |
this.name = name; |
4575 |
15 Sep 17 |
nicklas |
95 |
this.externalId = externalId; |
4575 |
15 Sep 17 |
nicklas |
96 |
this.itemType = itemType; |
4575 |
15 Sep 17 |
nicklas |
97 |
this.fileExtension = fileExtension; |
4575 |
15 Sep 17 |
nicklas |
98 |
this.subtype = subtype; |
4575 |
15 Sep 17 |
nicklas |
99 |
this.required = required; |
4575 |
15 Sep 17 |
nicklas |
100 |
this.allowMultiple = allowMultiple; |
4575 |
15 Sep 17 |
nicklas |
101 |
this.description = description; |
4575 |
15 Sep 17 |
nicklas |
102 |
} |
4575 |
15 Sep 17 |
nicklas |
103 |
|
4575 |
15 Sep 17 |
nicklas |
104 |
/** |
4575 |
15 Sep 17 |
nicklas |
Get the name of the biomaterial list. |
4575 |
15 Sep 17 |
nicklas |
106 |
*/ |
4575 |
15 Sep 17 |
nicklas |
107 |
public String getName() |
4575 |
15 Sep 17 |
nicklas |
108 |
{ |
4575 |
15 Sep 17 |
nicklas |
109 |
return name; |
4575 |
15 Sep 17 |
nicklas |
110 |
} |
4575 |
15 Sep 17 |
nicklas |
111 |
|
4575 |
15 Sep 17 |
nicklas |
112 |
/** |
4575 |
15 Sep 17 |
nicklas |
Get the list description. |
4575 |
15 Sep 17 |
nicklas |
114 |
*/ |
4575 |
15 Sep 17 |
nicklas |
115 |
public String getDescription() |
4575 |
15 Sep 17 |
nicklas |
116 |
{ |
4575 |
15 Sep 17 |
nicklas |
117 |
return description; |
4575 |
15 Sep 17 |
nicklas |
118 |
} |
4575 |
15 Sep 17 |
nicklas |
119 |
|
4575 |
15 Sep 17 |
nicklas |
120 |
/** |
4575 |
15 Sep 17 |
nicklas |
Get the external id. |
4575 |
15 Sep 17 |
nicklas |
122 |
*/ |
4575 |
15 Sep 17 |
nicklas |
123 |
public String getExternalId() |
4575 |
15 Sep 17 |
nicklas |
124 |
{ |
4575 |
15 Sep 17 |
nicklas |
125 |
return externalId; |
4575 |
15 Sep 17 |
nicklas |
126 |
} |
4575 |
15 Sep 17 |
nicklas |
127 |
|
4575 |
15 Sep 17 |
nicklas |
128 |
public Item getItemType() |
4575 |
15 Sep 17 |
nicklas |
129 |
{ |
4575 |
15 Sep 17 |
nicklas |
130 |
return itemType; |
4575 |
15 Sep 17 |
nicklas |
131 |
} |
4575 |
15 Sep 17 |
nicklas |
132 |
|
4575 |
15 Sep 17 |
nicklas |
133 |
public String getExtension() |
4575 |
15 Sep 17 |
nicklas |
134 |
{ |
4575 |
15 Sep 17 |
nicklas |
135 |
return fileExtension; |
4575 |
15 Sep 17 |
nicklas |
136 |
} |
4575 |
15 Sep 17 |
nicklas |
137 |
|
4575 |
15 Sep 17 |
nicklas |
138 |
public Subtype getSubtype() |
4575 |
15 Sep 17 |
nicklas |
139 |
{ |
4575 |
15 Sep 17 |
nicklas |
140 |
return subtype; |
4575 |
15 Sep 17 |
nicklas |
141 |
} |
4575 |
15 Sep 17 |
nicklas |
142 |
|
4575 |
15 Sep 17 |
nicklas |
143 |
public boolean isRequired() |
4575 |
15 Sep 17 |
nicklas |
144 |
{ |
4575 |
15 Sep 17 |
nicklas |
145 |
return required; |
4575 |
15 Sep 17 |
nicklas |
146 |
} |
4575 |
15 Sep 17 |
nicklas |
147 |
|
4575 |
15 Sep 17 |
nicklas |
148 |
public boolean getAllowMultiple() |
4575 |
15 Sep 17 |
nicklas |
149 |
{ |
4575 |
15 Sep 17 |
nicklas |
150 |
return allowMultiple; |
4575 |
15 Sep 17 |
nicklas |
151 |
} |
4575 |
15 Sep 17 |
nicklas |
152 |
|
4575 |
15 Sep 17 |
nicklas |
153 |
/** |
4575 |
15 Sep 17 |
nicklas |
Load the file type as a BASE item |
4575 |
15 Sep 17 |
nicklas |
@param dc The DbControl to use for database access |
4575 |
15 Sep 17 |
nicklas |
@return An FileServer object |
4575 |
15 Sep 17 |
nicklas |
157 |
*/ |
4575 |
15 Sep 17 |
nicklas |
158 |
public DataFileType load(DbControl dc) |
4575 |
15 Sep 17 |
nicklas |
159 |
{ |
4575 |
15 Sep 17 |
nicklas |
160 |
DataFileType type = null; |
4575 |
15 Sep 17 |
nicklas |
161 |
if (id == 0) |
4575 |
15 Sep 17 |
nicklas |
162 |
{ |
4575 |
15 Sep 17 |
nicklas |
163 |
List<DataFileType> result = list(dc); |
4575 |
15 Sep 17 |
nicklas |
164 |
if (result.size() == 0) |
4575 |
15 Sep 17 |
nicklas |
165 |
{ |
4575 |
15 Sep 17 |
nicklas |
166 |
throw new ItemNotFoundException("DataFileType["+getName()+"]"); |
4575 |
15 Sep 17 |
nicklas |
167 |
} |
4575 |
15 Sep 17 |
nicklas |
168 |
else if (result.size() > 1) |
4575 |
15 Sep 17 |
nicklas |
169 |
{ |
4575 |
15 Sep 17 |
nicklas |
170 |
throw new InvalidDataException("Found > 1 DataFileType["+getName()+"]"); |
4575 |
15 Sep 17 |
nicklas |
171 |
} |
4575 |
15 Sep 17 |
nicklas |
172 |
type = result.get(0); |
4575 |
15 Sep 17 |
nicklas |
173 |
id = type.getId(); |
4575 |
15 Sep 17 |
nicklas |
174 |
} |
4575 |
15 Sep 17 |
nicklas |
175 |
else |
4575 |
15 Sep 17 |
nicklas |
176 |
{ |
4575 |
15 Sep 17 |
nicklas |
177 |
type = DataFileType.getById(dc, id); |
4575 |
15 Sep 17 |
nicklas |
178 |
} |
4575 |
15 Sep 17 |
nicklas |
179 |
return type; |
4575 |
15 Sep 17 |
nicklas |
180 |
} |
4575 |
15 Sep 17 |
nicklas |
181 |
|
4575 |
15 Sep 17 |
nicklas |
182 |
/** |
4575 |
15 Sep 17 |
nicklas |
Load the file type as a BASE item. Same as {@link #load(DbControl)} but return null |
4575 |
15 Sep 17 |
nicklas |
if no BASE item is found instead of throwing an exception. |
4575 |
15 Sep 17 |
nicklas |
@param dc The DbControl to use for database access |
4575 |
15 Sep 17 |
nicklas |
@return A DataFileType object |
4575 |
15 Sep 17 |
nicklas |
187 |
*/ |
4575 |
15 Sep 17 |
nicklas |
188 |
public DataFileType get(DbControl dc) |
4575 |
15 Sep 17 |
nicklas |
189 |
{ |
4575 |
15 Sep 17 |
nicklas |
190 |
DataFileType type = null; |
4575 |
15 Sep 17 |
nicklas |
191 |
if (id == 0) |
4575 |
15 Sep 17 |
nicklas |
192 |
{ |
4575 |
15 Sep 17 |
nicklas |
193 |
List<DataFileType> result = list(dc); |
4575 |
15 Sep 17 |
nicklas |
194 |
if (result.size() == 1) |
4575 |
15 Sep 17 |
nicklas |
195 |
{ |
4575 |
15 Sep 17 |
nicklas |
196 |
type = result.get(0); |
4575 |
15 Sep 17 |
nicklas |
197 |
id = type.getId(); |
4575 |
15 Sep 17 |
nicklas |
198 |
} |
4575 |
15 Sep 17 |
nicklas |
199 |
} |
4575 |
15 Sep 17 |
nicklas |
200 |
else |
4575 |
15 Sep 17 |
nicklas |
201 |
{ |
4575 |
15 Sep 17 |
nicklas |
202 |
type = DataFileType.getById(dc, id); |
4575 |
15 Sep 17 |
nicklas |
203 |
} |
4575 |
15 Sep 17 |
nicklas |
204 |
return type; |
4575 |
15 Sep 17 |
nicklas |
205 |
} |
4575 |
15 Sep 17 |
nicklas |
206 |
|
4575 |
15 Sep 17 |
nicklas |
207 |
|
4575 |
15 Sep 17 |
nicklas |
208 |
/** |
4575 |
15 Sep 17 |
nicklas |
List all file server registered in BASE with an name matching this |
4575 |
15 Sep 17 |
nicklas |
definition. Normally, only a single file server should be returned. |
4575 |
15 Sep 17 |
nicklas |
211 |
*/ |
4575 |
15 Sep 17 |
nicklas |
212 |
public List<DataFileType> list(DbControl dc) |
4575 |
15 Sep 17 |
nicklas |
213 |
{ |
4575 |
15 Sep 17 |
nicklas |
214 |
ItemQuery<DataFileType> query = DataFileType.getQuery(); |
4575 |
15 Sep 17 |
nicklas |
215 |
query.restrict( |
4575 |
15 Sep 17 |
nicklas |
216 |
Restrictions.eq( |
4575 |
15 Sep 17 |
nicklas |
217 |
Hql.property("name"), |
4575 |
15 Sep 17 |
nicklas |
218 |
Expressions.parameter("name", getName(), Type.STRING) |
4575 |
15 Sep 17 |
nicklas |
219 |
)); |
4575 |
15 Sep 17 |
nicklas |
220 |
query.include(Include.ALL); |
4575 |
15 Sep 17 |
nicklas |
221 |
return query.list(dc); |
4575 |
15 Sep 17 |
nicklas |
222 |
} |
4575 |
15 Sep 17 |
nicklas |
223 |
|
4575 |
15 Sep 17 |
nicklas |
224 |
|
4575 |
15 Sep 17 |
nicklas |
225 |
} |