Module: Export::Coldp::Files::Synonym
- Defined in:
- lib/export/coldp/files/synonym.rb
Overview
The synonym table is a list of all the Names (valid and invalid) that have been used for valid OTUs (Taxa) in the current classification.
Only TaxonIds for valid OTUs valid taxon names should be here, though the CoL parser format will apparently handle taxon ids that are not in the taxon table.
Bigger picture: understand how this maps to core name usage table in CoL
We assume that the names exporting in Names are those that must be tied to Taxa, so we re-use that scoping.
!! TODO: While the scoping of names to be considered is likely correct, invalid names are not likely pointing to valid OTUs, but rather invalid OTUs.
!? To resolve this create a single lookup of all possibile name_ids to their valid otu_id !! TODO: If a lookup is in place, then we can do this all in parallel with Name.tsv, i.e. completely removing a redundant pass
Class Method Summary collapse
- .add_combinations(otu, otus, csv, project_members) ⇒ Object
- .add_invalid_core_names(otu, otus, csv, project_members) ⇒ Object
- .add_invalid_family_and_higher_names(otu, otus, csv, project_members) ⇒ Object
- .add_original_combinations(otu, otus, csv, project_members) ⇒ Object
- .generate(otu, otus, project_members, reference_csv = nil) ⇒ Object
-
.status(o, t) ⇒ Object
Last 3 of api.checklistbank.org/vocab/taxonomicstatus.
Class Method Details
.add_combinations(otu, otus, csv, project_members) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/export/coldp/files/synonym.rb', line 74 def self.add_combinations(otu, otus, csv, project_members) names = ::Export::Coldp::Files::Name.combination_names(otu).unscope(:select).select(:id, :cached_valid_taxon_name_id) x = Otu.with(name_scope: names) .joins('JOIN name_scope on name_scope.cached_valid_taxon_name_id = otus.taxon_name_id') .select(:id, :taxon_name_id) # TODO: ok to this point (check that we are not duplicating rows in y? y = TaxonName.with(invalid_names: names, otu_scope: x) .joins('JOIN invalid_names on invalid_names.id = taxon_names.id') .joins('LEFT JOIN otu_scope os on os.taxon_name_id = taxon_names.cached_valid_taxon_name_id') .select('invalid_names.id, MAX(os.id) AS otu_id, taxon_names.updated_at, taxon_names.updated_by_id') # housekeeping is meaningless here .group('taxon_names.id, invalid_names.id') y.find_each do |n| next if ::Export::Coldp.skipped_combinations.include?(n.id) csv << [ n.otu_id, # taxonID attached to the current valid concept n.id, # nameID nil, # status TODO: def status(taxon_name_id) nil, # remarks nil, # referenceID Unclear what this means in TW Export::Coldp.modified(n.updated_at), # modified Export::Coldp.modified_by(n.updated_by_id, project_members) # modifiedBy ] end end |
.add_invalid_core_names(otu, otus, csv, project_members) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/export/coldp/files/synonym.rb', line 45 def self.add_invalid_core_names(otu, otus, csv, project_members) names = ::Export::Coldp::Files::Name.invalid_core_names(otu) names.length # TODO: needed? x = Otu.with(name_scope: names) .joins('JOIN name_scope on name_scope.cached_valid_taxon_name_id = otus.taxon_name_id') .select(:id) y = TaxonName.with(invalid_names: names) .joins('JOIN invalid_names on invalid_names.cached_valid_taxon_name_id = taxon_names.id') .joins('LEFT JOIN otus on otus.taxon_name_id = taxon_names.id') .select('invalid_names.id, MAX(otus.id) AS otu_id, taxon_names.updated_at, taxon_names.updated_by_id') # housekeeping is meaningless here .group('taxon_names.id, invalid_names.id') y.find_each do |n| csv << [ n.otu_id, # taxonID attached to the current valid concept n.id, # nameID nil, # status TODO: def status(taxon_name_id) nil, # remarks nil, # referenceID Unclear what this means in TW Export::Coldp.modified(n.updated_at), # modified Export::Coldp.modified_by(n.updated_by_id, project_members) # modifiedBy ] end end |
.add_invalid_family_and_higher_names(otu, otus, csv, project_members) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/export/coldp/files/synonym.rb', line 105 def self.add_invalid_family_and_higher_names(otu, otus, csv, project_members) names = ::Export::Coldp::Files::Name.invalid_family_and_higher_names(otu) names.length # TODO: needed? x = Otu.with(name_scope: names) .joins('JOIN name_scope on name_scope.cached_valid_taxon_name_id = otus.taxon_name_id') .select(:id) y = TaxonName.with(invalid_names: names) .joins('JOIN invalid_names on invalid_names.cached_valid_taxon_name_id = taxon_names.id') .joins('LEFT JOIN otus on otus.taxon_name_id = taxon_names.id') .select('invalid_names.id, MAX(otus.id) AS otu_id, taxon_names.updated_at, taxon_names.updated_by_id') # housekeeping is meaningless here .group('taxon_names.id, invalid_names.id') # x = Otu.with(name_scope: names) # .joins('JOIN name_scope on name_scope.id = otus.taxon_name_id') # .select(:id) # y = Otu.with(otu_scope: x) # .joins('JOIN otu_scope on otu_scope.id = otus.id') # .select(:id, :taxon_name_id, :updated_at, :updated_by_id) y.find_each do |n| csv << [ n.otu_id, # taxonID attached to the current valid concept n.id, # nameID nil, # status TODO: def status(taxon_name_id) nil, # remarks nil, # referenceID Unclear what this means in TW Export::Coldp.modified(n.updated_at), # modified Export::Coldp.modified_by(n.updated_by_id, project_members) # modifiedBy ] end end |
.add_original_combinations(otu, otus, csv, project_members) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/export/coldp/files/synonym.rb', line 140 def self.add_original_combinations(otu, otus, csv, project_members) names = ::Export::Coldp::Files::Name.original_combination_names(otu) x = Otu.with(name_scope: names) .joins('JOIN name_scope on name_scope.cached_valid_taxon_name_id = otus.taxon_name_id') .select(:id) y = TaxonName.with(invalid_names: names) .joins('JOIN invalid_names on invalid_names.cached_valid_taxon_name_id = taxon_names.id') .joins('LEFT JOIN otus on otus.taxon_name_id = taxon_names.id') .select('invalid_names.id, MAX(otus.id) AS otu_id, taxon_names.updated_at, taxon_names.updated_by_id, invalid_names.cached_original_combination') # housekeeping is meaningless here .group('taxon_names.id, invalid_names.id, invalid_names.cached_original_combination') # a = Otu.with(name_scope: names, otu_scope: otus) # .joins('JOIN name_scope on name_scope.id = otus.taxon_name_id') # .joins('JOIN otu_scope on otu_scope.id = otus.id') # .select('otus.id, otus.taxon_name_id, otus.updated_at, otus.updated_by_id, name_scope.cached_original_combination').distinct y.find_each do |n| # By `original_combination_names(otu) these are all reified reified_id = ::Utilities::Nomenclature.reified_id(n.id, n.cached_original_combination) csv << [ n.otu_id, # taxonID attached to the current valid concept reified_id, # nameID nil, # status TODO: def status(taxon_name_id) nil, # remarks nil, # referenceID Unclear what this means in TW Export::Coldp.modified(n.updated_at), # modified Export::Coldp.modified_by(n.updated_by_id, project_members) # modifiedBy ] end end |
.generate(otu, otus, project_members, reference_csv = nil) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/export/coldp/files/synonym.rb', line 34 def self.generate(otu, otus, project_members, reference_csv = nil) ::CSV.generate(col_sep: "\t") do |csv| csv << %w{taxonID nameID status remarks referenceID modified modifiedBy} add_invalid_family_and_higher_names(otu, otus, csv, project_members) add_invalid_core_names(otu, otus, csv, project_members) add_original_combinations(otu, otus, csv, project_members) add_combinations(otu, otus, csv, project_members) end end |
.status(o, t) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/export/coldp/files/synonym.rb', line 23 def self.status(o, t) #'accepted' #'provisionally accepted' #'synonym' #'ambiguous synonym' #'missaplied' 'synonym' end |