-
Notifications
You must be signed in to change notification settings - Fork 4
DSERV-1291 Scorpion adapter #713
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
Open
pedrohr
wants to merge
15
commits into
dev
Choose a base branch
from
DSERV-1291-scorpion
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
cb75ec9
scorpion adapter
pedrohr a610d80
fix jsonschema issue
pedrohr b42f5a4
removing spaces in _key
pedrohr eba254c
updating files_filesets
pedrohr d742ed1
fetching metadata from collection
pedrohr f051da4
resolving ids
pedrohr 9db98d5
adding neglog10 pvalue
pedrohr 1867473
correct floating point
pedrohr 13514a4
beta -> effect_size
pedrohr 3923169
updating specs
pedrohr 3bfd21a
skip bug
pedrohr d92673a
updating schemas
pedrohr cc8050c
edge case for mapping
pedrohr 2ba0fc0
correct naming
pedrohr 20357f3
spec
pedrohr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| import csv | ||
| import requests | ||
| import gzip | ||
| import json | ||
| import math | ||
| from typing import Optional | ||
|
|
||
| from adapters.helpers import get_file_fileset_by_accession_in_arangodb, gene_synonym_to_ensembl_id | ||
| from adapters.base import BaseAdapter | ||
| from adapters.writer import Writer | ||
|
|
||
| # Sample data: | ||
| # tf,tf_ensembl,target,target_ensembl,beta,P,FDR | ||
| # ZNF250,ENSG00000196150,WNK1,ENSG00000060237,2.79614395634379,2.23950511461299e-22,2.2770944348533403e-19 | ||
| # ZNF770,ENSG00000198146,IL32,ENSG00000008517,2.68504180081855,1.80943850543389e-22,1.8921041491990902e-19 | ||
| # ZNF250,ENSG00000196150,RAB3GAP1,ENSG00000115839,2.60846182810368,6.8583125999997006e-15,4.46018704732234e-13 | ||
| # ZNF770,ENSG00000198146,FXYD5,ENSG00000089327,2.47636665757162,2.6083752753581298e-30,2.82424470955305e-26 | ||
| # ZNF250,ENSG00000196150,ECD,ENSG00000122882,2.47274455661664,1.0652979856438198e-11,2.14332529077824e-10 | ||
| # SP2,ENSG00000167182,IL32,ENSG00000008517,2.46075901773533,4.1256177738298497e-22,3.83064494763081e-19 | ||
| # KLF5,ENSG00000102554,RGS1,ENSG00000090104,-2.45832343792633,9.80241382630337e-12,1.9972107166922901e-10 | ||
| # ZNF250,ENSG00000196150,SECISBP2L,ENSG00000138593,2.44734259208731,8.10284619583455e-10,8.828469446648141e-09 | ||
|
|
||
|
|
||
| class ScorpionAdapter(BaseAdapter): | ||
| SOURCE = 'IGVF' | ||
| LABEL = 'predicted gene regulatory networks' | ||
|
|
||
| def __init__(self, filepath=None, writer: Optional[Writer] = None, validate=False, **kwargs): | ||
| self.filepath = filepath | ||
| self.file_accession = self.filepath.split('/')[-1].split('.')[0] | ||
| self.source_url = 'https://data.igvf.org/tabular-files/' + self.file_accession | ||
| super().__init__(filepath, '', writer, validate) | ||
|
|
||
| def process_file(self) -> Optional[dict]: | ||
| self.writer.open() | ||
| file_fileset_obj = get_file_fileset_by_accession_in_arangodb( | ||
| self.file_accession) | ||
| self.method = file_fileset_obj['method'] | ||
| self.collection_class = file_fileset_obj['class'] | ||
|
|
||
| with gzip.open(self.filepath, 'rt') as data_file: | ||
| data_csv = csv.DictReader(data_file) | ||
|
|
||
| skip = False | ||
| for row in data_csv: | ||
| if row['tf_ensembl'] == '': | ||
| if row['tf'] != '': | ||
| tf_ensembl = gene_synonym_to_ensembl_id(row['tf']) | ||
| if tf_ensembl is not None: | ||
| row['tf_ensembl'] = tf_ensembl | ||
| else: | ||
| skip = True | ||
| if row['target_ensembl'] == '': | ||
| if row['target'] != '': | ||
| target_ensembl = gene_synonym_to_ensembl_id( | ||
| row['target']) | ||
| if target_ensembl is not None: | ||
| row['target_ensembl'] = target_ensembl | ||
| else: | ||
| skip = True | ||
|
|
||
| if skip: | ||
| print('Row is invalid or gene name resolution failed, skipping:') | ||
| print(row) | ||
| skip = False | ||
| continue | ||
|
|
||
| props = { | ||
| '_key': row['tf_ensembl'] + '_' + row['target_ensembl'] + '_' + self.LABEL.replace(' ', '_'), | ||
| '_from': 'genes/' + row['tf_ensembl'], | ||
| '_to': 'genes/' + row['target_ensembl'], | ||
| 'effect_size': float(row['beta']) if row['beta'] != '' else None, | ||
| 'p_value': float(row['P']) if row['P'] != '' else None, | ||
| 'p_value_adj': float(row['FDR']) if row['FDR'] != '' else None, | ||
| 'neg_log10_p_value': -math.log10(float(row['P'])) if row['P'] != '' else None, | ||
| 'name': 'regulates', | ||
| 'inverse_name': 'is regulated by', | ||
| 'files_filesets': 'files_filesets/' + self.file_accession, | ||
| 'class': self.collection_class, | ||
| 'method': self.method, | ||
| 'label': self.LABEL, | ||
| 'source': self.SOURCE, | ||
| 'source_url': self.source_url | ||
|
|
||
| } | ||
| if self.validate: | ||
| self.validate_doc(props) | ||
|
|
||
| self.writer.write(json.dumps(props)) | ||
| self.writer.write('\n') | ||
| self.writer.close() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to also merge in dev branch and generate new files_filesets data file for IGVF source.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
may need to regenerate it again since we don't know which data loading ticket goes in first...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the only data loading ticket ready to QA is dual-ipa, it's already generated, so I think the JSONLs in this PR are the latest