Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update civic API #4775

Merged
merged 10 commits into from
Feb 5, 2024
Merged

Update civic API #4775

merged 10 commits into from
Feb 5, 2024

Conversation

leexgh
Copy link
Member

@leexgh leexgh commented Nov 10, 2023

Fix: cBioPortal/cbioportal#9521
Civic stops supporting v1 API and switches to v2 graphql API. This PR changes civic rest API to graphql API, other things remain the same.
Now we only need to call one API to get civic gene information and all variants associated with the gene, not need to keep two calls for gene and variant separately.
image

@leexgh leexgh added the external api This PR is related to handling an external API label Nov 10, 2023
@leexgh leexgh requested a review from onursumer November 10, 2023 15:31
@inodb
Copy link
Member

inodb commented Nov 10, 2023

@leexgh Thanks for fixing this! Looks like it's not yet working for copy number data:

https://cbioportal.mskcc.org/patient?studyId=ucec_tcga_pub&caseId=TCGA-BK-A0CC

@onursumer
Copy link
Member

Looks like we are querying the civic API separately for each gene in the CNA and mutation tables on patient view. Maybe that's why the CNA table is failing?

src/shared/lib/CivicUtils.ts Outdated Show resolved Hide resolved
Comment on lines 34 to 35
hugoSymbols.forEach(hugoSymbol =>
promises.push(civicClient.getCivicGenesBatch(hugoSymbol))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a batch query anymore. We are making a separate API call for each hugo symbol. This may cause a rate limit issue.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that's the problem right now. I don't see a way to send "POST" queries that can accept a list of hugo gene symbols. As far as I can see it can only accept single gene or giving the "start civic id" and "end civic id", the response will then include all genes between this range, but we still need to send extra queries to get the civic id, so it's still not ideal.
For results view it only sends one gene, but for copy number alterations on patients view it sends too many requests. I already asked civic team to see if they have a better way to handle it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is solved. Civic team just made a new release yesterday, they can support a list of hugo symbols now in their genes API.

Copy link
Member

@onursumer onursumer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thanks!

Just added a few minor suggestions.

packages/cbioportal-utils/src/civic/CivicDataFetcher.ts Outdated Show resolved Hide resolved
packages/cbioportal-utils/src/civic/CivicDataFetcher.ts Outdated Show resolved Hide resolved
Copy link

netlify bot commented Jan 22, 2024

Deploy Preview for cbioportalfrontend ready!

Name Link
🔨 Latest commit ff5fb8b
🔍 Latest deploy log https://app.netlify.com/sites/cbioportalfrontend/deploys/65bb560dddaf730009af4938
😎 Deploy Preview https://deploy-preview-4775--cbioportalfrontend.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@alisman alisman self-requested a review January 22, 2024 15:38
Copy link
Member

@onursumer onursumer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a few minor suggestions

@alisman
Copy link
Collaborator

alisman commented Jan 26, 2024

@leexgh i'd like to suggest that we not use Apollo client for this. It's a rather heavy dependency to bring into the project just for one fetch and brings a lot of unecessary code/complication. We should be able to fetch data from a graphql endpoint using fetch. We just have to find the data format the endpoint expects and generate/serialize it. I'm happy to help with this and it shouldn't take more than an hour i wouldn't think.

fetch(<graphql_endpoint>, {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ query: '{ posts { title } }' }),
})
.then(res => res.json())
.then(res => console.log(res.data));

level: EvidenceLevel;
drugs: string[];
disease?: string;
export interface EvidenceCountsByType {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets put Civic in the name since it's particular to Civic, right?

let geneSymbol = mutation.gene.hugoGeneSymbol;
let geneEntry = civicGenes[geneSymbol];
let proteinChanges = [mutation.proteinChange];
const geneToProteinChangeSet: {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@leexgh just took another look at this code and i think it could use a few unit tests. it doesn't seem like the split protein changes are covered by the current spec, but i could be wrong.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add unit tests for this

}, {} as { [geneSymbol: string]: Set<String> });

for (const geneSymbol in geneToProteinChangeSet) {
if (geneSymbol in civicGenes) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think you are really just iterating through civicGenes, so no need for the outer for loop.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, all genes in civicGenes should be in mutationSpecs, so we could change it to iterating through civicGenes

const proteinChangeSet = geneToProteinChangeSet[geneSymbol];
const geneVariants = civicGenes[geneSymbol].variants;
for (const variantName in geneVariants) {
if (proteinChangeSet.has(variantName)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, if proteinChangeSet is a subjset of geneVarits, then you could just iterate through proteinChangeSet and make this code clearer.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

proteinChangeSet is not a subset of geneVarits, they both contain some variants that are not in the other set. We can do something like find shared variants from the two sets and iterate from that list, but it doesn't make the logic easier, so maybe we can keep this

@leexgh leexgh force-pushed the civic-graphql branch 3 times, most recently from bd8f301 to 4a1d818 Compare January 31, 2024 21:54
@alisman alisman merged commit 61a7cc0 into cBioPortal:master Feb 5, 2024
13 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external api This PR is related to handling an external API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Upgrade to new CIViC API
4 participants