Module: Export::Coldp::Files::SpeciesInteraction
- Defined in:
- lib/export/coldp/files/species_interaction.rb
Overview
taxonID relatedTaxonID relatedTaxonScientificName type referenceID remarks
Class Method Summary collapse
- .generate(otus, project_members, reference_csv = nil) ⇒ Object
- .related_taxon_id(ba) ⇒ Object
- .related_taxon_scientific_name(otu_id) ⇒ Object
- .species_interaction_type(ba, inverted = false) ⇒ Object
- .taxon_id(ba) ⇒ Object
Class Method Details
.generate(otus, project_members, reference_csv = nil) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 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 |
# File 'lib/export/coldp/files/species_interaction.rb', line 59 def self.generate(otus, project_members, reference_csv = nil ) CSV.generate(col_sep: "\t") do |csv| csv << %w{ taxonID relatedTaxonID relatedTaxonScientificName type referenceID modified modifiedBy remarks } q = ::Queries::BiologicalAssociation::Filter.new({}) q.otu_query = otus # TODO: expand for CollectionObject or FO occurrences later q.all.where(biological_association_subject_type: 'Otu', biological_association_object_type: 'Otu' ).find_each do |ba| taxon_id = taxon_id(ba) = (ba) sources = ba.sources.load reference_ids = sources.collect{|a| a.id} reference_id = reference_ids.first csv << [ taxon_id, # taxonID , # relatedTaxonID (), # relatedTaxonScientificName species_interaction_type(ba), # type reference_id, # referenceID Export::Coldp.modified(ba[:update_at]), # modified Export::Coldp.modified_by(ba[:updated_by_id], project_members), # modified_by nil # remarks ] Export::Coldp::Files::Reference.add_reference_rows(sources, reference_csv, project_members) if reference_csv end # end end end |
.related_taxon_id(ba) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/export/coldp/files/species_interaction.rb', line 22 def self.(ba) object_otu = nil if ba.biological_association_object_type == "Otu" begin object_otu = Otu.find(ba.biological_association_object_id).id rescue ActiveRecord::RecordNotFound object_otu = nil end end object_otu end |
.related_taxon_scientific_name(otu_id) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/export/coldp/files/species_interaction.rb', line 34 def self.(otu_id) object_taxon_name = nil begin o = Otu.find(otu_id) rescue ActiveRecord::RecordNotFound return nil end if !o.taxon_name_id.nil? object_taxon_name = TaxonName.find(o.taxon_name_id).cached else unless o.name.nil? object_taxon_name = o.name end end object_taxon_name end |
.species_interaction_type(ba, inverted = false) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/export/coldp/files/species_interaction.rb', line 51 def self.species_interaction_type(ba, inverted=false) species_interaction_type = BiologicalRelationship.find(ba.biological_relationship_id).name if inverted species_interaction_type = BiologicalRelationship.find(ba.biological_relationship_id).inverted_name end species_interaction_type end |
.taxon_id(ba) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/export/coldp/files/species_interaction.rb', line 10 def self.taxon_id(ba) subject_otu = nil if ba.biological_association_subject_type == "Otu" begin subject_otu = Otu.find(ba.biological_association_subject_id).id rescue ActiveRecord::RecordNotFound subject_otu = nil end end subject_otu end |