Skip to content

Commit

Permalink
Merge pull request #101 from PavlidisLab/feature-display-uri-descript…
Browse files Browse the repository at this point in the history
…ions-2

Display URI descriptions
  • Loading branch information
oganm authored Jun 20, 2024
2 parents e3a0c3f + 03f242d commit 57592c9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 26 deletions.
17 changes: 9 additions & 8 deletions src/lib/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ function formatTerm(uri) {
/**
* Generate a human-readable description for a search settings.
* @param {SearchSettings} searchSettings
* @param {Map<String,Array<String>>} inferredTermsByCategory
* @param {Map<String,Map<String,String>>} inferredTermLabelsByCategory
* @returns {String}
*/
export function generateFilterDescription(searchSettings, inferredTermsByCategory) {
export function generateFilterDescription(searchSettings,inferredTermLabelsByCategory) {
const filter = [];
if (searchSettings.query) {
filter.push({ key: "Query", value: `"${searchSettings.query}"` });
Expand Down Expand Up @@ -198,14 +198,15 @@ export function generateFilterDescription(searchSettings, inferredTermsByCategor
acc[className].push(capitalizeFirstLetter(termName));
}
// drop the term from inferred annotations
let i;
if (inferredTermsByCategory[classUri] && (i = inferredTermsByCategory[classUri].indexOf(termUri)) !== -1) {
inferredTermsByCategory[classUri].splice(i, 1);
// annotations/children endpoint does not return itself so this part isn't really needed
// here in case that behaviour changes
if(inferredTermLabelsByCategory[classUri] && termUri in inferredTermLabelsByCategory[classUri]){
delete inferredTermLabelsByCategory[classUri][termUri]
}
return acc;
}, {});
for (let classUri in inferredTermsByCategory) {
const inferredTerms = inferredTermsByCategory[classUri];
for (let classUri in inferredTermLabelsByCategory) {
const inferredTerms = Object.values(inferredTermLabelsByCategory[classUri]);
if (inferredTerms) {
let className = searchSettings.annotations.filter(a => a.classUri === classUri)[0]?.className;
if (className) {
Expand All @@ -222,7 +223,7 @@ export function generateFilterDescription(searchSettings, inferredTermsByCategor
const annotations = annotationGroups[className];
const maxTermsToDisplay = 6 - annotations.length;
if (maxTermsToDisplay > 0) {
annotations.push(...inferredTerms.slice(0, maxTermsToDisplay).map(formatTerm));
annotations.push(...inferredTerms.slice(0, maxTermsToDisplay).map(capitalizeFirstLetter));
}
if (inferredTerms.length > maxTermsToDisplay) {
annotations.push((inferredTerms.length - maxTermsToDisplay) + " more terms...");
Expand Down
51 changes: 33 additions & 18 deletions src/views/Browser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ import { generateFilter, generateFilterDescription, generateFilterSummary } from
import Error from "@/components/Error.vue";
import { mapMutations, mapState } from "vuex";
import CodeSnippet from "@/components/CodeSnippet.vue";
import axios from "axios";

const MAX_CATEGORIES = 20;
const MAX_TERMS_PER_CATEGORY = 200;
Expand Down Expand Up @@ -217,7 +218,8 @@ export default {
},
downloadProgress: null,
expansionToggle: [],
tableWidth: ""
tableWidth: "",
inferredTermLabelsByCategory:{}
};
},
computed: {
Expand Down Expand Up @@ -378,32 +380,19 @@ export default {
return state.api.myself.code === 401 ? null : state.api.myself.data;
}
}),
annotations(){
return this.searchSettings.annotations
},
filterSummary() {
return generateFilterSummary(this.searchSettings);
},
filterDescription() {
return generateFilterDescription(this.searchSettings, this.inferredTermsByCategory);
return generateFilterDescription(this.searchSettings,this.inferredTermLabelsByCategory);
},
datasetsAllExpanded() {
return this.datasets.every(dataset => {
return !this.expansionToggle.some(item => item.accession === dataset.accession);
});
},
/**
* Inferred terms by category.
*/
inferredTermsByCategory() {
if (this.appliedFilter) {
return [
...this.appliedFilter.matchAll("allCharacteristics\\.categoryUri = (.+?) and allCharacteristics\\.valueUri in \\((.+?)\\)"),
...this.appliedFilter.matchAll("allCharacteristics\\.categoryUri = (.+?) and allCharacteristics\\.valueUri = (\\S+)")]
.reduce((acc, [_, category, terms]) => {
acc[category] = terms.split(", ");
return acc;
}, {});
} else {
return {};
}
}
},
methods: {
Expand Down Expand Up @@ -743,6 +732,32 @@ export default {
this.setLastError(err);
});
}
},
annotations: function(newVal){
// clear inferred terms of the previous call
this.inferredTermLabelsByCategory = {}

// updates inferredTemsLabelsByCategory
let url = baseUrl + "/rest/v2/annotations/children/"

newVal.forEach(value => {
let hede = axios.get(url,{
params: {uri:value.termUri, direct:false}
}).then(res => {
let inferredTerms = Object.fromEntries(res.data.map(value=>{
return [value.valueUri,value.value]
}))
this.$set(this.inferredTermLabelsByCategory,value.classUri, Object.assign({},this.inferredTermLabelsByCategory[value.classUri], inferredTerms))
//this.inferredTermLabelsByCategory[value.classUri] = Object.assign({},this.inferredTermLabelsByCategory[value.classUri], inferredTerms)
})
.catch(swallowCancellation)
.catch(err => {
if(err.message != 'Request failed with status code 404'){
console.error(`Error when requesting child terms: ${err.message}.`, err);
this.setLastError(err)
}
})
})
}
}
};
Expand Down

0 comments on commit 57592c9

Please sign in to comment.