Skip to content

Commit

Permalink
Fix InatObs#sequences bugs
Browse files Browse the repository at this point in the history
- Stops this method from zapping `inat_obs_fields`
- Refines condition for text :datatype sequences
Text must start with 10 ACGT bases
  • Loading branch information
JoeCohen committed Aug 5, 2024
1 parent 9c850c9 commit 4e8049c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 33 deletions.
6 changes: 2 additions & 4 deletions app/classes/inat_obs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,7 @@ def lng
end

def sequences
obs_sequence_fields =
inat_obs_fields.keep_if { |f| sequence_field?(f) }

obs_sequence_fields = inat_obs_fields.select { |f| sequence_field?(f) }
obs_sequence_fields.each_with_object([]) do |field, ary|
# TODO: 2024-06-19 jdc. Need more investigation/test to handle
# field[:value] blank or not a (pure) lists of bases
Expand Down Expand Up @@ -297,7 +295,7 @@ def description

def sequence_field?(field)
field[:datatype] == "dna" ||
field[:name] =~ /DNA/
field[:name] =~ /DNA/ && field[:value] =~ /^[ACTG]{,10}/
end

def fungi?
Expand Down
58 changes: 29 additions & 29 deletions app/controllers/observations/inat_imports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -343,35 +343,6 @@ def adjust_consensus_name_naming
end
end

def add_inat_summmary_data(inat_obs)
params = {
target: @observation,
summary: "#{:inat_data_comment.t} #{@observation.created_at}",
comment: comment(inat_obs),
user: inat_manager
}

Comment.create(params)
end

def comment(inat_obs)
<<~COMMENT.gsub(/^\s+/, "")
#{:USER.t}: #{inat_obs.inat_user_login}
#{:OBSERVED.t}: #{inat_obs.when}\n
#{:LAT_LON.t}: #{lat_lon_accuracy(inat_obs)}\n
#{:PLACE.t}: #{inat_obs.inat_place_guess}\n
#{:ID.t}: #{inat_obs.inat_taxon_name}\n
#{:DQA.t}: #{inat_obs.dqa}\n
#{:ANNOTATIONS.t}: #{:UNDER_DEVELOPMENT.t}\n
#{:PROJECTS.t}: #{inat_obs.inat_project_names}\n
#{:SEQUENCES.t}: #{:UNDER_DEVELOPMENT.t}\n
#{:OBSERVATION_FIELDS.t}: \n\
#{obs_fields(inat_obs.inat_obs_fields)}\n
#{:TAGS.t}: #{inat_obs.inat_tags.join(" ")}\n
COMMENT
end

def lat_lon_accuracy(inat_obs)
"#{inat_obs.inat_location} " \
"+/-#{inat_obs.inat_public_positional_accuracy} m"
Expand Down Expand Up @@ -402,5 +373,34 @@ def obs_fields(fields)
"&nbsp;&nbsp;#{field[:name]}: #{field[:value]}"
end.join("\n")
end

def add_inat_summmary_data(inat_obs)
params = {
target: @observation,
summary: "#{:inat_data_comment.t} #{@observation.created_at}",
comment: comment(inat_obs),
user: inat_manager
}

Comment.create(params)
end

def comment(inat_obs)
<<~COMMENT.gsub(/^\s+/, "")
#{:USER.t}: #{inat_obs.inat_user_login}
#{:OBSERVED.t}: #{inat_obs.when}\n
#{:LAT_LON.t}: #{lat_lon_accuracy(inat_obs)}\n
#{:PLACE.t}: #{inat_obs.inat_place_guess}\n
#{:ID.t}: #{inat_obs.inat_taxon_name}\n
#{:DQA.t}: #{inat_obs.dqa}\n
#{:ANNOTATIONS.t}: #{:UNDER_DEVELOPMENT.t}\n
#{:PROJECTS.t}: #{inat_obs.inat_project_names}\n
#{:SEQUENCES.t}: #{:UNDER_DEVELOPMENT.t}\n
#{:OBSERVATION_FIELDS.t}: \n\
#{obs_fields(inat_obs.inat_obs_fields)}\n
#{:TAGS.t}: #{inat_obs.inat_tags.join(" ")}\n
COMMENT
end
end
end

0 comments on commit 4e8049c

Please sign in to comment.