6373 |
07 Sep 21 |
nicklas |
1 |
package net.sf.basedb.varsearch.index; |
6373 |
07 Sep 21 |
nicklas |
2 |
|
6373 |
07 Sep 21 |
nicklas |
3 |
import java.util.ArrayList; |
6373 |
07 Sep 21 |
nicklas |
4 |
import java.util.List; |
6373 |
07 Sep 21 |
nicklas |
5 |
|
6373 |
07 Sep 21 |
nicklas |
6 |
import org.slf4j.LoggerFactory; |
6373 |
07 Sep 21 |
nicklas |
7 |
|
6373 |
07 Sep 21 |
nicklas |
8 |
import net.sf.basedb.core.AnyToAny; |
6373 |
07 Sep 21 |
nicklas |
9 |
import net.sf.basedb.core.DbControl; |
6373 |
07 Sep 21 |
nicklas |
10 |
import net.sf.basedb.core.File; |
6373 |
07 Sep 21 |
nicklas |
11 |
import net.sf.basedb.core.Item; |
6373 |
07 Sep 21 |
nicklas |
12 |
import net.sf.basedb.core.ItemQuery; |
6373 |
07 Sep 21 |
nicklas |
13 |
import net.sf.basedb.core.RawBioAssay; |
6373 |
07 Sep 21 |
nicklas |
14 |
import net.sf.basedb.core.query.Expressions; |
6373 |
07 Sep 21 |
nicklas |
15 |
import net.sf.basedb.core.query.Hql; |
6373 |
07 Sep 21 |
nicklas |
16 |
import net.sf.basedb.core.query.Restriction; |
6373 |
07 Sep 21 |
nicklas |
17 |
import net.sf.basedb.core.query.Restrictions; |
7074 |
24 Mar 23 |
nicklas |
18 |
import net.sf.basedb.util.extensions.logging.ExtensionsLog; |
7074 |
24 Mar 23 |
nicklas |
19 |
import net.sf.basedb.util.extensions.logging.ExtensionsLogger; |
7074 |
24 Mar 23 |
nicklas |
20 |
import net.sf.basedb.varsearch.service.VarSearchService; |
6373 |
07 Sep 21 |
nicklas |
21 |
|
6373 |
07 Sep 21 |
nicklas |
22 |
/** |
6373 |
07 Sep 21 |
nicklas |
VCF file locator implementation that find a single or multiple |
6373 |
07 Sep 21 |
nicklas |
files that are linked as data files of a given type. |
6373 |
07 Sep 21 |
nicklas |
@since 1.2 |
6373 |
07 Sep 21 |
nicklas |
26 |
*/ |
6373 |
07 Sep 21 |
nicklas |
27 |
public class AnyToAnyVcfLocator |
6373 |
07 Sep 21 |
nicklas |
28 |
implements VcfFileLocator |
6373 |
07 Sep 21 |
nicklas |
29 |
{ |
6373 |
07 Sep 21 |
nicklas |
30 |
|
7074 |
24 Mar 23 |
nicklas |
31 |
private static final ExtensionsLogger logger = |
7074 |
24 Mar 23 |
nicklas |
32 |
ExtensionsLog.getLogger(VarSearchService.ID, true).wrap(LoggerFactory.getLogger(AnyToAnyVcfLocator.class)); |
6373 |
07 Sep 21 |
nicklas |
33 |
|
6373 |
07 Sep 21 |
nicklas |
34 |
private final String linkName; |
6373 |
07 Sep 21 |
nicklas |
35 |
private final Restriction linkRestriction; |
6373 |
07 Sep 21 |
nicklas |
36 |
|
6373 |
07 Sep 21 |
nicklas |
37 |
/** |
6373 |
07 Sep 21 |
nicklas |
Find the file that is linked with the exakt name. |
6373 |
07 Sep 21 |
nicklas |
39 |
*/ |
6373 |
07 Sep 21 |
nicklas |
40 |
public AnyToAnyVcfLocator(String linkName) |
6373 |
07 Sep 21 |
nicklas |
41 |
{ |
6373 |
07 Sep 21 |
nicklas |
42 |
this.linkName = linkName; |
6373 |
07 Sep 21 |
nicklas |
43 |
this.linkRestriction = Restrictions.eq(Hql.property("name"), Expressions.string(linkName)); |
6373 |
07 Sep 21 |
nicklas |
44 |
} |
6373 |
07 Sep 21 |
nicklas |
45 |
|
6373 |
07 Sep 21 |
nicklas |
46 |
/** |
6373 |
07 Sep 21 |
nicklas |
Find all files that are linked matching the given restriction. The |
6373 |
07 Sep 21 |
nicklas |
linkName is not used except for logging. |
6373 |
07 Sep 21 |
nicklas |
49 |
*/ |
6373 |
07 Sep 21 |
nicklas |
50 |
public AnyToAnyVcfLocator(Restriction linkRestriction, String linkName) |
6373 |
07 Sep 21 |
nicklas |
51 |
{ |
6373 |
07 Sep 21 |
nicklas |
52 |
this.linkName = linkName; |
6373 |
07 Sep 21 |
nicklas |
53 |
this.linkRestriction = linkRestriction; |
6373 |
07 Sep 21 |
nicklas |
54 |
} |
6373 |
07 Sep 21 |
nicklas |
55 |
|
6373 |
07 Sep 21 |
nicklas |
56 |
|
6373 |
07 Sep 21 |
nicklas |
57 |
@Override |
6528 |
20 Dec 21 |
nicklas |
58 |
public List<VcfFile> getVcfFiles(DbControl dc, RawBioAssay rba) |
6373 |
07 Sep 21 |
nicklas |
59 |
{ |
6373 |
07 Sep 21 |
nicklas |
60 |
ItemQuery<AnyToAny> query = AnyToAny.getLinksFrom(rba); |
6373 |
07 Sep 21 |
nicklas |
61 |
query.restrict(Restrictions.eq(Hql.property("toType"), Expressions.integer(Item.FILE.getValue()))); |
6373 |
07 Sep 21 |
nicklas |
62 |
query.restrict(linkRestriction); |
6373 |
07 Sep 21 |
nicklas |
63 |
|
6528 |
20 Dec 21 |
nicklas |
64 |
List<VcfFile> vcfFiles = new ArrayList<>(); |
6373 |
07 Sep 21 |
nicklas |
65 |
for (AnyToAny link : query.list(dc)) |
6373 |
07 Sep 21 |
nicklas |
66 |
{ |
6528 |
20 Dec 21 |
nicklas |
67 |
vcfFiles.add(new VcfFile((File)link.getTo(), link)); |
6528 |
20 Dec 21 |
nicklas |
68 |
} |
6373 |
07 Sep 21 |
nicklas |
69 |
if (vcfFiles.size() == 0) |
6373 |
07 Sep 21 |
nicklas |
70 |
{ |
6373 |
07 Sep 21 |
nicklas |
71 |
logger.warn("No '" + linkName + "' link found for rawbioassay: " + rba.getName()); |
6373 |
07 Sep 21 |
nicklas |
72 |
} |
6373 |
07 Sep 21 |
nicklas |
73 |
return vcfFiles; |
6373 |
07 Sep 21 |
nicklas |
74 |
} |
6373 |
07 Sep 21 |
nicklas |
75 |
|
6373 |
07 Sep 21 |
nicklas |
76 |
|
6373 |
07 Sep 21 |
nicklas |
77 |
} |