Skip to content

Commit

Permalink
(#114) add an icon for searching monomorphisms or isomorphisms
Browse files Browse the repository at this point in the history
  • Loading branch information
jinhan committed Jan 31, 2023
1 parent 15efb56 commit 0419044
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 26 deletions.
32 changes: 19 additions & 13 deletions neuronal_motifs/client/src/components/MotifPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ function MotifPanel() {
context.setLoadingMessage("Searching for Motifs");
context.setErrorMessage(null);
try {
const motifs = await queryMotifs(context.motifQuery, number);
const motifs = await queryMotifs(
context.motifQuery,
number,
context.allowBidirectional
);
context.setLoadingMessage(null);
setSearchedMotifs(motifs);
setSearched(true);
Expand Down Expand Up @@ -163,18 +167,20 @@ function MotifPanel() {
<div className="form">
<div className="handle">
<DragHandleIcon />
<ThemeProvider theme={Color.theme}>
<Tooltip title={parseButtonTooltip()} arrow placement="right">
<span>
<InfoButton
text={getMotifCountAsString()}
disabled={!enableAbsMotifCountInfo}
color={countButtonColor}
icon={<SearchIcon />}
/>
</span>
</Tooltip>
</ThemeProvider>
{context.allowBidirectional && (
<ThemeProvider theme={Color.theme}>
<Tooltip title={parseButtonTooltip()} arrow placement="right">
<span>
<InfoButton
text={getMotifCountAsString()}
disabled={!enableAbsMotifCountInfo}
color={countButtonColor}
icon={<SearchIcon />}
/>
</span>
</Tooltip>
</ThemeProvider>
)}
{context.showWarning ? (
<InfoButton color="error" icon={<PriorityHighIcon />} />
) : null}
Expand Down
30 changes: 28 additions & 2 deletions neuronal_motifs/client/src/components/SketchPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { useContext, useEffect, useState } from "react";
import "./SketchPanel.css";
import QueryBuilder from "./QueryBuilder";
import CircleTwoToneIcon from "@mui/icons-material/CircleTwoTone";
import ArrowRightAltIcon from "@mui/icons-material/ArrowRightAlt";
import EditIcon from "@mui/icons-material/Edit";
import DeleteIcon from "@mui/icons-material/Delete";
import InfoIcon from "@mui/icons-material/Info";
Expand All @@ -15,6 +14,9 @@ import {
faFileExport,
faFileImport,
faHand,
faArrowRight,
faArrowsUpDown,
faArrowUp,
} from "@fortawesome/free-solid-svg-icons";
import { Utils as QbUtils } from "react-awesome-query-builder";
import axios from "axios";
Expand Down Expand Up @@ -223,6 +225,8 @@ function SketchPanel() {
}
};

const allowBidirectional = () => {};

const renameEdge = (fromNode, toNode, nodeIndices, edge) => {
let tree = "tree" in edge ? edge.tree : null;
let edgeObj = {
Expand Down Expand Up @@ -1219,7 +1223,7 @@ function SketchPanel() {
setMouseState("edge");
}}
>
<ArrowRightAltIcon fontSize="small" />
<FontAwesomeIcon size={"sm"} icon={faArrowRight} />
</IconButton>
</Tooltip>
<Tooltip title="Edit Properties" placement="right">
Expand Down Expand Up @@ -1363,6 +1367,28 @@ function SketchPanel() {
<FontAwesomeIcon size={"sm"} icon={faFileExport} />
</IconButton>
</Tooltip>
<Tooltip
title={
context.allowBidirectional
? "Change to search for Isomorphisms"
: "Change to search for Monomorphisms"
}
placement="left"
>
<IconButton
value="edit"
color="default"
onClick={() =>
context.setAllowBidirectional(!context.allowBidirectional)
}
>
{context.allowBidirectional ? (
<FontAwesomeIcon size={"sm"} icon={faArrowsUpDown} />
) : (
<FontAwesomeIcon size={"sm"} icon={faArrowUp} />
)}
</IconButton>
</Tooltip>
</Grid>
</Grid>
</Grid>
Expand Down
3 changes: 3 additions & 0 deletions neuronal_motifs/client/src/contexts/GlobalContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export const ContextWrapper = (props) => {

// search constraints
const [constraintsToAddToSketch, setConstraintsToAddToSketch] = useState();
const [allowBidirectional, setAllowBidirectional] = useState(true);

const [displayedROIs, setDisplayedROIs] = useState([]);

Expand Down Expand Up @@ -125,6 +126,8 @@ export const ContextWrapper = (props) => {
setConstraintsToAddToSketch,
displayedROIs,
setDisplayedROIs,
allowBidirectional,
setAllowBidirectional,
}}
>
{props.children}
Expand Down
3 changes: 2 additions & 1 deletion neuronal_motifs/client/src/services/data.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios from "axios";
import { getAuthToken } from "../utils/authentication";

export async function queryMotifs(motif, number) {
export async function queryMotifs(motif, number, allowBidirectional) {
try {
const res = await axios.post(
`${process.env.REACT_APP_API_PROTOCOL}://${process.env.REACT_APP_API_URL}/search`,
Expand All @@ -10,6 +10,7 @@ export async function queryMotifs(motif, number) {
motif: motif,
lim: number,
token: JSON.stringify(getAuthToken()),
allowBidirectional: allowBidirectional,
}
);
return res.data;
Expand Down
3 changes: 2 additions & 1 deletion neuronal_motifs/server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ async def search_motif(req: Request):
motif = req['motif']
lim = req['lim']
token = req['token']
allowBidirectional = req['allowBidirectional']
try:
return motif_search.search_hemibrain_motif(motif, lim, token)
return motif_search.search_hemibrain_motif(motif, lim, token, allowBidirectional)
except HTTPError as e:
raise HTTPException(status_code=e.response.status_code, detail=json.loads(e.response.text))
except Exception as e:
Expand Down
4 changes: 2 additions & 2 deletions neuronal_motifs/server/services/motif_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
from utils.data_conversion import nodes_and_edges_to_motif_string


def search_hemibrain_motif(motif_specs, lim, token):
def search_hemibrain_motif(motif_specs, lim, token, allowBidirectional):
E = NeuPrintExecutor(host=get_data_server(), dataset=get_data_version(),
token=token)

motif_source = nodes_and_edges_to_motif_string(motif_specs)
motif_source = nodes_and_edges_to_motif_string(motif_specs, allowBidirectional)
motif = Motif(enforce_inequality=True).from_motif(motif_source)
results = E.find(motif=motif, limit=lim)
return results.to_dict('records')
15 changes: 8 additions & 7 deletions neuronal_motifs/server/utils/data_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def nodes_and_edges_to_networkx(motif):


# Converts Query Builder Mongo-esque parameters to dotmotif query format
def nodes_and_edges_to_motif_string(motif):
def nodes_and_edges_to_motif_string(motif, allowBidirectional):
print(motif)
edges = motif['edges']
nodes = motif['nodes']
Expand Down Expand Up @@ -111,12 +111,13 @@ def nodes_and_edges_to_motif_string(motif):

# Check opposite direction of edge
# https://github.com/aplbrain/dotmotif/wiki/Monomorphism-and-Isomorphism#considerations-for-motif-search
for label in edgeLabels:
start, arrow, end = label.split(' ')
oppositeLabel = ' '.join([end, arrow, start])
if oppositeLabel not in output:
output += ' '.join([end, '!>', start]) + ' \n'
print(output)
if allowBidirectional is not True:
for label in edgeLabels:
start, arrow, end = label.split(' ')
oppositeLabel = ' '.join([end, arrow, start])
if oppositeLabel not in output:
output += ' '.join([end, '!>', start]) + ' \n'
print(output)

# Now list every node property like A['prop'] == True
for node in nodes:
Expand Down

0 comments on commit 0419044

Please sign in to comment.