7853 |
19 Oct 20 |
nicklas |
1 |
/* |
7853 |
19 Oct 20 |
nicklas |
$Id$ |
7853 |
19 Oct 20 |
nicklas |
3 |
|
7853 |
19 Oct 20 |
nicklas |
Copyright (C) 2020 Nicklas Nordborg |
7853 |
19 Oct 20 |
nicklas |
5 |
|
7853 |
19 Oct 20 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
7853 |
19 Oct 20 |
nicklas |
Available at http://base.thep.lu.se/ |
7853 |
19 Oct 20 |
nicklas |
8 |
|
7853 |
19 Oct 20 |
nicklas |
BASE is free software; you can redistribute it and/or |
7853 |
19 Oct 20 |
nicklas |
modify it under the terms of the GNU General Public License |
7853 |
19 Oct 20 |
nicklas |
as published by the Free Software Foundation; either version 3 |
7853 |
19 Oct 20 |
nicklas |
of the License, or (at your option) any later version. |
7853 |
19 Oct 20 |
nicklas |
13 |
|
7853 |
19 Oct 20 |
nicklas |
BASE is distributed in the hope that it will be useful, |
7853 |
19 Oct 20 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
7853 |
19 Oct 20 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
7853 |
19 Oct 20 |
nicklas |
GNU General Public License for more details. |
7853 |
19 Oct 20 |
nicklas |
18 |
|
7853 |
19 Oct 20 |
nicklas |
You should have received a copy of the GNU General Public License |
7853 |
19 Oct 20 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
7853 |
19 Oct 20 |
nicklas |
21 |
*/ |
7853 |
19 Oct 20 |
nicklas |
22 |
package net.sf.basedb.util; |
7853 |
19 Oct 20 |
nicklas |
23 |
|
7853 |
19 Oct 20 |
nicklas |
24 |
import net.sf.basedb.core.Item; |
7853 |
19 Oct 20 |
nicklas |
25 |
|
7853 |
19 Oct 20 |
nicklas |
26 |
/** |
7853 |
19 Oct 20 |
nicklas |
Class for holding statisics about any-to-any links between items. |
7853 |
19 Oct 20 |
nicklas |
28 |
|
7853 |
19 Oct 20 |
nicklas |
@author nicklas |
7853 |
19 Oct 20 |
nicklas |
@since 3.17 |
7853 |
19 Oct 20 |
nicklas |
31 |
*/ |
7853 |
19 Oct 20 |
nicklas |
32 |
public class AnyToAnyLinkStatistics |
7853 |
19 Oct 20 |
nicklas |
33 |
implements Comparable<AnyToAnyLinkStatistics> |
7853 |
19 Oct 20 |
nicklas |
34 |
{ |
7853 |
19 Oct 20 |
nicklas |
35 |
|
7853 |
19 Oct 20 |
nicklas |
36 |
private int sampleSize; |
7853 |
19 Oct 20 |
nicklas |
37 |
private String linkName; |
7853 |
19 Oct 20 |
nicklas |
38 |
private Item targetType; |
7853 |
19 Oct 20 |
nicklas |
39 |
private int count; |
7853 |
19 Oct 20 |
nicklas |
40 |
|
7853 |
19 Oct 20 |
nicklas |
41 |
public AnyToAnyLinkStatistics() |
7853 |
19 Oct 20 |
nicklas |
42 |
{} |
7853 |
19 Oct 20 |
nicklas |
43 |
|
7853 |
19 Oct 20 |
nicklas |
44 |
/** |
7853 |
19 Oct 20 |
nicklas |
Get the number of items that was sampled to generated the statistics. |
7853 |
19 Oct 20 |
nicklas |
46 |
*/ |
7853 |
19 Oct 20 |
nicklas |
47 |
public int getSampleSize() |
7853 |
19 Oct 20 |
nicklas |
48 |
{ |
7853 |
19 Oct 20 |
nicklas |
49 |
return sampleSize; |
7853 |
19 Oct 20 |
nicklas |
50 |
} |
7853 |
19 Oct 20 |
nicklas |
51 |
|
7853 |
19 Oct 20 |
nicklas |
52 |
public void setSampleSize(int sampleSize) |
7853 |
19 Oct 20 |
nicklas |
53 |
{ |
7853 |
19 Oct 20 |
nicklas |
54 |
this.sampleSize = sampleSize; |
7853 |
19 Oct 20 |
nicklas |
55 |
} |
7853 |
19 Oct 20 |
nicklas |
56 |
|
7853 |
19 Oct 20 |
nicklas |
57 |
/** |
7853 |
19 Oct 20 |
nicklas |
Get the name of the link. |
7853 |
19 Oct 20 |
nicklas |
59 |
*/ |
7853 |
19 Oct 20 |
nicklas |
60 |
public String getLinkName() |
7853 |
19 Oct 20 |
nicklas |
61 |
{ |
7853 |
19 Oct 20 |
nicklas |
62 |
return linkName; |
7853 |
19 Oct 20 |
nicklas |
63 |
} |
7853 |
19 Oct 20 |
nicklas |
64 |
|
7853 |
19 Oct 20 |
nicklas |
65 |
public void setLinkName(String linkName) |
7853 |
19 Oct 20 |
nicklas |
66 |
{ |
7853 |
19 Oct 20 |
nicklas |
67 |
this.linkName = linkName; |
7853 |
19 Oct 20 |
nicklas |
68 |
} |
7853 |
19 Oct 20 |
nicklas |
69 |
|
7853 |
19 Oct 20 |
nicklas |
70 |
/** |
7853 |
19 Oct 20 |
nicklas |
Get the item type of the target item for the link. |
7853 |
19 Oct 20 |
nicklas |
72 |
*/ |
7853 |
19 Oct 20 |
nicklas |
73 |
public Item getTargetType() |
7853 |
19 Oct 20 |
nicklas |
74 |
{ |
7853 |
19 Oct 20 |
nicklas |
75 |
return targetType; |
7853 |
19 Oct 20 |
nicklas |
76 |
} |
7853 |
19 Oct 20 |
nicklas |
77 |
|
7853 |
19 Oct 20 |
nicklas |
78 |
public void setTargetType(Item targetType) |
7853 |
19 Oct 20 |
nicklas |
79 |
{ |
7853 |
19 Oct 20 |
nicklas |
80 |
this.targetType = targetType; |
7853 |
19 Oct 20 |
nicklas |
81 |
} |
7853 |
19 Oct 20 |
nicklas |
82 |
|
7853 |
19 Oct 20 |
nicklas |
83 |
/** |
7853 |
19 Oct 20 |
nicklas |
Get the number of links that was found among the sampled items. |
7853 |
19 Oct 20 |
nicklas |
85 |
*/ |
7853 |
19 Oct 20 |
nicklas |
86 |
public int getCount() |
7853 |
19 Oct 20 |
nicklas |
87 |
{ |
7853 |
19 Oct 20 |
nicklas |
88 |
return count; |
7853 |
19 Oct 20 |
nicklas |
89 |
} |
7853 |
19 Oct 20 |
nicklas |
90 |
|
7853 |
19 Oct 20 |
nicklas |
91 |
public void setCount(int count) |
7853 |
19 Oct 20 |
nicklas |
92 |
{ |
7853 |
19 Oct 20 |
nicklas |
93 |
this.count = count; |
7853 |
19 Oct 20 |
nicklas |
94 |
} |
7853 |
19 Oct 20 |
nicklas |
95 |
|
7853 |
19 Oct 20 |
nicklas |
96 |
/** |
7853 |
19 Oct 20 |
nicklas |
Sort items by count, linkName and targetType. |
7853 |
19 Oct 20 |
nicklas |
98 |
*/ |
7853 |
19 Oct 20 |
nicklas |
99 |
@Override |
7853 |
19 Oct 20 |
nicklas |
100 |
public int compareTo(AnyToAnyLinkStatistics o) |
7853 |
19 Oct 20 |
nicklas |
101 |
{ |
7853 |
19 Oct 20 |
nicklas |
102 |
int result = count - o.count; |
7853 |
19 Oct 20 |
nicklas |
103 |
if (result == 0) linkName.compareTo(o.linkName); |
7853 |
19 Oct 20 |
nicklas |
104 |
if (result == 0) result = targetType.name().compareTo(o.targetType.name()); |
7853 |
19 Oct 20 |
nicklas |
105 |
return result; |
7853 |
19 Oct 20 |
nicklas |
106 |
} |
7853 |
19 Oct 20 |
nicklas |
107 |
|
7853 |
19 Oct 20 |
nicklas |
108 |
@Override |
7853 |
19 Oct 20 |
nicklas |
109 |
public int hashCode() |
7853 |
19 Oct 20 |
nicklas |
110 |
{ |
7853 |
19 Oct 20 |
nicklas |
111 |
return count + linkName.hashCode() + targetType.hashCode(); |
7853 |
19 Oct 20 |
nicklas |
112 |
} |
7853 |
19 Oct 20 |
nicklas |
113 |
|
7853 |
19 Oct 20 |
nicklas |
114 |
@Override |
7853 |
19 Oct 20 |
nicklas |
115 |
public boolean equals(Object o) |
7853 |
19 Oct 20 |
nicklas |
116 |
{ |
7853 |
19 Oct 20 |
nicklas |
117 |
if (o == null) return false; |
7853 |
19 Oct 20 |
nicklas |
118 |
if (!o.getClass().equals(getClass())) return false; |
7853 |
19 Oct 20 |
nicklas |
119 |
AnyToAnyLinkStatistics other = (AnyToAnyLinkStatistics)o; |
7853 |
19 Oct 20 |
nicklas |
120 |
return count == other.count && targetType == other.targetType && linkName.equals(other.linkName); |
7853 |
19 Oct 20 |
nicklas |
121 |
} |
7853 |
19 Oct 20 |
nicklas |
122 |
|
7853 |
19 Oct 20 |
nicklas |
123 |
@Override |
7853 |
19 Oct 20 |
nicklas |
124 |
public String toString() |
7853 |
19 Oct 20 |
nicklas |
125 |
{ |
7853 |
19 Oct 20 |
nicklas |
126 |
return linkName + "[" + targetType.name() + "]="+count; |
7853 |
19 Oct 20 |
nicklas |
127 |
} |
7853 |
19 Oct 20 |
nicklas |
128 |
|
7853 |
19 Oct 20 |
nicklas |
129 |
|
7853 |
19 Oct 20 |
nicklas |
130 |
/** |
7853 |
19 Oct 20 |
nicklas |
Options to specify how the statistics should be generated. |
7853 |
19 Oct 20 |
nicklas |
* @author nicklas |
7853 |
19 Oct 20 |
nicklas |
133 |
* |
7853 |
19 Oct 20 |
nicklas |
134 |
*/ |
7853 |
19 Oct 20 |
nicklas |
135 |
public static class Options |
7853 |
19 Oct 20 |
nicklas |
136 |
{ |
7853 |
19 Oct 20 |
nicklas |
137 |
|
7853 |
19 Oct 20 |
nicklas |
138 |
private int maxRandomSamples; |
7853 |
19 Oct 20 |
nicklas |
139 |
private int minCount; |
7853 |
19 Oct 20 |
nicklas |
140 |
private int minFraction; |
7853 |
19 Oct 20 |
nicklas |
141 |
|
7853 |
19 Oct 20 |
nicklas |
142 |
public Options() |
7853 |
19 Oct 20 |
nicklas |
143 |
{ |
7853 |
19 Oct 20 |
nicklas |
144 |
this.maxRandomSamples = 500; |
7853 |
19 Oct 20 |
nicklas |
145 |
this.minCount = 10; |
7853 |
19 Oct 20 |
nicklas |
146 |
this.minFraction = 50; |
7853 |
19 Oct 20 |
nicklas |
147 |
} |
7853 |
19 Oct 20 |
nicklas |
148 |
|
7853 |
19 Oct 20 |
nicklas |
149 |
/** |
7853 |
19 Oct 20 |
nicklas |
Set the maximum number of items to use for gathering the statistics. |
7853 |
19 Oct 20 |
nicklas |
The default value is 500. A higher value may affect performance. |
7853 |
19 Oct 20 |
nicklas |
152 |
*/ |
7853 |
19 Oct 20 |
nicklas |
153 |
public void setMaxRandomSamples(int maxRandomSamples) |
7853 |
19 Oct 20 |
nicklas |
154 |
{ |
7853 |
19 Oct 20 |
nicklas |
155 |
this.maxRandomSamples = maxRandomSamples; |
7853 |
19 Oct 20 |
nicklas |
156 |
} |
7853 |
19 Oct 20 |
nicklas |
157 |
|
7853 |
19 Oct 20 |
nicklas |
158 |
public int getMaxRandomSamples() |
7853 |
19 Oct 20 |
nicklas |
159 |
{ |
7853 |
19 Oct 20 |
nicklas |
160 |
return maxRandomSamples; |
7853 |
19 Oct 20 |
nicklas |
161 |
} |
7853 |
19 Oct 20 |
nicklas |
162 |
|
7853 |
19 Oct 20 |
nicklas |
163 |
/** |
7853 |
19 Oct 20 |
nicklas |
Do not return information about links with a count that is less |
7853 |
19 Oct 20 |
nicklas |
than this value. The default value is 10. This option is ignored |
7853 |
19 Oct 20 |
nicklas |
if the fraction yields a lower count (sampleSize / fraction). |
7853 |
19 Oct 20 |
nicklas |
167 |
*/ |
7853 |
19 Oct 20 |
nicklas |
168 |
public void setMinCount(int minCount) |
7853 |
19 Oct 20 |
nicklas |
169 |
{ |
7853 |
19 Oct 20 |
nicklas |
170 |
this.minCount = minCount; |
7853 |
19 Oct 20 |
nicklas |
171 |
} |
7853 |
19 Oct 20 |
nicklas |
172 |
|
7853 |
19 Oct 20 |
nicklas |
173 |
public int getMinCount() |
7853 |
19 Oct 20 |
nicklas |
174 |
{ |
7853 |
19 Oct 20 |
nicklas |
175 |
return minCount; |
7853 |
19 Oct 20 |
nicklas |
176 |
} |
7853 |
19 Oct 20 |
nicklas |
177 |
|
7853 |
19 Oct 20 |
nicklas |
178 |
/** |
7853 |
19 Oct 20 |
nicklas |
Do not return information about links if they are found |
7853 |
19 Oct 20 |
nicklas |
on less than the specified fraction of samples. The default |
7853 |
19 Oct 20 |
nicklas |
value is 50, which means that links that are found in less than |
7853 |
19 Oct 20 |
nicklas |
1 of 50 samples are ignored. This option is ignored if the |
7853 |
19 Oct 20 |
nicklas |
min count is lower. |
7853 |
19 Oct 20 |
nicklas |
184 |
*/ |
7853 |
19 Oct 20 |
nicklas |
185 |
public void setMinFraction(int minFraction) |
7853 |
19 Oct 20 |
nicklas |
186 |
{ |
7853 |
19 Oct 20 |
nicklas |
187 |
this.minFraction = minFraction; |
7853 |
19 Oct 20 |
nicklas |
188 |
} |
7853 |
19 Oct 20 |
nicklas |
189 |
|
7853 |
19 Oct 20 |
nicklas |
190 |
public int getMinFraction() |
7853 |
19 Oct 20 |
nicklas |
191 |
{ |
7853 |
19 Oct 20 |
nicklas |
192 |
return minFraction; |
7853 |
19 Oct 20 |
nicklas |
193 |
} |
7853 |
19 Oct 20 |
nicklas |
194 |
|
7853 |
19 Oct 20 |
nicklas |
195 |
} |
7853 |
19 Oct 20 |
nicklas |
196 |
} |