Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Genesys PGR
Genesys Backend
Commits
e1bb7d98
Commit
e1bb7d98
authored
Apr 23, 2015
by
Matija Obreza
Browse files
PDCI calculation and display
parent
0d3b6c25
Changes
9
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/genesys2/server/model/elastic/AccessionDetails.java
View file @
e1bb7d98
...
...
@@ -85,6 +85,9 @@ public class AccessionDetails {
private
boolean
historic
;
@Field
(
index
=
FieldIndex
.
not_analyzed
,
type
=
FieldType
.
String
)
private
String
bredCode
;
public
static
AccessionDetails
from
(
AccessionData
accession
)
{
AccessionDetails
ad
=
new
AccessionDetails
();
ad
.
version
=
accession
.
getVersion
();
...
...
@@ -159,6 +162,7 @@ public class AccessionDetails {
if
(
breeding
==
null
)
return
;
this
.
pedigree
=
StringUtils
.
defaultIfBlank
(
breeding
.
getPedigree
(),
null
);
this
.
bredCode
=
StringUtils
.
defaultIfBlank
(
breeding
.
getBreederCode
(),
null
);
}
public
void
exch
(
AccessionExchange
exch
)
{
...
...
@@ -188,7 +192,7 @@ public class AccessionDetails {
public
UUID
getUuid
()
{
return
uuid
;
}
public
void
setUuid
(
UUID
uuid
)
{
this
.
uuid
=
uuid
;
}
...
...
@@ -337,6 +341,14 @@ public class AccessionDetails {
this
.
coll
=
coll
;
}
public
String
getBredCode
()
{
return
bredCode
;
}
public
void
setBredCode
(
String
bredCode
)
{
this
.
bredCode
=
bredCode
;
}
public
String
getPedigree
()
{
return
pedigree
;
}
...
...
@@ -404,11 +416,11 @@ public class AccessionDetails {
public
boolean
getHistoric
()
{
return
historic
;
}
public
void
setHistoric
(
boolean
historic
)
{
this
.
historic
=
historic
;
}
public
void
networks
(
List
<
Organization
>
organizations
)
{
if
(
organizations
==
null
||
organizations
.
isEmpty
())
return
;
...
...
src/main/java/org/genesys2/server/model/genesys/PDCI.java
0 → 100644
View file @
e1bb7d98
/**
* Copyright 2015 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package
org.genesys2.server.model.genesys
;
import
java.io.Serializable
;
import
java.util.HashSet
;
import
java.util.Set
;
import
javax.persistence.PrePersist
;
import
javax.persistence.Transient
;
public
class
PDCI
implements
Serializable
{
public
static
final
String
[]
independentItems
=
{
"genus"
,
"species"
,
"spAuthor"
,
"subTaxa"
,
"subtAuthor"
,
"cropName"
,
"acqDate"
,
"sampStat"
,
"donorCode"
,
"donorNumb"
,
"otherNumb"
,
"duplSite"
,
"storage"
,
"donorName"
,
"duplInstName"
,
"acceUrl"
,
"mlsStat"
};
public
static
final
String
[]
dependentItems
=
{
"origCty"
,
"collSite"
,
"latitude"
,
"longitude"
,
"elevation"
,
"collDate"
,
"bredCode"
,
"ancest"
,
"collSrc"
,
"acceName"
,
"collNumb"
,
"collCode"
,
"collName"
};
private
Float
score
=
null
;
private
int
acqDate
=
0
;
private
int
sampStat
=
0
;
private
int
donorCode
=
0
;
private
int
genus
=
0
;
private
int
species
=
0
;
private
int
spAuthor
=
0
;
private
int
subTaxa
=
0
;
private
int
subtAuthor
=
0
;
private
int
donorNumb
=
0
;
private
int
otherNumb
=
0
;
private
int
duplSite
=
0
;
private
int
storage
=
0
;
private
int
donorName
=
0
;
private
int
duplInstName
=
0
;
private
int
acceUrl
=
0
;
private
int
mlsStat
=
0
;
private
int
origCty
=
0
;
private
int
latitude
=
0
;
private
int
longitude
=
0
;
private
int
collSite
=
0
;
private
int
elevation
=
0
;
private
int
collDate
=
0
;
private
int
collSrc
=
0
;
private
int
collNumb
=
0
;
private
int
collCode
=
0
;
private
int
collName
=
0
;
private
int
ancest
=
0
;
private
int
acceName
=
0
;
private
int
bredCode
=
0
;
private
int
cropName
=
0
;
@PrePersist
protected
void
prePersist
()
{
this
.
score
=
calculateScore
();
}
public
int
getAcqDate
()
{
return
acqDate
;
}
public
int
getSampStat
()
{
return
sampStat
;
}
public
int
getDonorCode
()
{
return
donorCode
;
}
public
int
getGenus
()
{
return
genus
;
}
public
int
getSpecies
()
{
return
species
;
}
public
int
getSpAuthor
()
{
return
spAuthor
;
}
public
int
getSubTaxa
()
{
return
subTaxa
;
}
public
int
getSubtAuthor
()
{
return
subtAuthor
;
}
public
int
getDonorNumb
()
{
return
donorNumb
;
}
public
int
getOtherNumb
()
{
return
otherNumb
;
}
public
int
getDuplSite
()
{
return
duplSite
;
}
public
int
getStorage
()
{
return
storage
;
}
public
int
getDonorName
()
{
return
donorName
;
}
public
int
getDuplInstName
()
{
return
duplInstName
;
}
public
int
getAcceUrl
()
{
return
acceUrl
;
}
public
int
getMlsStat
()
{
return
mlsStat
;
}
public
int
getOrigCty
()
{
return
origCty
;
}
public
int
getLatitude
()
{
return
latitude
;
}
public
int
getLongitude
()
{
return
longitude
;
}
public
int
getCollSite
()
{
return
collSite
;
}
public
int
getElevation
()
{
return
elevation
;
}
public
int
getCollDate
()
{
return
collDate
;
}
public
int
getCollSrc
()
{
return
collSrc
;
}
public
int
getCollNumb
()
{
return
collNumb
;
}
public
int
getCollCode
()
{
return
collCode
;
}
public
int
getCollName
()
{
return
collName
;
}
public
int
getAncest
()
{
return
ancest
;
}
public
int
getAcceName
()
{
return
acceName
;
}
public
int
getBredCode
()
{
return
bredCode
;
}
public
void
setAcqDate
(
int
score
)
{
this
.
acqDate
=
score
;
}
public
void
setSampStat
(
int
score
)
{
this
.
sampStat
=
score
;
}
public
void
setDonorCode
(
int
score
)
{
this
.
donorCode
=
score
;
}
public
void
setGenus
(
int
score
)
{
this
.
genus
=
score
;
}
public
void
setSpecies
(
int
score
)
{
this
.
species
=
score
;
}
public
void
setSpAuthor
(
int
score
)
{
this
.
spAuthor
=
score
;
}
public
void
setSubTaxa
(
int
score
)
{
this
.
subTaxa
=
score
;
}
public
void
setSubtAuthor
(
int
score
)
{
this
.
subtAuthor
=
score
;
}
public
void
setDonorNumb
(
int
score
)
{
this
.
donorNumb
=
score
;
}
public
void
setOtherNumb
(
int
score
)
{
this
.
otherNumb
=
score
;
}
public
void
setDuplSite
(
int
score
)
{
this
.
duplSite
=
score
;
}
public
void
setStorage
(
int
score
)
{
this
.
storage
=
score
;
}
public
void
setDonorName
(
int
score
)
{
this
.
donorName
=
score
;
}
public
void
setDuplInstName
(
int
score
)
{
this
.
duplInstName
=
score
;
}
public
void
setAcceUrl
(
int
score
)
{
this
.
acceUrl
=
score
;
}
public
void
setMlsStat
(
int
score
)
{
this
.
mlsStat
=
score
;
}
public
void
setOrigCty
(
int
score
)
{
this
.
origCty
=
score
;
}
public
void
setLatitude
(
int
score
)
{
this
.
latitude
=
score
;
}
public
void
setLongitude
(
int
score
)
{
this
.
longitude
=
score
;
}
public
void
setCollSite
(
int
score
)
{
this
.
collSite
=
score
;
}
public
void
setElevation
(
int
score
)
{
this
.
elevation
=
score
;
}
public
void
setCollDate
(
int
score
)
{
this
.
collDate
=
score
;
}
public
void
setCollSrc
(
int
score
)
{
this
.
collSrc
=
score
;
}
public
void
setCollNumb
(
int
score
)
{
this
.
collNumb
=
score
;
}
public
void
setCollCode
(
int
score
)
{
this
.
collCode
=
score
;
}
public
void
setCollName
(
int
score
)
{
this
.
collName
=
score
;
}
public
void
setAncest
(
int
score
)
{
this
.
ancest
=
score
;
}
public
void
setAcceName
(
int
score
)
{
this
.
acceName
=
score
;
}
public
void
setBredCode
(
int
score
)
{
this
.
bredCode
=
score
;
}
public
Float
getScore
()
{
if
(
score
==
null
)
{
score
=
calculateScore
();
}
return
score
;
}
public
void
setScore
(
Float
score
)
{
this
.
score
=
score
;
}
private
Float
calculateScore
()
{
float
total
=
getTotal
();
return
total
/
100
f
;
}
@Transient
public
float
getTotal
()
{
float
score
=
0
;
score
+=
acqDate
;
score
+=
sampStat
;
score
+=
donorCode
;
score
+=
genus
;
score
+=
species
;
score
+=
spAuthor
;
score
+=
subTaxa
;
score
+=
subtAuthor
;
score
+=
donorNumb
;
score
+=
otherNumb
;
score
+=
duplSite
;
score
+=
storage
;
score
+=
donorName
;
score
+=
duplInstName
;
score
+=
acceUrl
;
score
+=
mlsStat
;
score
+=
origCty
;
score
+=
latitude
;
score
+=
longitude
;
score
+=
collSite
;
score
+=
elevation
;
score
+=
collDate
;
score
+=
collSrc
;
score
+=
collNumb
;
score
+=
collCode
;
score
+=
collName
;
score
+=
ancest
;
score
+=
acceName
;
score
+=
bredCode
;
score
+=
cropName
;
return
score
;
}
public
void
setCropName
(
int
score
)
{
this
.
cropName
=
score
;
}
public
int
getCropName
()
{
return
cropName
;
}
public
String
[]
getIndependentItems
()
{
return
independentItems
;
}
public
String
[]
getDependentItems
()
{
return
dependentItems
;
}
public
static
Set
<
String
>
getPdciItems
()
{
Set
<
String
>
descriptors
=
new
HashSet
<
String
>();
for
(
java
.
lang
.
reflect
.
Method
method
:
PDCI
.
class
.
getMethods
())
{
if
(
method
.
getName
().
startsWith
(
"get"
)
&&
method
.
getReturnType
()
==
int
.
class
)
{
String
str
=
method
.
getName
().
substring
(
3
);
descriptors
.
add
(
str
.
substring
(
0
,
1
).
toLowerCase
()
+
str
.
substring
(
1
));
}
}
return
descriptors
;
}
}
src/main/java/org/genesys2/server/service/GenesysService.java
View file @
e1bb7d98
...
...
@@ -199,10 +199,15 @@ public interface GenesysService {
List
<
Long
>
listAccessionsIds
(
Taxonomy2
taxonomy
);
public
static
class
AllStuff
{
public
AllStuff
(
L
ong
id
)
{
public
AllStuff
(
l
ong
id
)
{
this
.
id
=
id
;
}
public
AllStuff
(
AccessionData
accession
)
{
this
.
accession
=
accession
;
this
.
id
=
accession
.
getId
();
}
public
Long
id
;
public
AccessionData
accession
=
null
;
public
AccessionGeo
geo
=
null
;
...
...
src/main/java/org/genesys2/server/service/impl/GenesysServiceImpl.java
View file @
e1bb7d98
...
...
@@ -319,14 +319,17 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
public
AccessionDetails
getAccessionDetails
(
long
accessionId
)
{
AccessionData
accession
=
getAccession
(
accessionId
);
if
(
accession
==
null
)
AccessionData
accession
=
getAccessionData
(
accessionId
);
if
(
accession
==
null
)
{
LOG
.
warn
(
"No such accession with id="
+
accessionId
);
return
null
;
}
return
toAccessionDetails
(
loadAllStuff
(
accession
));
}
private
AccessionDetails
toAccessionDetails
(
AllStuff
all
)
{
// LOG.info("Converting to AccessionDetails " + all);
if
(
all
==
null
||
all
.
accession
==
null
)
return
null
;
...
...
@@ -432,7 +435,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
public
AllStuff
loadAllStuff
(
AccessionData
accession
)
{
if
(
accession
==
null
)
return
null
;
AllStuff
all
=
new
AllStuff
(
accession
.
getAccessionId
().
getId
()
);
AllStuff
all
=
new
AllStuff
(
accession
);
all
.
bred
=
listAccessionBreeding
(
accession
.
getAccessionId
());
all
.
collect
=
listAccessionCollect
(
accession
.
getAccessionId
());
all
.
exch
=
listAccessionExchange
(
accession
.
getAccessionId
());
...
...
@@ -582,11 +585,17 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
private
AccessionData
getAccessionData
(
AccessionId
accessionId
)
{
if
(
accessionId
==
null
)
return
null
;
Accession
a
=
accessionRepository
.
findOne
(
accessionId
.
getId
());
if
(
a
!=
null
)
return
getAccessionData
(
accessionId
.
getId
());
}
private
AccessionData
getAccessionData
(
Long
id
)
{
Accession
a
=
accessionRepository
.
findOne
(
id
);
if
(
a
!=
null
)
{
return
a
;
AccessionHistoric
ah
=
accessionHistoricRepository
.
findOne
(
accessionId
.
getId
());
return
ah
;
}
else
{
AccessionHistoric
ah
=
accessionHistoricRepository
.
findOne
(
id
);
return
ah
;
}
}
@Override
...
...
src/main/java/org/genesys2/server/service/impl/PDCICalculator.java
0 → 100644
View file @
e1bb7d98
/**
* Copyright 2015 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package
org.genesys2.server.service.impl
;
import
java.util.ArrayList
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.genesys2.server.model.elastic.AccessionDetails
;
import
org.genesys2.server.model.elastic.Alias
;
import
org.genesys2.server.model.elastic.Collect
;
import
org.genesys2.server.model.elastic.Geo
;
import
org.genesys2.server.model.elastic.Taxonomy
;
import
org.genesys2.server.model.genesys.AccessionAlias.AliasType
;
import
org.genesys2.server.model.genesys.PDCI
;
import
org.genesys2.server.service.GenesysService
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
/**
* Calculates PDCI value for an accession.
*
* <p>
* Theo van Hintum, Frank Menting and Elisabeth van Strien (2011). <b>Quality
* indicators for passport data in ex situ genebanks.</b> Plant Genetic Resources,
* 9, pp 478-485.
*
* doi:10.1017/S1479262111000682
* </p>
*/
@Component
public
class
PDCICalculator
implements
InitializingBean
{
public
static
final
Log
LOG
=
LogFactory
.
getLog
(
PDCICalculator
.
class
);
@Autowired
private
GenesysService
genesysService
;
@Override
public
void
afterPropertiesSet
()
throws
Exception
{
}
public
PDCI
getPdci
(
long
accessionId
)
{
return
calculatePDCI
(
accessionId
);
}
private
PDCI
calculatePDCI
(
long
accessionId
)
{
AccessionDetails
accessionDetails
=
genesysService
.
getAccessionDetails
(
accessionId
);
if
(
accessionDetails
==
null
)
{
LOG
.
warn
(
"No such accession "
+
accessionId
);
return
null
;
}
PDCI
pdci
=
new
PDCI
();
independentDescriptors
(
pdci
,
accessionDetails
);
switch
(
accessionDetails
.
getSampStat
()
==
null
?
-
1
:
accessionDetails
.
getSampStat
()
/
100
)
{
case
1
:
case
2
:
wildOrWeedy
(
pdci
,
accessionDetails
);
break
;
case
3
:
landrace
(
pdci
,
accessionDetails
);
break
;
case
4
:
breedingMaterial
(
pdci
,
accessionDetails
);
break
;
case
5
:
cultivar
(
pdci
,
accessionDetails
);
default
:
otherTypes
(
pdci
,
accessionDetails
);
}
return
pdci
;
}
private
void
in