Skip to content

Commit 2664345

Browse files
authored
Issue 47265 - Data validation queries for dams and sires (#667)
1 parent 34345ea commit 2664345

5 files changed

Lines changed: 107 additions & 0 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
SELECT DISTINCT dam AS Id,
3+
gender,
4+
species
5+
FROM demographics
6+
WHERE dam IN (SELECT sire FROM demographics)
7+
8+
UNION
9+
10+
SELECT DISTINCT sire AS Id,
11+
gender,
12+
species
13+
FROM demographics
14+
WHERE sire IN (SELECT dam FROM demographics);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
SELECT *
2+
FROM (
3+
SELECT
4+
d1.Id,
5+
d1.gender,
6+
d1.species,
7+
d2.Id as damId,
8+
d2.species as damSpecies,
9+
d3.Id as sireId,
10+
d3.species as sireSpecies,
11+
CASE WHEN (d2.species IS NOT NULL AND d1.species != d2.species) AND
12+
(d3.species IS NOT NULL AND d1.species != d3.species)
13+
THEN TRUE
14+
ELSE FALSE
15+
END as parentSpeciesMismatch
16+
FROM demographics d1
17+
LEFT JOIN demographics d2 ON d1.dam = d2.Id
18+
LEFT JOIN demographics d3 ON d1.sire = d3.Id
19+
) d4
20+
WHERE d4.parentSpeciesMismatch = TRUE
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
SELECT *
2+
FROM (
3+
SELECT
4+
d1.Id,
5+
d1.gender,
6+
d1.species,
7+
d2.Id as damId,
8+
d2.gender as damGender,
9+
d3.Id as sireId,
10+
d3.gender as sireGender,
11+
CASE WHEN (d2.gender IS NOT NULL AND upper(d2.gender.meaning) NOT IN ('FEMALE', 'UNKNOWN', 'UNDETERMINED')) OR
12+
(d3.gender IS NOT NULL AND upper(d3.gender.meaning) NOT IN ('MALE', 'UNKNOWN', 'UNDETERMINED'))
13+
THEN TRUE
14+
ELSE FALSE
15+
END as parentSpeciesMismatch
16+
FROM demographics d1
17+
LEFT JOIN demographics d2 ON d1.dam = d2.Id
18+
LEFT JOIN demographics d3 ON d1.sire = d3.Id
19+
) d4
20+
WHERE d4.parentSpeciesMismatch = TRUE
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
SELECT *
2+
FROM (
3+
SELECT
4+
dem.Id,
5+
dem.gender,
6+
dem.species,
7+
dem.birth,
8+
dem.dam,
9+
damDem.birth as damBirth,
10+
dem.sire,
11+
sireDem.birth as sireBirth
12+
FROM demographics dem
13+
LEFT JOIN demographics damDem ON dem.dam = damDem.Id
14+
LEFT JOIN demographics sireDem ON dem.sire = sireDem.Id
15+
) t
16+
WHERE (t.birth <= t.damBirth OR t.birth <= t.sireBirth)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<div id="incorrect-gender"></div>
2+
<div id="incorrect-species"></div>
3+
<div id="incorrect-ids"></div>
4+
<div id="incorrect-age"></div>
5+
6+
<script type="text/javascript">
7+
Ext4.onReady(function (){
8+
9+
new LABKEY.QueryWebPart({
10+
renderTo: 'incorrect-gender',
11+
title: 'Parents having incorect gender',
12+
schemaName: 'study',
13+
queryName: 'parentsIncorrectGender',
14+
})
15+
16+
new LABKEY.QueryWebPart({
17+
renderTo: 'incorrect-species',
18+
title: 'Parents having different species than offspring',
19+
schemaName: 'study',
20+
queryName: 'parentsDifferentSpecies',
21+
})
22+
23+
new LABKEY.QueryWebPart({
24+
renderTo: 'incorrect-ids',
25+
title: 'Parents that are listed as both dam and sire',
26+
schemaName: 'study',
27+
queryName: 'animalIdsAsDamAndSire',
28+
})
29+
30+
new LABKEY.QueryWebPart({
31+
renderTo: 'incorrect-age',
32+
title: 'Dam/Sire younger than offspring',
33+
schemaName: 'study',
34+
queryName: 'parentsYoungerThanOffspring',
35+
})
36+
});
37+
</script>

0 commit comments

Comments
 (0)