Skip to content

Commit

Permalink
Merge branch 'main' into bento007/processing_logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Bento007 authored Jan 11, 2023
2 parents 2eeaa5c + 632838f commit 1fcbdad
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 18 deletions.
4 changes: 3 additions & 1 deletion backend/portal/api/curation/curation-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,9 @@ components:
description: Collection metadata
properties:
collection_url:
description: The CELLxGENE Discover URL for the Collection.
description: |
The CELLxGENE Discover URL for the Collection. This points to the canonical link unless it's a revision,
in which case it points to the unpublished revision version.
type: string
contact_email:
$ref: "#/components/schemas/contact_email"
Expand Down
21 changes: 17 additions & 4 deletions backend/portal/api/curation/v1/curation/collections/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def reshape_for_curation_api(
if is_published:
# Published
collection_id = collection_version.collection_id
collection_url = f"{get_collections_base_url()}/collections/{collection_id.id}"
revision_of = None
if not user_info.is_user_owner_or_allowed(collection_version.owner):
_revising_in = None
Expand All @@ -78,9 +79,21 @@ def reshape_for_curation_api(
)
revising_in = _revising_in.version_id.id if _revising_in else None
else:
# Unpublished
collection_id = collection_version.version_id
revision_of = collection_version.collection_id.id
# Unpublished - need to determine if it's a revision or first time collection
# For that, we look at whether the canonical collection is published
is_revision = collection_version.canonical_collection.originally_published_at is not None
if is_revision:
# If it's a revision, both collection_id and collection_url need to point to the version_id
collection_id = collection_version.version_id
collection_url = f"{get_collections_base_url()}/collections/{collection_id.id}"
revision_of = collection_version.collection_id.id
else:
# If it's an unpublished, unrevised collection, then collection_url will point to the permalink
# (aka the link to the canonical_id) and the collection_id will point to version_id.
# Also, revision_of should be None
collection_id = collection_version.version_id
collection_url = f"{get_collections_base_url()}/collections/{collection_version.collection_id}"
revision_of = None
revising_in = None

# get collection dataset attributes
Expand All @@ -94,7 +107,7 @@ def reshape_for_curation_api(
else:
revised_at = None
response = dict(
collection_url=f"{get_collections_base_url()}/collections/{collection_id.id}",
collection_url=collection_url,
contact_email=collection_version.metadata.contact_email,
contact_name=collection_version.metadata.contact_name,
created_at=collection_version.created_at,
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/common/analytics/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ export enum EVENTS {
WMG_CLICKED = "WMG_CLICKED",
WMG_DOWNLOAD_CLICKED = "WMG_DOWNLOAD_CLICKED",
WMG_DOWNLOAD_COMPLETE = "WMG_DOWNLOAD_COMPLETE",
WMG_FMG_INFO_CLICKED = "WMG_FMG_INFO_CLICKED",
WMG_FMG_COPY_GENES_CLICKED = "WMG_FMG_COPY_GENES_CLICKED",
WMG_FMG_ADD_GENES_CLICKED = "WMG_FMG_ADD_GENES_CLICKED",
WMG_FMG_QUESTION_BUTTON_HOVER = "WMG_FMG_QUESTION_BUTTON_HOVER",
WMG_FMG_DOCUMENTATION_CLICKED = "WMG_FMG_DOCUMENTATION_CLICKED",
BROWSE_COLLECTIONS_CLICKED = "BROWSE_COLLECTIONS_CLICKED",
DATASET_EXPLORE_CLICKED = "DATASET_EXPLORE_CLICKED",
BROWSE_TUTORIALS_CLICKED = "BROWSE_TUTORIALS_CLICKED",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/common/queries/wheresMyGene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ export async function fetchMarkerGenes({
cellTypeID,
organismID,
tissueID,
test = "binomtest",
test = "ttest",
}: FetchMarkerGeneParams): Promise<MarkerGeneResponse> {
const url = API_URL + API.WMG_MARKER_GENES;
const body = generateMarkerGeneBody(cellTypeID, tissueID, organismID, test);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import {
TableRow,
Tooltip,
} from "czifui";
import React, { useCallback, useContext } from "react";
import React, { useCallback, useContext, useState } from "react";
import { track } from "src/common/analytics";
import { EVENTS } from "src/common/analytics/events";
import { ROUTES } from "src/common/constants/routes";
import { useMarkerGenes } from "src/common/queries/wheresMyGene";
import { BetaChip } from "src/components/Header/style";
Expand All @@ -30,15 +32,16 @@ export interface CellInfoBarProps {
cellInfoCellType: Exclude<State["cellInfoCellType"], null>;
tissueName: string;
}

function CellInfoSideBar({
cellInfoCellType,
tissueName,
}: CellInfoBarProps): JSX.Element | null {
const urlParams = new URLSearchParams(window.location.search);
let testType: "ttest" | undefined = undefined;
let testType: "binomtest" | undefined = undefined;

if (urlParams.get("test") === "ttest") {
testType = "ttest";
if (urlParams.get("test") === "binomtest") {
testType = "binomtest";
}
const { isLoading, data } = useMarkerGenes({
cellTypeID: cellInfoCellType.cellType.id,
Expand All @@ -53,14 +56,24 @@ function CellInfoSideBar({
if (!data) return;
const genes = Object.keys(data.marker_genes);
navigator.clipboard.writeText(genes.join(", "));
track(EVENTS.WMG_FMG_COPY_GENES_CLICKED);
}, [data]);

const handleDisplayGenes = useCallback(() => {
if (!data || !dispatch) return;
const genes = Object.keys(data.marker_genes);
dispatch(addSelectedGenes(genes));
track(EVENTS.WMG_FMG_ADD_GENES_CLICKED);
}, [data, dispatch]);

const [hoverStartTime, setHoverStartTime] = useState(0);

const handleHoverEnd = useCallback(() => {
if (Date.now() - hoverStartTime > 2 * 1000) {
track(EVENTS.WMG_FMG_QUESTION_BUTTON_HOVER);
}
}, [hoverStartTime]);

if (isLoading || !data) return null;

if (!cellInfoCellType) return null;
Expand All @@ -78,13 +91,20 @@ function CellInfoSideBar({
arrow={true}
title={
<StyledTooltip>
<div>Marker genes are highly and uniquely expressed in the cell type relative to all other cell types.</div>
<br/>
<div>
<a
href={ROUTES.FMG_DOCS}
rel="noopener"
target="_blank"
Marker genes are highly and uniquely expressed in the cell
type relative to all other cell types.
</div>
<br />
<div>
<a
href={ROUTES.FMG_DOCS}
rel="noopener"
target="_blank"
onClick={() => {
handleHoverEnd();
track(EVENTS.WMG_FMG_DOCUMENTATION_CLICKED);
}}
>
Click to read more about the identification method.
</a>
Expand All @@ -97,6 +117,8 @@ function CellInfoSideBar({
sdsType="secondary"
isAllCaps={false}
style={{ fontWeight: "500" }}
onMouseEnter={() => setHoverStartTime(Date.now())}
onMouseLeave={handleHoverEnd}
>
<StyledIconImage src={questionMarkIcon} />
</TooltipButton>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import {
InfoButtonWrapper,
} from "./style";
import { SELECTED_STYLE } from "../../style";
import { track } from "src/common/analytics";
import { EVENTS } from "src/common/analytics/events";

const MAX_DEPTH = 2;

Expand Down Expand Up @@ -192,6 +194,9 @@ const CellTypeButton = ({
if (isMarkerGenes) {
const cellType = deserializeCellTypeMetadata(metadata);
generateMarkerGenes(cellType, tissueID);
track(EVENTS.WMG_FMG_INFO_CLICKED, {
combination: `${cellType.name}, ${tissue}}`,
});
}
}}
>
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/backend/layers/api/test_curation_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,11 +349,11 @@ def test__get_collections_with_auth__OK_5(self):

def test__get_collections_with_auth__OK_6(self):
"revision_of contains None if the collection is unpublished"
unpublished_collection_id = self.generate_unpublished_collection()
self.generate_unpublished_collection()
resp = self._test_response(visibility="PRIVATE", auth=True)
self.assertEqual(1, len(resp))
resp_collection = resp[0]
self.assertEqual(unpublished_collection_id.collection_id.id, resp_collection["revision_of"])
self.assertIsNone(resp_collection["revision_of"])

def test__get_collections_no_auth_visibility_private__403(self):
self._test_response(visibility="PRIVATE", status_code=403)
Expand Down

0 comments on commit 1fcbdad

Please sign in to comment.