Skip to content

Commit

Permalink
Merge pull request #13 from refgenie/dev
Browse files Browse the repository at this point in the history
Release v0.6.0
  • Loading branch information
nsheff authored Aug 9, 2024
2 parents 506f523 + b132525 commit da9b527
Show file tree
Hide file tree
Showing 11 changed files with 138 additions and 79 deletions.
27 changes: 23 additions & 4 deletions frontend/src/components/ObjectLists.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { Link } from "react-router-dom"
import { useLoaderData } from "react-router-dom"


// Basic list of Sequence Collections
const CollectionList = ({collections}) => {
const seqColList = collections || useLoaderData()[0]
console.log("CollectionList", CollectionList)
console.log("seqColList", seqColList)

return (<>
<div>
<ul>
{seqColList.items.map((seqCol) => (
{seqColList.results.map((seqCol) => (
<li key={seqCol}>
Collection: <Link to={`/collection/${seqCol}`} className="font-monospace">{seqCol}</Link>
</li>
Expand All @@ -18,6 +20,23 @@ const CollectionList = ({collections}) => {
)
}

const AttributeList = ({attributes}) => {
const attrList = attributes || useLoaderData()[0]
console.log("attrList", attrList)

return (<>
<div>
<ul>
{attrList.results.map((attr) => (
<li key={attr}>
Attribute: <Link to={`/attribute/sorted_name_length_pairs/${attr}`}>{attr}</Link>
</li>
))}
</ul>
</div></>
)
}


// Basic list of Pangenomes
const PangenomeList = ({pangenomes}) => {
Expand All @@ -27,7 +46,7 @@ const PangenomeList = ({pangenomes}) => {
return (<>
<div>
<ul>
{pangenomeList.items.map((pangenome) => (
{pangenomeList.results.map((pangenome) => (
<li key={pangenome}>
<Link to={`/pangenome/${pangenome}`}>{pangenome}</Link>
</li>
Expand All @@ -39,5 +58,5 @@ const PangenomeList = ({pangenomes}) => {



export { CollectionList, PangenomeList }
export { AttributeList, CollectionList, PangenomeList }

20 changes: 11 additions & 9 deletions frontend/src/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ const fetchPangenomeLevels = async(digest, level="2", collated=true) => {
}

const fetchSeqColList = async() => {
const url = `${API_BASE}/list/collections?limit=10&offset=10`
const url2 = `${API_BASE}/list/pangenomes?limit=5`
const url = `${API_BASE}/list/collections?page_size=10&page=1`
const url2 = `${API_BASE}/list/pangenomes?page_size=5`
const url3 = `${API_BASE}/list/attributes/sorted_name_length_pairs?page_size=5`
let resps = [
fetch(url).then((response) => response.json()),
fetch(url2).then((response) => response.json())
fetch(url2).then((response) => response.json()),
fetch(url3).then((response) => response.json())
]
return Promise.all(resps)
}
Expand All @@ -79,8 +81,8 @@ const fecthComparison = async(digest1, digest2) => {
}

const fetchAttribute = async(attribute, digest) => {
const url = `${API_BASE}/attribute/${attribute}/${digest}/list`
const url2 = `${API_BASE}/attribute/${attribute}/${digest}`
const url = `${API_BASE}/list/collections/${attribute}/${digest}`
const url2 = `${API_BASE}/attribute/collection/${attribute}/${digest}`
let resps = [
fetch(url).then((response) => response.json()),
fetch(url2).then((response) => response.json())
Expand All @@ -93,9 +95,9 @@ const fetchAttribute = async(attribute, digest) => {
const Level1Collection = ({collection}) => {
return (
<div>
Names: <Link to={`/attribute/names/${collection.names}`}>{collection.names}</Link><br/>
Lengths: <Link to={`/attribute/lengths/${collection.lengths}`}>{collection.lengths}</Link><br/>
Sequences: <Link to={`/attribute/sequences/${collection.sequences}`}>{collection.sequences}</Link><br/>
Names: <Link to={`/attribute/collection/names/${collection.names}`}>{collection.names}</Link><br/>
Lengths: <Link to={`/attribute/collection/lengths/${collection.lengths}`}>{collection.lengths}</Link><br/>
Sequences: <Link to={`/attribute/collection/sequences/${collection.sequences}`}>{collection.sequences}</Link><br/>
</div>
)
}
Expand Down Expand Up @@ -185,7 +187,7 @@ const CollectionTable = ({collections}) => {
</tr>
</thead>
<tbody>
{seqColList["items"].map((collection) => (
{seqColList["results"].map((collection) => (
<tr key={collection}>
<td><LinkedCollectionDigest digest={collection.digest} clipboard={false}/></td>
<td className="tiny mx-2"><LinkedAttributeDigest attribute="names" digest={collection.names_digest} clipboard={false}/></td>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/AttributeView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { CollectionList } from '../components/ObjectLists.jsx'
const AttributeView = () => {
const content = useLoaderData()
const { attribute, digest } = useParams()
const api_url = `${API_BASE}/attribute/${attribute}/${digest}`
const api_url = `${API_BASE}/attribute/collection/${attribute}/${digest}`
const api_url_list = `${API_BASE}/list/collections/${attribute}/${digest}`
let results = content[0]
let attribute_value = content[1]
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/pages/DemoPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function DemoPage() {
<th>digest</th>
</tr>
</thead>
<tbody>
{Object.keys(demo_seqcol_digests).map((property) => {
return (
<tr key={demo_seqcol_digests[property]}>
Expand All @@ -29,6 +30,7 @@ function DemoPage() {
</tr>
)
})}
</tbody>
</table>
<CompareTable seqColList={Object.values(demo_seqcol_digests)}/>
</div>
Expand Down
13 changes: 12 additions & 1 deletion frontend/src/pages/HomePage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ import { PangenomeList } from '../components/ObjectLists.jsx'
import { CollectionList } from '../components/ObjectLists.jsx'
import { Link } from "react-router-dom";
import { useLoaderData } from "react-router-dom";
import { AttributeList } from '../components/ObjectLists';


const HomePage = () => {
const loaderData = useLoaderData()
console.log("HomePage loadData ", loaderData)
const collections = loaderData[0]
const pangenomes = loaderData[1]
const sorted_name_length_pairs = loaderData[2]

const PangenomeExamplesList = () => {
if (pangenomes.items[0]) {
if (pangenomes.results[0]) {
return <>
<h3>Example Pangenomes:</h3>
<PangenomeList pangenomes={pangenomes}/>
Expand Down Expand Up @@ -54,6 +57,14 @@ const HomePage = () => {
</ul>
<PangenomeExamplesList/>

<h5 className="mt-4">4. List of sorted_name_length_pairs on this server:</h5>
<p className="text-muted fs-6">
The <span className="font-monospace text-success">/list/attributes</span> endpoint lets you retrieve
a list of all the values of a particular attribute hosted by this server.
</p>
<AttributeList attributes={sorted_name_length_pairs}/>


</div>
)
}
Expand Down
2 changes: 1 addition & 1 deletion refget/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.5.0"
__version__ = "0.6.0"
8 changes: 4 additions & 4 deletions refget/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def list_by_offset(self, limit=50, offset=0):
list_res = session.exec(list_stmt)
count = cnt_res.one()
seqcols = list_res.all()
return {"count": count, "limit": limit, "offset": offset, "items": seqcols}
return {"pagination": { "page": offset*limit, "page_size": limit, "total": count}, "results": seqcols}

def list(self, page_size=100, cursor=None):
with Session(self.engine) as session:
Expand Down Expand Up @@ -223,7 +223,7 @@ def list_by_offset(self, limit=50, offset=0):
list_res = session.exec(list_stmt)
count = cnt_res.one()
seqcols = list_res.all()
return {"count": count, "limit": limit, "offset": offset, "items": seqcols}
return {"pagination": { "page": offset*limit, "page_size": limit, "total": count}, "results": seqcols}


class AttributeAgent(object):
Expand All @@ -250,7 +250,7 @@ def list(self, attribute_type, offset=0, limit=50):
list_res = session.exec(list_stmt)
count = cnt_res.one()
seqcols = list_res.all()
return {"count": count, "limit": limit, "offset": offset, "items": seqcols}
return {"pagination": { "page": offset*limit, "page_size": limit, "total": count}, "results": seqcols}

def search(self, attribute_type, digest, offset=0, limit=50):
Attribute = ATTR_TYPE_MAP[attribute_type]
Expand All @@ -268,7 +268,7 @@ def search(self, attribute_type, digest, offset=0, limit=50):
list_res = session.exec(list_stmt)
count = cnt_res.one()
seqcols = list_res.all()
return {"count": count, "limit": limit, "offset": offset, "items": seqcols}
return {"pagination": { "page": offset*limit, "page_size": limit, "total": count}, "results": seqcols}


class RefgetDBAgent(object):
Expand Down
9 changes: 9 additions & 0 deletions refget/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@
examples="a6748aa0f6a1e165f871dbed5e54ba62",
)

example_attribute_digest = Path(
...,
description="Attribute digest",
pattern=r"^[-\w]+$",
max_length=64,
min_length=16,
examples="cGRMZIb3AVgkcAfNv39RN7hnT5Chk7RXCopy",
)

example_collection_digest = Path(
...,
description="Sequence collection digest",
Expand Down
114 changes: 64 additions & 50 deletions refget/seqcol_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ async def get_schenge(request: Request):
return request.app.state.schenge


# dbagent is a RefgetDBAgent

async def get_dbagent(request: Request):
return request.app.state.dbagent

Expand All @@ -49,17 +51,6 @@ async def refget(request: Request, sequence_digest: str = example_sequence):
return Response(content=schenge.refget(sequence_digest))


@seqcol_router.get(
"/attribute/{attribute}/{attribute_digest}",
summary="Retrieve a single attribute of a sequence collection",
tags=["Retrieving data"],
)
async def attribute(
dbagent=Depends(get_dbagent), attribute: str = "names", attribute_digest: str = example_digest
):
return JSONResponse(dbagent.attribute.get(attribute, attribute_digest))


@seqcol_router.get(
"/collection/{collection_digest}",
summary="Retrieve a sequence collection",
Expand Down Expand Up @@ -92,6 +83,18 @@ async def collection(
detail=str(e),
)

@seqcol_router.get(
"/attribute/collection/{attribute}/{attribute_digest}",
summary="Retrieve a single attribute of a sequence collection",
tags=["Retrieving data"],
)
async def attribute(
dbagent=Depends(get_dbagent), attribute: str = "names", attribute_digest: str = example_digest
):
return JSONResponse(dbagent.attribute.get(attribute, attribute_digest))




@seqcol_router.get(
"/pangenome/{pangenome_digest}",
Expand Down Expand Up @@ -133,28 +136,6 @@ async def pangenome(
)


@seqcol_router.get(
"/attribute/{attribute}/{attribute_digest}/list",
summary="List sequence collections that contain a given attribute",
tags=["Discovering data"],
)
@seqcol_router.get(
"/list/collections/{attribute}/{attribute_digest}",
summary="List sequence collections that contain a given attribute",
tags=["Discovering data"],
)
async def attribute_search(
dbagent=Depends(get_dbagent),
attribute: str = "names",
attribute_digest: str = example_digest,
limit: int = 100,
offset: int = 0,
):
# attr = dbagent.attribute.get(attribute, digest)
res = dbagent.attribute.search(attribute, attribute_digest, limit=limit, offset=offset)
res["items"] = [x.digest for x in res["items"]]
return JSONResponse(res)


@seqcol_router.get(
"/collection2/{collection_digest}",
Expand Down Expand Up @@ -268,34 +249,64 @@ async def compare_1_digest(
return JSONResponse(schenge.compat_all(A, B))



@seqcol_router.get(
"/list",
summary="List sequence collections on the server, paged by offset",
"/list/collections",
summary="List sequence collections on the server",
tags=["Discovering data"],
)
async def list_collections_by_offset(
dbagent=Depends(get_dbagent), page_size: int = 100, page: int = 0
):
res = dbagent.seqcol.list_by_offset(limit=page_size, offset=page*page_size)
res["results"] = [x.digest for x in res["results"]]
return JSONResponse(res)


# @seqcol_router.get(
# "/list-by-cursor",
# summary="List sequence collections on the server, paged by cursor",
# tags=["Discovering data"],
# )
# async def list_collections_by_token(
# dbagent=Depends(get_dbagent), page_size: int = 100, cursor: str = None
# ):
# res = dbagent.seqcol.list(page_size=page_size, cursor=cursor)
# res["results"] = [x.digest for x in res["results"]]
# return JSONResponse(res)





@seqcol_router.get(
"/list/collections",
summary="List sequence collections on the server, paged by offset",
"/list/collections/{attribute}/{attribute_digest}",
summary="Filtered list of sequence collections that contain a given attribute",
tags=["Discovering data"],
)
async def list_collections_by_offset(
dbagent=Depends(get_dbagent), limit: int = 100, offset: int = 0
async def attribute_search(
dbagent=Depends(get_dbagent),
attribute: str = "names",
attribute_digest: str = example_attribute_digest,
page_size: int = 100,
page: int = 0,
):
res = dbagent.seqcol.list_by_offset(limit=limit, offset=offset)
res["items"] = [x.digest for x in res["items"]]
# attr = dbagent.attribute.get(attribute, digest)
res = dbagent.attribute.search(attribute, attribute_digest, limit=page_size, offset=page*page_size)
res["results"] = [x.digest for x in res["results"]]
return JSONResponse(res)


@seqcol_router.get(
"/list-by-cursor",
summary="List sequence collections on the server, paged by cursor",
"/list/attributes/{attribute}",
summary="List attributes on the server",
tags=["Discovering data"],
)
async def list_collections_by_token(
dbagent=Depends(get_dbagent), page_size: int = 100, cursor: str = None
async def list_attributes(
dbagent=Depends(get_dbagent), attribute: str = "names", page_size: int = 100, page: int = 0
):
res = dbagent.seqcol.list(page_size=page_size, cursor=cursor)
res["items"] = [x.digest for x in res["items"]]
res = dbagent.attribute.list(attribute, limit=page_size, offset=page*page_size)
res["results"] = [x.digest for x in res["results"]]
return JSONResponse(res)


Expand All @@ -305,8 +316,11 @@ async def list_collections_by_token(
tags=["Discovering data"],
)
async def list_cpangenomes_by_offset(
dbagent=Depends(get_dbagent), limit: int = 100, offset: int = 0
dbagent=Depends(get_dbagent), page_size: int = 100, page: int = 0
):
res = dbagent.pangenome.list_by_offset(limit=limit, offset=offset)
res["items"] = [x.digest for x in res["items"]]
res = dbagent.pangenome.list_by_offset(limit=page_size, offset=page*page_size)
res["results"] = [x.digest for x in res["results"]]
return JSONResponse(res)



Loading

0 comments on commit da9b527

Please sign in to comment.