Skip to content

Commit

Permalink
Merge 6fcb3fc into 0fe36d1
Browse files Browse the repository at this point in the history
  • Loading branch information
mboudet committed Jul 25, 2023
2 parents 0fe36d1 + 6fcb3fc commit f48855a
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 28 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/github-publish-celery-flaskomics.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Publish Flaskomics Docker image to github
name: Publish Flaskomics Docker image to github

on:
push:
Expand All @@ -14,13 +14,14 @@ env:

jobs:
build-and-push-image:
if: github.repository == 'askomics/flaskomics'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
-
-
name: Checkout repository
uses: actions/checkout@v3

Expand Down Expand Up @@ -60,7 +61,7 @@ jobs:
uses: docker/build-push-action@v2
with:
context: .
file: ./docker/DockerfileCelery
file: ./docker/DockerfileCelery
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
5 changes: 3 additions & 2 deletions .github/workflows/github-publish-flaskomics.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Publish Flaskomics Docker image to github
name: Publish Flaskomics Docker image to github

on:
push:
Expand All @@ -14,13 +14,14 @@ env:

jobs:
build-and-push-image:
if: github.repository == 'askomics/flaskomics'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
-
-
name: Checkout repository
uses: actions/checkout@v3

Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ This changelog was started for release 4.2.0.
- Fixed Gff Faldo integration (was only integrating the last selected entity)
- Fixed an issue when using filters and an 'UNION' node
- Fixed an issue when launching a query with a 'linked' attribute toggled but unselected
- Fixed missing includeIn and includeInReference in bed files
- Fixed 'overlap_with' faldo query

### Changed

Expand Down
10 changes: 10 additions & 0 deletions askomics/libaskomics/BedFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,4 +306,14 @@ def generate_rdf_content(self):
self.graph_chunk.add((begin, rdflib.RDF.type, faldo_strand))
self.graph_chunk.add((end, rdflib.RDF.type, faldo_strand))

# blocks
block_base = self.settings.getint("triplestore", "block_size")
block_start = int(self.convert_type(feature.start + 1)) // block_base
block_end = int(self.convert_type(feature.end)) // block_base

for slice_block in range(block_start, block_end + 1):
self.graph_chunk.add((entity, self.namespace_internal['includeIn'], rdflib.Literal(int(slice_block))))
block_reference = self.rdfize(self.format_uri("{}_{}".format(feature.chrom, slice_block)))
self.graph_chunk.add((entity, self.namespace_internal["includeInReference"], block_reference))

yield
18 changes: 9 additions & 9 deletions askomics/libaskomics/GffFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,15 +412,15 @@ def generate_rdf_content(self):
self.graph_chunk.add((begin, rdflib.RDF.type, faldo_strand))
self.graph_chunk.add((end, rdflib.RDF.type, faldo_strand))

# blocks
block_base = self.settings.getint("triplestore", "block_size")
block_start = int(self.convert_type(feature.location.start)) // block_base
block_end = int(self.convert_type(feature.location.end)) // block_base

for slice_block in range(block_start, block_end + 1):
self.graph_chunk.add((entity, self.namespace_internal['includeIn'], rdflib.Literal(int(slice_block))))
block_reference = self.rdfize(self.format_uri("{}_{}".format(rec.id, slice_block)))
self.graph_chunk.add((entity, self.namespace_internal["includeInReference"], block_reference))
# blocks
block_base = self.settings.getint("triplestore", "block_size")
block_start = int(self.convert_type(feature.location.start)) // block_base
block_end = int(self.convert_type(feature.location.end)) // block_base

for slice_block in range(block_start, block_end + 1):
self.graph_chunk.add((entity, self.namespace_internal['includeIn'], rdflib.Literal(int(slice_block))))
block_reference = self.rdfize(self.format_uri("{}_{}".format(rec.id, slice_block)))
self.graph_chunk.add((entity, self.namespace_internal["includeInReference"], block_reference))

yield

Expand Down
43 changes: 36 additions & 7 deletions askomics/libaskomics/SparqlQuery.py
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,10 @@ def get_block_type(self, blockid):
"minusNode": "MINUS"
}

# Union sub-block
if '_' in blockid:
return "DEFAULT"

for node in self.json["nodes"]:
if node["type"] in ("unionNode", "minusNode"):
if node["specialNodeId"] == blockid:
Expand Down Expand Up @@ -970,6 +974,25 @@ def store_block(self, triple, blockid, sblockid, pblock_ids):
}, ]
})

def update_sub_block(self, block_dict, depths, type, value, current_depth):
depth = depths[current_depth]
if depth not in block_dict:
block_dict[depth] = {
"type": self.get_block_type(depth),
"triples": [],
"filters": [],
"values": [],
"sub_blocks": {}
}
# End of branch
if current_depth == len(depths) - 1:
block_dict[depth][type].append(value)
else:
self.update_sub_block(block_dict[depth]["sub_blocks"], depths, type, value, current_depth + 1)

def update_block_dict(self, depths, type, value):
self.update_sub_block(self.triples_blocks_dict, depths, type, value, 0)

def replace_variables_in_triples(self, var_to_replace):
"""Replace variables in triples
Expand Down Expand Up @@ -1036,8 +1059,9 @@ def get_source_of_special_node(self, special_node_id):
"""
for link in self.json["links"]:
if link["type"] == "specialLink":
if link["source"]["id"] == special_node_id:
return link["target"]["id"]
# Source is also a special node. Get source of source
if link["source"]['type'] in ['unionNode', 'minusNode']:
return self.get_source_of_special_node(link["source"]['id'])
if link["target"]["id"] == special_node_id:
return link["source"]["id"]
return None
Expand All @@ -1062,6 +1086,7 @@ def build_query_from_json(self, preview=False, for_editor=False):

self.triples = []
self.triples_blocks = []
self.triples_blocks_dict = {}

self.values = []
self.filters = []
Expand Down Expand Up @@ -1093,12 +1118,17 @@ def build_query_from_json(self, preview=False, for_editor=False):

# if link is special, replace the special node variable with its real node
if link["type"] == "specialLink":
special_node = link["source"] if link["source"]["type"] in ("unionNode", "minusNode") else link["target"]
real_node = link["target"] if link["source"]["type"] in ("unionNode", "minusNode") else link["source"]
special_node = link["target"]
real_node = link["source"]
real_node_id = real_node['id']

# Both end are special nodes.
if real_node['type'] in ['minusNode', 'unionNode']:
real_node_id = self.get_source_of_special_node(real_node_id)

var_to_replace.append((
self.format_sparql_variable("{}{}_uri".format(special_node["label"], special_node["id"])),
self.format_sparql_variable("{}{}_uri".format(real_node["label"], real_node["id"]))
self.format_sparql_variable("{}{}_uri".format(real_node["label"], real_node_id))
))

continue
Expand Down Expand Up @@ -1185,7 +1215,7 @@ def build_query_from_json(self, preview=False, for_editor=False):
), block_id, sblock_id, pblock_ids)

elif link["uri"] == "overlap_with":
self.store_filter("FILTER (({start2} >{equalsign} {start1} && {start2} <{equalsign} {end1}) || ({end2} >{equalsign} {start1} && {end2} <{equalsign} {end1}))".format(
self.store_filter("FILTER (({start2} >{equalsign} {start1} && {start2} <{equalsign} {end1}) || ({end2} >{equalsign} {start1} && {end2} <{equalsign} {end1}) || ({start1} >{equalsign} {start2} && {end1} <{equalsign} {end2}))".format(
start1=start_1,
start2=start_2,
end1=end_1,
Expand Down Expand Up @@ -1563,7 +1593,6 @@ def build_query_from_json(self, preview=False, for_editor=False):
self.replace_variables_in_triples(var_to_replace)

# Write the query

# query is for editor (no froms, no federated)
if for_editor:
query = """
Expand Down
50 changes: 43 additions & 7 deletions askomics/react/src/routes/query/query.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -432,20 +432,27 @@ export default class Query extends Component {
this.graphState.attr = this.graphState.attr.concat(nodeAttributes)
}

insertNode (uri, selected, suggested, special=null, forceSpecialId=null, specialNodeGroupId=null, specialPreviousIds=[null, null]) {
insertNode (uri, selected, suggested, special=null, forceSpecialId=null, specialNodeGroupId=null, specialPreviousIds=[null, null], newDepth=[]) {
/*
Insert a new node in the graphState
*/
let nodeId = this.getId()
let humanId = this.getHumanNodeId(uri)
let specialNodeId = null

let depth = [...newDepth]

if (special) {
specialNodeId = this.getSpecialNodeId()
}

if (special == "minusNode"){
depth = [...newDepth, specialNodeId, specialNodeId + "_1"]
}

if (forceSpecialId) {
specialNodeId = forceSpecialId
depth = [...depth, forceSpecialId, forceSpecialId + "_" + specialNodeGroupId]
}

let node = {
Expand All @@ -459,6 +466,7 @@ export default class Query extends Component {
specialNodeId: specialNodeId,
specialNodeGroupId: specialNodeGroupId,
specialPreviousIds: specialPreviousIds,
depth: depth,
label: this.getLabel(uri),
faldo: this.isFaldoEntity(uri),
selected: selected,
Expand Down Expand Up @@ -544,6 +552,11 @@ export default class Query extends Component {
let reLink = new RegExp(node.filterLink.toLowerCase(), 'g')

let specialNodeGroupId = incrementSpecialNodeGroupId ? incrementSpecialNodeGroupId : node.specialNodeGroupId
let depth = [...node.depth]

if(incrementSpecialNodeGroupId){
depth = [...node.depth, node.specialNodeGroupId, node.specialNodeGroupId + "_" + incrementSpecialNodeGroupId]
}

if (this.isOntoEndNode(node.id)){
return
Expand Down Expand Up @@ -575,7 +588,8 @@ export default class Query extends Component {
faldo: this.isFaldoEntity(relation.target),
selected: false,
suggested: true,
ontology: isOnto
ontology: isOnto,
depth: depth
})
// push suggested link
this.graphState.links.push({
Expand All @@ -594,6 +608,9 @@ export default class Query extends Component {
faldoFilters: this.defaultFaldoFilters
})
incrementSpecialNodeGroupId ? specialNodeGroupId += 1 : specialNodeGroupId = specialNodeGroupId
if (incrementSpecialNodeGroupId){
depth = [...node.depth, node.specialNodeGroupId, node.specialNodeGroupId + "_" + incrementSpecialNodeGroupId]
}
}
}
}
Expand Down Expand Up @@ -621,7 +638,8 @@ export default class Query extends Component {
label: label,
faldo: this.isFaldoEntity(relation.source),
selected: false,
suggested: true
suggested: true,
depth: depth
})
// push suggested link
this.graphState.links.push({
Expand All @@ -639,6 +657,9 @@ export default class Query extends Component {
faldoFilters: this.defaultFaldoFilters
})
incrementSpecialNodeGroupId ? specialNodeGroupId += 1 : specialNodeGroupId = specialNodeGroupId
if (incrementSpecialNodeGroupId){
depth = [...node.depth, node.specialNodeGroupId, node.specialNodeGroupId + "_" + incrementSpecialNodeGroupId]
}
}
}
}
Expand All @@ -665,6 +686,7 @@ export default class Query extends Component {
faldo: entity.faldo,
selected: false,
suggested: true,
depth: depth
})
// push suggested link
this.graphState.links.push({
Expand All @@ -683,6 +705,9 @@ export default class Query extends Component {
faldoFilters: this.defaultFaldoFilters
})
incrementSpecialNodeGroupId ? specialNodeGroupId += 1 : specialNodeGroupId = specialNodeGroupId
if (incrementSpecialNodeGroupId){
depth = [...node.depth, node.specialNodeGroupId, node.specialNodeGroupId + "_" + incrementSpecialNodeGroupId]
}
}
})
}
Expand Down Expand Up @@ -971,11 +996,18 @@ export default class Query extends Component {
// Get previous special node ids
let specialPreviousIds = [sourceNode.specialNodeId, sourceNode.specialNodeGroupId]

let depth
if (this.currentSelected.type == "unionNode"){
depth = [...sourceNode.depth, sourceNode.specialNodeId + "_" + this.getLargestSpecialNodeGroupId(sourceNode) + 1]
} else {
depth = [...sourceNode.depth]
}

// insert a special node and select it
let specialNode = this.insertNode(sourceNode.uri, true, false, data.convertTo, null, null, specialPreviousIds)
let specialNode = this.insertNode(sourceNode.uri, true, false, data.convertTo, null, null, specialPreviousIds, depth)

// insert target node with specialNodeGroupId = 1
let targetNode = this.insertNode(data.node.uri, false, false, null, specialNode.specialNodeId, 1, specialPreviousIds)
let targetNode = this.insertNode(data.node.uri, false, false, null, specialNode.specialNodeId, 1, specialPreviousIds, depth)

// insert link between source and special node
this.insertSpecialLink(sourceNode, specialNode, data.convertTo)
Expand All @@ -989,7 +1021,11 @@ export default class Query extends Component {
this.graphState.links.push(relation)

//insert suggestion with first specialNodeGroupId = 2 (will be incremented for each suggestion)
this.insertSuggestion(specialNode, 2)
if (this.currentSelected.type == "unionNode"){
this.insertSuggestion(specialNode, 2)
} else {
this.insertSuggestion(specialNode)
}

// Manage selection
this.manageCurrentPreviousSelected(specialNode)
Expand Down Expand Up @@ -1718,7 +1754,7 @@ export default class Query extends Component {
if (this.currentSelected) {
if (this.currentSelected.type != "link" && this.currentSelected.type != "posLink" && this.currentSelected.type != "ontoLink") {
if (this.currentSelected.type == "unionNode") {
this.insertSuggestion(this.currentSelected, this.getLargestSpecialNodeGroupId(this.currentSelected) + 1, true)
this.insertSuggestion(this.currentSelected, this.getLargestSpecialNodeGroupId(this.currentSelected) + 1)
} else {
this.insertSuggestion(this.currentSelected)
}
Expand Down

0 comments on commit f48855a

Please sign in to comment.