diff --git a/server/app/tsv_formatters/variant_tsv_formatter.rb b/server/app/tsv_formatters/variant_tsv_formatter.rb index c49a29fe2..dd33e8c01 100644 --- a/server/app/tsv_formatters/variant_tsv_formatter.rb +++ b/server/app/tsv_formatters/variant_tsv_formatter.rb @@ -3,18 +3,32 @@ 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_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', @@ -23,29 +37,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, @@ -54,19 +79,77 @@ 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, + 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("Unkown variant type for TSV export: #{variant.class}") + end + + shared_cols + variant_cols end def self.file_name