Skip to content

Commit

Permalink
make the check for existing asm_accession before proceeding with down…
Browse files Browse the repository at this point in the history
…load and the ingestion process
  • Loading branch information
waterflow80 committed Feb 5, 2024
1 parent 419417b commit 2c0ee58
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package uk.ac.ebi.eva.evaseqcol.entities;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Type;
Expand Down Expand Up @@ -39,13 +38,13 @@ public class SeqColLevelOneEntity extends SeqColEntity{
protected NamingConvention namingConvention;

@Column(name = "insdc_accession")
private String asm_accession; // The INSDC assembly accession from which the seqcol was created
private String asmAccession; // The INSDC assembly accession from which the seqcol was created

public SeqColLevelOneEntity(String digest, NamingConvention namingConvention, JSONLevelOne jsonLevelOne, String asm_accession){
public SeqColLevelOneEntity(String digest, NamingConvention namingConvention, JSONLevelOne jsonLevelOne, String asmAccession){
super(digest, namingConvention);
this.seqColLevel1Object = jsonLevelOne;
this.namingConvention = namingConvention;
this.asm_accession = asm_accession;
this.asmAccession = asmAccession;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
@Repository
public interface SeqColLevelOneRepository extends JpaRepository<SeqColLevelOneEntity, String> {
SeqColLevelOneEntity findSeqColLevelOneEntityByDigest(String digest);
boolean existsByAsmAccession(String asm_accession);

long countSeqColLevelOneEntitiesByDigest(String digest);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ public Optional<SeqColLevelOneEntity> getSeqColLevelOneByDigest(String digest){
}
}

/**
* Check whether the given asm_accession exists in the database (in the sequence_collection_level1)*/
public boolean isAsmAccessionExists(String asm_accession) {
return repository.existsByAsmAccession(asm_accession);
}

public void removeSeqColLevelOneByDigest(String digest) {
repository.removeSeqColLevelOneEntityByDigest(digest);
}
Expand All @@ -67,7 +73,7 @@ public SeqColLevelOneEntity constructSeqColLevelOne(List<SeqColExtendedDataEntit
List<SeqColExtendedDataEntity<List<Integer>>> integerListExtendedDataEntities,
SeqColEntity.NamingConvention convention, String asm_accession) throws IOException {
SeqColLevelOneEntity levelOneEntity = new SeqColLevelOneEntity();
levelOneEntity.setAsm_accession(asm_accession);
levelOneEntity.setAsmAccession(asm_accession);
JSONLevelOne jsonLevelOne = new JSONLevelOne();

// Looping over List<String> types
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/uk/ac/ebi/eva/evaseqcol/service/SeqColService.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ public void removeAllSeqCol() {
public IngestionResultEntity fetchAndInsertAllSeqColByAssemblyAccession(
String assemblyAccession) throws IOException, DuplicateSeqColException, AssemblyNotFoundException,
AssemblyAlreadyIngestedException{
if (levelOneService.isAsmAccessionExists(assemblyAccession)) {
logger.warn("Seqcol objects for assembly " + assemblyAccession + " has been already ingested");
throw new AssemblyAlreadyIngestedException(assemblyAccession);
}
Optional<Map<String, Object>> seqColDataMap = ncbiSeqColDataSource
.getAllPossibleSeqColExtendedData(assemblyAccession);
if (!seqColDataMap.isPresent()) {
Expand Down Expand Up @@ -218,12 +222,7 @@ public IngestionResultEntity fetchAndInsertAllSeqColByAssemblyAccession(
" already exists. Skipping.");
}
}
if (ingestionResultEntity.getNumberOfInsertedSeqcols() == 0) {
logger.warn("Seqcol objects for assembly " + assemblyAccession + " has been already ingested");
throw new AssemblyAlreadyIngestedException(assemblyAccession);
} else {
return ingestionResultEntity;
}
return ingestionResultEntity;

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.support.BasicAuthenticationInterceptor;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.springframework.transaction.annotation.Transactional;
Expand Down Expand Up @@ -106,7 +105,7 @@ void ingestSeqColsTest() {
assertTrue(levelTwoEntity.isPresent());
assertEquals(insertedSeqColDigest,levelOneEntity.get().getDigest());
assertNotNull(levelTwoEntity.get().getLengths());
assertEquals(ASM_ACCESSION, levelOneEntity.get().getAsm_accession());
assertEquals(ASM_ACCESSION, levelOneEntity.get().getAsmAccession());
}

@Test
Expand Down

0 comments on commit 2c0ee58

Please sign in to comment.