Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle full subspecies name in taxa upload #4094

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions bims/scripts/taxa_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,11 @@ def validate_parents(self, taxon, row):
csv_data = DataCSVUpload.row_value(
row, taxon_parent_rank.capitalize())
if taxon_parent_rank == SPECIES:
csv_data = DataCSVUpload.row_value(
row, GENUS) + ' ' + csv_data
genus = DataCSVUpload.row_value(
row, GENUS)
if genus not in csv_data:
csv_data = DataCSVUpload.row_value(
row, GENUS) + ' ' + csv_data
except KeyError:
parent = parent.parent
continue
Expand All @@ -218,7 +221,7 @@ def validate_parents(self, taxon, row):
print('Different parent for {}'.format(str(taxon)))
taxon_parent = self.get_parent(
row,
current_rank=taxon_parent_rank.upper()
current_rank=PARENT_RANKS.get(taxon_parent_rank.upper(), '')
)
print('Updated to {}'.format(str(taxon_parent)))
taxon.parent = taxon_parent
Expand All @@ -227,7 +230,7 @@ def validate_parents(self, taxon, row):
parent = parent.parent
if self.rank_name(taxon) != 'KINGDOM' and not parent:
parent = self.get_parent(
row, current_rank=taxon.rank.capitalize()
row, current_rank=PARENT_RANKS.get(taxon.rank.upper(), '')
)
if parent:
taxon.parent = parent
Expand Down Expand Up @@ -278,7 +281,9 @@ def get_parent(self, row, current_rank=GENUS):
if not taxon_name:
return None
if current_rank == SPECIES:
taxon_name = DataCSVUpload.row_value(row, GENUS) + ' ' + taxon_name
genus_name = DataCSVUpload.row_value(row, GENUS)
if genus_name not in taxon_name:
taxon_name = DataCSVUpload.row_value(row, GENUS) + ' ' + taxon_name
if current_rank == VARIETY:
taxon_name = (
DataCSVUpload.row_value(row, GENUS) + ' ' +
Expand All @@ -290,7 +295,7 @@ def get_parent(self, row, current_rank=GENUS):
taxon_name,
current_rank.upper()
)
while not taxon.gbif_key or not taxon.parent or taxon.parent.rank != 'KINGDOM':
while not taxon.gbif_key or not taxon.parent and taxon.parent.rank != 'KINGDOM':
parent_rank_name = parent_rank(current_rank)
if not parent_rank_name:
break
Expand Down Expand Up @@ -452,8 +457,8 @@ def process_data(self, row, taxon_group: TaxonGroup):

# Taxonomy found or created then validate it
if taxonomy:
if not taxonomy.parent:
taxonomy.parent = self.get_parent(row, parent_rank(rank))
if not taxonomy.parent and parent:
taxonomy.parent = parent

# Data from GBIF couldn't be found, so add it manually
if not taxonomy:
Expand Down