Skip to content

Commit

Permalink
ZFIN-9213: (ZFIN#1152)
Browse files Browse the repository at this point in the history
- Give helpful errors for issues with deleting features that have FeatureDnaMutationDetail.
  • Loading branch information
rtaylorzfin authored Sep 13, 2024
1 parent e9e0771 commit 8303b21
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 123 deletions.
116 changes: 4 additions & 112 deletions source/org/zfin/feature/FeatureDnaMutationDetail.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package org.zfin.feature;

import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.GenericGenerator;
import org.zfin.sequence.ReferenceDatabase;

import javax.persistence.*;

@Setter
@Getter
@Entity
@Table(name = "feature_dna_mutation_detail")
public class FeatureDnaMutationDetail implements Cloneable {
Expand Down Expand Up @@ -51,118 +55,6 @@ public class FeatureDnaMutationDetail implements Cloneable {
private DnaMutationTerm dnaMutationTerm;


public Feature getFeature() {
return feature;
}

public void setFeature(Feature feature) {
this.feature = feature;
}

public ReferenceDatabase getReferenceDatabase() {
return referenceDatabase;
}

public void setReferenceDatabase(ReferenceDatabase referenceDatabase) {
this.referenceDatabase = referenceDatabase;
}

public DnaMutationTerm getDnaMutationTerm() {
return dnaMutationTerm;
}

public void setDnaMutationTerm(DnaMutationTerm dnaMutationTerm) {
this.dnaMutationTerm = dnaMutationTerm;
}

public Integer getDnaPositionEnd() {
return dnaPositionEnd;
}

public void setDnaPositionEnd(Integer dnaPositionEnd) {
this.dnaPositionEnd = dnaPositionEnd;
}

public Integer getDnaPositionStart() {
return dnaPositionStart;
}

public void setDnaPositionStart(Integer dnaPositionStart) {
this.dnaPositionStart = dnaPositionStart;
}

public String getDnaSequenceReferenceAccessionNumber() {
return dnaSequenceReferenceAccessionNumber;
}

public void setDnaSequenceReferenceAccessionNumber(String dnaSequenceReferenceAccessionNumber) {
this.dnaSequenceReferenceAccessionNumber = dnaSequenceReferenceAccessionNumber;
}

public Integer getNumberAddedBasePair() {
return numberAddedBasePair;
}

public void setNumberAddedBasePair(Integer numberAdditionalBasePair) {
this.numberAddedBasePair = numberAdditionalBasePair;
}

public Integer getExonNumber() {
return exonNumber;
}

public void setExonNumber(Integer exonNumber) {
this.exonNumber = exonNumber;
}

public Integer getIntronNumber() {
return intronNumber;
}

public void setIntronNumber(Integer intronNumber) {
this.intronNumber = intronNumber;
}

public Integer getNumberRemovedBasePair() {
return numberRemovedBasePair;
}

public void setNumberRemovedBasePair(Integer numberRemovedBasePair) {
this.numberRemovedBasePair = numberRemovedBasePair;
}

public String getInsertedSequence() {
return insertedSequence;
}

public void setInsertedSequence(String insertedSequence) {
this.insertedSequence = insertedSequence;
}

public String getDeletedSequence() {
return deletedSequence;
}

public void setDeletedSequence(String deletedSequence) {
this.deletedSequence = deletedSequence;
}

public String getZdbID() {
return zdbID;
}

public void setZdbID(String zdbID) {
this.zdbID = zdbID;
}

public GeneLocalizationTerm getGeneLocalizationTerm() {
return geneLocalizationTerm;
}

public void setGeneLocalizationTerm(GeneLocalizationTerm geneLocalizationTerm) {
this.geneLocalizationTerm = geneLocalizationTerm;
}

public FeatureDnaMutationDetail clone() {
try {
FeatureDnaMutationDetail detail = (FeatureDnaMutationDetail) super.clone();
Expand Down
2 changes: 1 addition & 1 deletion source/org/zfin/feature/repository/FeatureRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public interface FeatureRepository {

Feature getFeatureByAbbreviation(String featureAbbrev);

String getFeatureByAbbreviationInTrackingTable(String featureAbbrev);
FeatureTracking getFeatureByAbbreviationInTrackingTable(String featureAbbrev);

String getFeatureByIDInTrackingTable(String featTrackingFeatZdbID);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -784,12 +784,12 @@ public Feature getFeatureByAbbreviation(String name) {
}

@Override
public String getFeatureByAbbreviationInTrackingTable(String featTrackingFeatAbbrev) {
public FeatureTracking getFeatureByAbbreviationInTrackingTable(String featTrackingFeatAbbrev) {
Session session = HibernateUtil.currentSession();
String hqlFtrTrack = " select ft.featTrackingFeatAbbrev from FeatureTracking ft where ft.feature.zdbID =:featTrackingFeatAbbrev ";
Query queryTracker = session.createQuery(hqlFtrTrack);
String hqlFtrTrack = "from FeatureTracking where featTrackingFeatAbbrev = :featTrackingFeatAbbrev";
Query<FeatureTracking> queryTracker = session.createQuery(hqlFtrTrack, FeatureTracking.class);
queryTracker.setParameter("featTrackingFeatAbbrev", featTrackingFeatAbbrev);
return (String) queryTracker.uniqueResult();
return queryTracker.uniqueResult();
}

public String getFeatureByIDInTrackingTable(String featTrackingFeatZdbID) {
Expand Down
36 changes: 30 additions & 6 deletions source/org/zfin/gwt/curation/server/FeatureRPCServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import static org.zfin.framework.HibernateUtil.currentSession;
Expand Down Expand Up @@ -96,14 +98,36 @@ private void checkDupes(FeatureDTO featureDTO) throws DuplicateEntryException {
}
}

private void checkDupesinTrackingTable(FeatureDTO featureDTO) throws DuplicateEntryException {
String featureInTrackingTable = featureRepository.getFeatureByAbbreviationInTrackingTable(featureDTO.getAbbreviation());

private void checkDupesinTrackingTable(String featureAbbreviation) throws DuplicateEntryException {
FeatureTracking featureInTrackingTable = featureRepository.getFeatureByAbbreviationInTrackingTable(featureAbbreviation);

if (featureInTrackingTable != null) {
throw new DuplicateEntryException("Feature exists in the tracking table for this abbreviation: " + featureDTO.getAbbreviation());
String labPrefix = getLabPrefixFromFeatureAbbreviation(featureAbbreviation);

String nextLine = null;
if (labPrefix != null) {
nextLine = getFeatureRepository().getNextLineNumberForLabPrefix(labPrefix);
}

String helpfulTip = "";
if (nextLine != null && labPrefix != null) {
helpfulTip = " Next line number for this lab prefix is: " + nextLine + ".";
}

throw new DuplicateEntryException(
"Feature exists in the tracking table for this abbreviation: " + featureAbbreviation + ". " + helpfulTip);
}
}

private String getLabPrefixFromFeatureAbbreviation(String line) {
String pattern = "(.*?)(\\d+)";
Pattern r = Pattern.compile(pattern);
Matcher m = r.matcher(line);

if (m.find()) {
return m.group(1);
}
return null;
}

private void updateFeatureLocation(FeatureLocation fl, FeatureDTO dto) {
Expand Down Expand Up @@ -579,7 +603,7 @@ public FeatureDTO createFeature(FeatureDTO featureDTO) throws DuplicateEntryExce

DTOConversionService.escapeFeatureDTO(featureDTO);
checkDupes(featureDTO);
checkDupesinTrackingTable(featureDTO);
checkDupesinTrackingTable(featureDTO.getAbbreviation());
validateUnspecified(featureDTO);

FeatureDTO newFeatureDTO;
Expand Down Expand Up @@ -607,7 +631,7 @@ public FeatureDTO createFeature(FeatureDTO featureDTO) throws DuplicateEntryExce
feature.getAliases().add(featureAlias);
}


checkDupesinTrackingTable(feature.getAbbreviation());
getFeatureRepository().saveFeature(feature, publication);
if (CollectionUtils.isNotEmpty(featureDTO.getPublicNoteList())) {

Expand Down
10 changes: 10 additions & 0 deletions source/org/zfin/infrastructure/delete/DeleteFeatureRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ public List<DeleteValidationReport> validate() {
addToValidationReport(feature.getAbbreviation() + " has the following accession numbers associated: ", feature.getDbLinks());
}

// Can't delete the feature if it has mutation details
if (CollectionUtils.isNotEmpty(feature.getFeatureDnaMutationDetailSet())) {
addToValidationReport("Need to remove Mutation Detail data.");
}

// Can't delete the feature if it has protein mutation details
if (CollectionUtils.isNotEmpty(feature.getFeatureProteinMutationDetailSet())) {
addToValidationReport("Need to remove Protein Mutation Detail data.");
}

// Can't delete the feature if it has more than 1 publications
if (CollectionUtils.isNotEmpty(featurePublications) && featurePublications.size() > 1) {
addToValidationReport(feature.getAbbreviation() + " associated with more than one publication: ", featurePublications);
Expand Down

0 comments on commit 8303b21

Please sign in to comment.