-
Notifications
You must be signed in to change notification settings - Fork 32
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
Create UniProt Mapping file. #691
base: staging
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
class GenerateUniprotMappingTsv < GenerateTsvs | ||
def perform | ||
ensure_downloads_directory_exists | ||
tsvs_to_generate.each do |e| | ||
begin | ||
tmp_file = tmp_file(e.file_name) | ||
tmp_file.puts(e.headers.join("\t")) | ||
|
||
e.objects.find_each do |object| | ||
|
||
row = e.row_from_object(object) | ||
if row[1].is_a?(Array) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I might change this to be |
||
overview_col = e.formatted_overview_col(object) | ||
row[1].each do |r| | ||
new_row = [row[0], r, overview_col].join("\t") | ||
tmp_file.puts(new_row) | ||
end | ||
elsif row[1] == "N/A" | ||
next | ||
else | ||
tmp_file.puts(row.join("\t")) | ||
end | ||
end | ||
|
||
tmp_file.close | ||
public_path = public_file_path(e.file_name) | ||
FileUtils.cp(tmp_file.path, public_path) | ||
File.chmod(0644, public_path) | ||
ensure | ||
tmp_file.unlink | ||
end | ||
end | ||
end | ||
|
||
def tsvs_to_generate | ||
[UniprotMappingTsvPresenter] | ||
end | ||
|
||
def public_file_path(filename) | ||
File.join(downloads_dir_path, filename) | ||
end | ||
|
||
def downloads_dir_path | ||
TsvRelease.downloads_path | ||
end | ||
|
||
def release_path | ||
'' | ||
end | ||
|
||
def filename_prefix | ||
'' | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
class UniprotMappingTsvPresenter | ||
def self.objects | ||
Gene.joins(variants: :evidence_items).where("variants.evidence_items.status!='rejected'").distinct | ||
end | ||
|
||
def self.headers | ||
[ | ||
'civic_name', | ||
'uniprot_name', | ||
'gene_overview' | ||
] | ||
end | ||
|
||
def self.row_from_object(gene) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rename to
That way you have a list of rows for your TSV, |
||
[ | ||
gene.name, | ||
Scrapers::MyGeneInfo.get_swissprot_name(gene), | ||
formatted_overview_col(gene) | ||
] | ||
end | ||
|
||
def self.file_name | ||
"UniprotMapping.tsv" | ||
end | ||
|
||
def self.formatted_overview_col(gene) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd get the counts in the following ways:
You could also invert the logic and do something like this:
depending on what's more clear to you. |
||
|
||
eid_count = 0 | ||
gene.variants.each do |vs| | ||
eid_count += vs.evidence_items.size | ||
end | ||
"#{gene.assertions.size} clinical assertion(s) and #{eid_count} evidence item(s) for #{gene.variants.size} variant(s) curated from #{gene.sources.size} published source(s)" | ||
end | ||
end |
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.
You probably don't need the indirection here of calling
e.objects
and can deletedef self.objects
in the presenter file. This can probably just beGene.find_each