Skip to content

Commit

Permalink
Merge 7a0677e into 0fe36d1
Browse files Browse the repository at this point in the history
  • Loading branch information
mboudet committed Aug 2, 2023
2 parents 0fe36d1 + 7a0677e commit 1ddd9f5
Show file tree
Hide file tree
Showing 14 changed files with 366 additions and 148 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
25 changes: 20 additions & 5 deletions askomics/libaskomics/BedFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ def set_rdf_abstraction_domain_knowledge(self):
# Domain Knowledge
if "values" in attribute.keys():
for value in attribute["values"]:
self.graph_abstraction_dk.add((self.namespace_data[self.format_uri(value)], rdflib.RDF.type, self.namespace_data[self.format_uri("{}CategoryValue".format(attribute["label"]))]))
self.graph_abstraction_dk.add((self.namespace_data[self.format_uri(value)], rdflib.RDFS.label, rdflib.Literal(value)))
self.graph_abstraction_dk.add((self.namespace_data[self.format_uri("{}Category".format(attribute["label"]))], self.namespace_internal[self.format_uri("category")], self.namespace_data[self.format_uri(value)]))

o = self.namespace_data[self.format_uri(value)]
if attribute["label"] == rdflib.Literal("strand"):
self.graph_abstraction_dk.add((self.namespace_data[self.format_uri(value)], rdflib.RDF.type, self.get_faldo_strand(value)))
o = self.get_faldo_strand(value)
self.graph_abstraction_dk.add((o, rdflib.RDF.type, self.namespace_data[self.format_uri("{}CategoryValue".format(attribute["label"]))]))
self.graph_abstraction_dk.add((o, rdflib.RDFS.label, rdflib.Literal(value)))
self.graph_abstraction_dk.add((self.namespace_data[self.format_uri("{}Category".format(attribute["label"]))], self.namespace_internal[self.format_uri("category")], o))

# Faldo:
if self.faldo_entity:
Expand Down Expand Up @@ -306,4 +306,19 @@ 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))
if faldo_strand:
self.graph_chunk.add((entity, self.namespace_internal["includeInStrand"], faldo_strand))
strand_ref = self.get_reference_strand_uri(feature.chrom, faldo_strand, slice_block)
for sref in strand_ref:
self.graph_chunk.add((entity, self.namespace_internal["includeInReferenceStrand"], sref))

yield
18 changes: 14 additions & 4 deletions askomics/libaskomics/CsvFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,11 @@ def set_rdf_domain_knowledge(self):
p = self.namespace_internal["category"]
for value in self.category_values[self.header[index]]:
o = self.rdfize(value)
if self.columns_type[index] == "strand":
o = self.get_faldo_strand(value)
self.graph_abstraction_dk.add((s, p, o))
self.graph_abstraction_dk.add((o, rdflib.RDF.type, self.namespace_data["{}CategoryValue".format(self.format_uri(self.header[index]))]))
self.graph_abstraction_dk.add((o, rdflib.RDFS.label, rdflib.Literal(value)))
if self.columns_type[index] == "strand":
self.graph_abstraction_dk.add((o, rdflib.RDF.type, self.get_faldo_strand(value)))

def set_rdf_abstraction(self):
"""Set the abstraction"""
Expand Down Expand Up @@ -617,8 +617,9 @@ def generate_rdf_content(self):
# Category
elif current_type in ('category', 'reference', 'strand'):
potential_relation = self.rdfize(current_header)
if not cell:
cell = "unknown/both"
if current_type == "strand":
# Override csv value, use "proper" values
cell = self.get_faldo_strand_label(cell)
if current_header not in self.category_values.keys():
# Add the category in dict, and the first value in a set
self.category_values[current_header] = {cell, }
Expand Down Expand Up @@ -708,5 +709,14 @@ def generate_rdf_content(self):
if reference:
block_reference = self.rdfize(self.format_uri("{}_{}".format(reference, slice_block)))
self.graph_chunk.add((entity, self.namespace_internal["includeInReference"], block_reference))
if faldo_strand:
strand_ref = self.get_reference_strand_uri(reference, faldo_strand, slice_block)
for sref in strand_ref:
self.graph_chunk.add((entity, self.namespace_internal["includeInReferenceStrand"], sref))
if faldo_strand:
self.graph_chunk.add((entity, self.namespace_internal["includeInStrand"], faldo_strand))
if faldo_strand == self.faldo.BothStrandPosition:
self.graph_chunk.add((entity, self.namespace_internal["includeInStrand"], self.faldo.ForwardStrandPosition))
self.graph_chunk.add((entity, self.namespace_internal["includeInStrand"], self.faldo.ReverseStrandPosition))

yield
12 changes: 12 additions & 0 deletions askomics/libaskomics/Database.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ def create_results_table(self):
template boolean,
has_form_attr boolean,
form boolean,
version text,
FOREIGN KEY(user_id) REFERENCES users(user_id)
)
'''
Expand Down Expand Up @@ -355,6 +356,17 @@ def update_results_table(self):
except Exception:
pass

query = '''
ALTER TABLE results
ADD version text NULL
DEFAULT(NULL)
'''

try:
self.execute_sql_query(query)
except Exception:
pass

def create_endpoints_table(self):
"""Create the endpoints table"""
query = '''
Expand Down
33 changes: 33 additions & 0 deletions askomics/libaskomics/File.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,39 @@ def get_faldo_strand(self, raw_strand):

return self.faldo.BothStrandPosition

def get_faldo_strand_label(self, raw_strand):
"""Get faldo strand label
Parameters
----------
raw_strand : string
raw value of strand
Returns
-------
label
"+", "-", or "."
"""

if raw_strand in ("+", "plus", "1", "positive", "forward"):
return "+"

if raw_strand in ("-", "minus", "moins", "-1", "reverse", "negative"):
return "-"

return "."

def get_reference_strand_uri(self, reference, strand, block):
faldo_dict = {
self.faldo.ForwardStrandPosition: "ForwardStrand",
self.faldo.ReverseStrandPosition: "ReverseStrand",
self.faldo.BothStrandPosition: "BothStrand"
}
if strand == self.faldo.BothStrandPosition:
return [self.rdfize(self.format_uri("{}_s{}_{}".format(reference, dstrand, block))) for dstrand in faldo_dict.values()]

return [self.rdfize(self.format_uri("{}_s{}_{}".format(reference, faldo_dict[strand], block)))]

def get_rdf_type(self, value):
"""get xsd type of a value
Expand Down
34 changes: 19 additions & 15 deletions askomics/libaskomics/GffFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,12 @@ def set_rdf_abstraction_domain_knowledge(self):
# Domain Knowledge
if "values" in attribute.keys():
for value in attribute["values"]:
self.graph_abstraction_dk.add((self.namespace_data[self.format_uri(value)], rdflib.RDF.type, self.namespace_data[self.format_uri("{}CategoryValue".format(attribute["label"]))]))
self.graph_abstraction_dk.add((self.namespace_data[self.format_uri(value)], rdflib.RDFS.label, rdflib.Literal(value)))
self.graph_abstraction_dk.add((self.namespace_data[self.format_uri("{}Category".format(attribute["label"]))], self.namespace_internal[self.format_uri("category")], self.namespace_data[self.format_uri(value)]))

o = self.namespace_data[self.format_uri(value)]
if attribute["label"] == rdflib.Literal("strand"):
self.graph_abstraction_dk.add((self.namespace_data[self.format_uri(value)], rdflib.RDF.type, self.get_faldo_strand(value)))

o = self.get_faldo_strand(value)
self.graph_abstraction_dk.add((o, rdflib.RDF.type, self.namespace_data[self.format_uri("{}CategoryValue".format(attribute["label"]))]))
self.graph_abstraction_dk.add((o, rdflib.RDFS.label, rdflib.Literal(value)))
self.graph_abstraction_dk.add((self.namespace_data[self.format_uri("{}Category".format(attribute["label"]))], self.namespace_internal[self.format_uri("category")], o))
# Faldo:
if self.faldo_entity:
for key, values in self.faldo_abstraction.items():
Expand Down Expand Up @@ -412,15 +411,20 @@ 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))
if faldo_strand:
self.graph_chunk.add((entity, self.namespace_internal["includeInStrand"], faldo_strand))
strand_ref = self.get_reference_strand_uri(rec.id, faldo_strand, slice_block)
for sref in strand_ref:
self.graph_chunk.add((entity, self.namespace_internal["includeInReferenceStrand"], sref))

yield

Expand Down
6 changes: 5 additions & 1 deletion askomics/libaskomics/Result.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from askomics.libaskomics.Params import Params
from askomics.libaskomics.Utils import Utils

from pkg_resources import get_distribution


class Result(Params):
"""Result represent a query result file
Expand Down Expand Up @@ -381,6 +383,7 @@ def save_in_db(self, start=None):
?,
?,
?,
?,
?
)
'''
Expand All @@ -396,7 +399,8 @@ def save_in_db(self, start=None):
json.dumps({"graphs": self.graphs, "endpoints": self.endpoints}),
False,
self.session["user"]["admin"] and any([attrib.get("form") for attrib in self.graph_state["attr"]]) if (self.graph_state and self.graph_state.get("attr")) else False,
False
False,
get_distribution('askomics').version
), get_id=True)

return self.id
Expand Down

0 comments on commit 1ddd9f5

Please sign in to comment.