Skip to content

Commit

Permalink
Merge pull request #1122 from griffithlab/variant-tsv
Browse files Browse the repository at this point in the history
Update Variant TSV exporter to include new variant types
  • Loading branch information
acoffman authored Oct 16, 2024
2 parents f6098ee + fc1ddb5 commit 3e90167
Showing 1 changed file with 110 additions and 25 deletions.
135 changes: 110 additions & 25 deletions server/app/tsv_formatters/variant_tsv_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,33 @@ def self.objects
Variant.joins(molecular_profiles: [:evidence_items])
.includes(:variant_groups, :variant_types, :hgvs_descriptions, :variant_aliases, :feature)
.where("evidence_items.status = 'accepted'")
.where(features: { feature_instance_type: 'Features::Gene'})
.distinct
end

def self.headers
[
shared_headers = [
'variant_id',
'variant_civic_url',
'gene',
'entrez_id',
'feature_type',
'feature_id',
'feature_name',
'feature_civic_url',
'variant',
'variant_aliases',
'is_flagged',
'variant_groups',
'variant_types',
'single_variant_molecular_profile_id',
'last_review_date',
]

shared_headers + gene_headers + factor_headers + fusion_headers
end

def self.gene_headers
[
'gene',
'entrez_id',
'chromosome',
'start',
'stop',
Expand All @@ -23,29 +38,40 @@ def self.headers
'representative_transcript',
'ensembl_version',
'reference_build',
'chromosome2',
'start2',
'stop2',
'representative_transcript2',
'variant_types',
'hgvs_descriptions',
'last_review_date',
'allele_registry_id',
'clinvar_ids',
'variant_aliases',
'is_flagged',
'single_variant_molecular_profile_id'
]
end

def self.row_from_object(variant)
def self.factor_headers
[
variant.id,
LinkAdaptors::Variant.new(variant).permalink_path(include_domain: true),
'ncit_id'
]
end

def self.fusion_headers
[
'5_prime_partner_status',
'5_prime_partner',
'3_prime_partner_status',
'3_prime_partner',
'vicc_compliant_name',
'5_prime_transcript',
'5_prime_end_exon',
'5_prime_exon_offset',
'5_prime_exon_offset_direction',
'3_prime_transcript',
'3_prime_start_exon',
'3_prime_exon_offset',
'3_prime_exon_offset_direction',
]
end

def self.create_gene_row(variant)
row = [
variant.feature.name,
variant.feature.feature_instance.entrez_id,
variant.name,
variant.variant_groups.map(&:name).join(','),
variant.chromosome,
variant.start,
variant.stop,
Expand All @@ -54,19 +80,78 @@ def self.row_from_object(variant)
variant.representative_transcript,
variant.ensembl_version,
variant.reference_build,
variant.chromosome2,
variant.start2,
variant.stop2,
variant.representative_transcript2,
variant.variant_types.map(&:name).join(','),
variant.hgvs_descriptions.map(&:description).join(','),
variant.updated_at,
variant.allele_registry_id,
variant.clinvar_entries.map(&:clinvar_id).join(','),
]
row += Array.new(factor_headers.size)
row += Array.new(fusion_headers.size)
return row
end

def self.create_factor_row(variant)
row = Array.new(gene_headers.size)
row += [
variant.ncit_id
]
row += Array.new(fusion_headers.size)
return row
end

def self.create_fusion_row(variant)
fusion_feature = variant.feature.feature_instance
five_prime_coords = variant.five_prime_end_exon_coordinates
three_prime_coords = variant.three_prime_start_exon_coordinates

row = Array.new(gene_headers.size)
row += Array.new(factor_headers.size)
row += [
fusion_feature.five_prime_partner_status,
fusion_feature.five_prime_gene&.name,
fusion_feature.three_prime_partner_status,
fusion_feature.three_prime_gene&.name,
variant.vicc_compliant_name,
five_prime_coords&.representative_transcript,
five_prime_coords&.exon,
five_prime_coords&.exon_offset,
five_prime_coords&.exon_offset_direction,
three_prime_coords&.representative_transcript,
three_prime_coords&.exon,
three_prime_coords&.exon_offset,
three_prime_coords&.exon_offset_direction,
]
return row
end

def self.row_from_object(variant)
shared_cols = [
variant.id,
LinkAdaptors::Variant.new(variant).permalink_path(include_domain: true),
variant.feature.feature_instance_type.demodulize,
variant.feature.id,
variant.feature.name,
LinkAdaptors::Feature.new(variant.feature).permalink_path(include_domain: true),
variant.name,
variant.variant_aliases.map(&:name).join(','),
variant.flagged,
variant.single_variant_molecular_profile_id
variant.variant_groups.map(&:name).join(','),
variant.variant_types.map(&:name).join(','),
variant.single_variant_molecular_profile_id,
variant.updated_at,
]

variant_cols = case variant
when Variants::GeneVariant
create_gene_row(variant)
when Variants::FactorVariant
create_factor_row(variant)
when Variants::FusionVariant
create_fusion_row(variant)
else
raise StandardError.new("Unknown variant type for TSV export: #{variant.class}")
end

shared_cols + variant_cols
end

def self.file_name
Expand Down

0 comments on commit 3e90167

Please sign in to comment.