Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package cz.mendelu.model;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.quarkus.runtime.annotations.RegisterForReflection;
import org.hibernate.annotations.CreationTimestamp;
import javax.persistence.*;
import java.util.*;
import java.util.stream.Collectors;
@Entity
@Table(name = "sequences")
public class Sequence extends UUIDPanacheEntity {
@JsonIgnore
@Column(name = "buffer_id")
public UUID bufferId;
public String name;
@Temporal(TemporalType.TIMESTAMP)
@CreationTimestamp
public Date created;
public SequenceType type;
public Boolean circular;
public Integer length;
public String ncbi;
@ElementCollection
public Set<String> tags;
@Column(name = "owner_id")
@JsonIgnore
public UUID ownerId;
@Column(name = "fasta_comment")
public String fastaComment;
@ElementCollection
@CollectionTable(name = "sequence_nucleic_counts")
@MapKeyColumn(name = "nucleic_counts_key")
@Column(name = "nucleic_counts")
public Map<Nucleotide, Integer> nucleicCounts;
public Map<Nucleotide, Integer> getNucleicCounts() {
return (nucleicCounts == null || nucleicCounts.isEmpty())
? null
: Collections.unmodifiableMap(nucleicCounts);
}
public static List<Sequence> findAllByOwnerIsNull() {
return list("ownerId IS NULL");
}
public static Optional<String> getNcbi(UUID id) {
Optional<Sequence> sequence = findByIdOptional(id);
return sequence.map(s -> s.ncbi);
}
public static Optional<String> getName(UUID id) {
Optional<Sequence> sequence = findByIdOptional(id);
return sequence.map(s -> s.name);
}
public static List<Sequence> findAll(UUID ownerId) {
return list("ownerId = ?1", ownerId);
}
public static List<Sequence> findAll(UUID ownerId, String tag) {
return list("ownerId = ?1 and ?2 member of tags", ownerId, tag);
}
public static Optional<Sequence> findById(UUID id, UUID ownerId) {
return find("id = ?1 and ownerId = ?2", id, ownerId)
.firstResultOptional();
}
public static List<String> findAllTags(UUID ownerId) {
List<TagRecord> tagRecords = Sequence.find("SELECT DISTINCT t FROM Sequence s, IN (s.tags) t WHERE s.ownerId = ?1", ownerId)
.project(TagRecord.class)
.list();
return tagRecords.stream()
.map(TagRecord::tag)
.collect(Collectors.toList());
}
public static List<Sequence> findByNcbi(String ncbi) {
return list("ncbi", ncbi);
}
@RegisterForReflection
public record TagRecord(String tag) {
}
}