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

added a column 'asm_accession' to the sequence_collection_l1 table #78

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,14 @@ public class SeqColLevelOneEntity extends SeqColEntity{
@Enumerated(EnumType.STRING)
protected NamingConvention namingConvention;

public SeqColLevelOneEntity(String digest, NamingConvention namingConvention, JSONLevelOne jsonLevelOne){
@Column(name = "insdc_accession")
private String asmAccession; // The INSDC assembly accession from which the seqcol was created

public SeqColLevelOneEntity(String digest, NamingConvention namingConvention, JSONLevelOne jsonLevelOne, String asmAccession){
super(digest, namingConvention);
this.seqColLevel1Object = jsonLevelOne;
this.namingConvention = namingConvention;
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 @@ -65,8 +71,9 @@ public List<SeqColLevelOneEntity> getAllSeqColLevelOneObjects(){
* hold names, lengths and sequences objects*/
public SeqColLevelOneEntity constructSeqColLevelOne(List<SeqColExtendedDataEntity<List<String>>> stringListExtendedDataEntities,
List<SeqColExtendedDataEntity<List<Integer>>> integerListExtendedDataEntities,
SeqColEntity.NamingConvention convention) throws IOException {
SeqColEntity.NamingConvention convention, String asm_accession) throws IOException {
SeqColLevelOneEntity levelOneEntity = new SeqColLevelOneEntity();
levelOneEntity.setAsmAccession(asm_accession);
JSONLevelOne jsonLevelOne = new JSONLevelOne();

// Looping over List<String> types
Expand Down Expand Up @@ -106,7 +113,8 @@ public SeqColLevelOneEntity constructSeqColLevelOne(List<SeqColExtendedDataEntit
/**
* Construct a Level 1 seqCol out of a Level 2 seqCol*/
public SeqColLevelOneEntity constructSeqColLevelOne(
SeqColLevelTwoEntity levelTwoEntity, SeqColEntity.NamingConvention convention) throws IOException {
SeqColLevelTwoEntity levelTwoEntity, SeqColEntity.NamingConvention convention, String asm_accession)
throws IOException {
DigestCalculator digestCalculator = new DigestCalculator();
JSONExtData<List<String>> sequencesExtData = new JSONStringListExtData(levelTwoEntity.getSequences());
JSONExtData<List<Integer>> lengthsExtData = new JSONIntegerListExtData(levelTwoEntity.getLengths());
Expand Down Expand Up @@ -151,7 +159,7 @@ public SeqColLevelOneEntity constructSeqColLevelOne(
lengthsExtEntity
);

return constructSeqColLevelOne(stringListExtendedDataEntities,integerListExtendedDataEntities, convention);
return constructSeqColLevelOne(stringListExtendedDataEntities,integerListExtendedDataEntities, convention, asm_accession);
}

/**
Expand Down
15 changes: 7 additions & 8 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 @@ -198,8 +202,8 @@ public IngestionResultEntity fetchAndInsertAllSeqColByAssemblyAccession(

// Constructing seqCol Level One object
SeqColLevelOneEntity levelOneEntity = levelOneService.constructSeqColLevelOne(
seqColStringListExtDataEntities, seqColIntegerListExtDataEntities, extendedNamesEntity.getNamingConvention()
);
seqColStringListExtDataEntities, seqColIntegerListExtDataEntities, extendedNamesEntity.getNamingConvention(),
assemblyAccession);

try {
Optional<String> seqColDigest = insertSeqColL1AndL2( // TODO: Check for possible self invocation problem
Expand All @@ -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,6 +105,7 @@ void ingestSeqColsTest() {
assertTrue(levelTwoEntity.isPresent());
assertEquals(insertedSeqColDigest,levelOneEntity.get().getDigest());
assertNotNull(levelTwoEntity.get().getLengths());
assertEquals(ASM_ACCESSION, levelOneEntity.get().getAsmAccession());
}

@Test
Expand Down
6 changes: 4 additions & 2 deletions src/test/java/uk/ac/ebi/eva/evaseqcol/io/SeqColWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ public void create() throws IOException {
extendedIntegerListDataEntitiesUcsc =
(List<SeqColExtendedDataEntity<List<Integer>>>) ucscExtendedDataMap.get("integerListExtDataList");
levelOneEntityUcsc = levelOneService.constructSeqColLevelOne(
extendedStringListDataEntitiesUcsc, extendedIntegerListDataEntitiesUcsc, SeqColEntity.NamingConvention.UCSC);
extendedStringListDataEntitiesUcsc, extendedIntegerListDataEntitiesUcsc, SeqColEntity.NamingConvention.UCSC,
assemblyEntity.getInsdcAccession());
Optional<String> resultDigestUcsc = seqColService.addFullSequenceCollection(
levelOneEntityUcsc, extendedStringListDataEntitiesUcsc, extendedIntegerListDataEntitiesUcsc);
if (resultDigestUcsc.isPresent()) {
Expand All @@ -163,7 +164,8 @@ public void create() throws IOException {
extendedIntegerListDataEntitiesGenbank = (List<SeqColExtendedDataEntity<List<Integer>>>) genbankExtendedDataMap.get("integerListExtDataList");

levelOneEntityGenbank = levelOneService.constructSeqColLevelOne(
extendedStringListDataEntitiesGenbank, extendedIntegerListDataEntitiesGenbank, SeqColEntity.NamingConvention.GENBANK);
extendedStringListDataEntitiesGenbank, extendedIntegerListDataEntitiesGenbank, SeqColEntity.NamingConvention.GENBANK,
assemblyEntity.getInsdcAccession());
Optional<String> resultDigestGenbank = seqColService.addFullSequenceCollection(
levelOneEntityGenbank, extendedStringListDataEntitiesGenbank, extendedIntegerListDataEntitiesGenbank);
if (resultDigestGenbank.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,12 @@ void constructSeqColL1Test() throws IOException {
List<SeqColExtendedDataEntity<List<Integer>>> integerListExtDataList =
(List<SeqColExtendedDataEntity<List<Integer>>>) extendedDataMapGenbank.get("integerListExtDataList");
SeqColLevelOneEntity levelOneEntity = levelOneService.constructSeqColLevelOne(
stringListExtDataList, integerListExtDataList, SeqColEntity.NamingConvention.GENBANK);
stringListExtDataList, integerListExtDataList, SeqColEntity.NamingConvention.GENBANK, assemblyEntity.getInsdcAccession());
SeqColLevelTwoEntity levelTwoEntity = levelTwoService.
constructSeqColL2(levelOneEntity.getDigest(), stringListExtDataList, integerListExtDataList);
SeqColLevelOneEntity constructedEntity = levelOneService.constructSeqColLevelOne(levelTwoEntity, SeqColEntity.NamingConvention.GENBANK);
SeqColLevelOneEntity constructedEntity = levelOneService.constructSeqColLevelOne(levelTwoEntity,
SeqColEntity.NamingConvention.GENBANK,
assemblyEntity.getInsdcAccession());
assertNotNull(constructedEntity);
assertNotNull(constructedEntity.getSeqColLevel1Object().getSequences());
}
Expand All @@ -100,7 +102,7 @@ void addSequenceCollectionL1() throws IOException {
List<SeqColExtendedDataEntity<List<Integer>>> integerListExtDataList =
(List<SeqColExtendedDataEntity<List<Integer>>>) extendedDataMapGenbank.get("integerListExtDataList");
SeqColLevelOneEntity levelOneEntity = levelOneService.constructSeqColLevelOne(
stringListExtDataList, integerListExtDataList, SeqColEntity.NamingConvention.GENBANK);
stringListExtDataList, integerListExtDataList, SeqColEntity.NamingConvention.GENBANK, assemblyEntity.getInsdcAccession());
Optional<SeqColLevelOneEntity> savedEntity = levelOneService.addSequenceCollectionL1(levelOneEntity);
assertTrue(savedEntity.isPresent());
System.out.println(savedEntity.get());
Expand Down
Loading