Skip to content

Commit

Permalink
Merge pull request #46 from waterflow80/fix-issue-45
Browse files Browse the repository at this point in the history
Fixed the digits verification for seqCol arrays to be digested - ingestion endpoint
  • Loading branch information
waterflow80 authored Aug 31, 2023
2 parents 3484340 + 04d9605 commit c7b9ebc
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public ResponseEntity<?> fetchAndInsertSeqColByAssemblyAccession(
return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST);
}
catch (IOException e) {
e.printStackTrace();
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
} catch (DuplicateSeqColException e) {
return new ResponseEntity<>(e.getMessage(), HttpStatus.CONFLICT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public Optional<AssemblySequenceEntity> getAssemblySequencesByAccession(String a
Files.deleteIfExists(downloadFilePath.get());
Files.deleteIfExists(compressedFilePath.get()); // Deleting the fasta file
} catch (IOException e) {
//e.printStackTrace(); // We might want to uncomment this when debugging
logger.warn("Error while trying to disconnect - ncbiBrowser (assembly: " + accession + ")");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public Optional<Map<String, List<SeqColExtendedDataEntity>>> getAllPossibleSeqCo
logger.error("Could not fetch Sequences FASTA file from NCBI for assembly accession: " + accession);
return Optional.empty();
}
logger.info("Assembly report and FASTA file have been fetched and parsed successfully");
seqColResultData.put(
"sameValueAttributes",
SeqColExtendedDataEntity.constructSameValueExtendedSeqColData(assemblyEntity.get(), sequenceEntity.get()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public boolean downloadFTPFile(String ftpFilePath, Path downloadFilePath, long f
super.setFileTransferMode(FTP.BINARY_FILE_TYPE);
Files.deleteIfExists(downloadFilePath);

logger.info("Downloading file " + ftpFilePath + " in progress...");
boolean success = super.retrieveFile(ftpFilePath, new FileOutputStream(downloadFilePath.toFile()));

if (success && Files.exists(downloadFilePath) && Files.isReadable(downloadFilePath)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,13 +367,20 @@ private boolean onlyDigits(String str) {
return m.matches();
}

/**
* Check whether the given list contains only digits (in a form of strings)*/
private boolean onlyDigitsStringList(List<String> list) {
return list.isEmpty() || list.stream()
.allMatch(this::onlyDigits);
}

/**
* Return a normalized string representation of the given seqColL2Attribute
* Note: This is the same method as the toString of the JSONExtData class*/
private String convertSeqColLevelTwoAttributeValuesToString(List<String> seqColL2Attribute) {
StringBuilder objectStr = new StringBuilder();
objectStr.append("[");
if (onlyDigits(seqColL2Attribute.get(0).toString())) { // Lengths array, No quotes "...". Eg: [1111, 222, 333]
if (onlyDigitsStringList(seqColL2Attribute)) { // Lengths array, No quotes "...". Eg: [1111, 222, 333]
for (int i=0; i<seqColL2Attribute.size()-1; i++) {
objectStr.append(seqColL2Attribute.get(i));
objectStr.append(",");
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/uk/ac/ebi/eva/evaseqcol/utils/JSONExtData.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,18 @@ private boolean onlyDigits(String str) {
return m.matches();
}

/**
* Check whether the given list contains only digits (in a form of strings)*/
private boolean onlyDigitsStringList(List<String> list) {
return list.isEmpty() || list.stream()
.allMatch(this::onlyDigits);
}

@Override
public String toString() {
StringBuilder objectStr = new StringBuilder();
objectStr.append("[");
if (onlyDigits(object.get(0).toString())) { // Lengths array, No quotes "...". Eg: [1111, 222, 333]
if (onlyDigitsStringList(object)) { // Lengths array, No quotes "...". Eg: [1111, 222, 333]
for (int i=0; i<object.size()-1; i++) {
objectStr.append(object.get(i));
objectStr.append(",");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class DigestCalculatorTest {
private final String ARRAY_TEST = "[248956422, 242193529, 198295559]";
private final String ARRAY_DIGEST = "5K4odB173rjao1Cnbk5BnvLt9V7aPAa2";

private final String sequences_array = "[\"MD5-sqdfsdodshijfsd354768\",\"MD5-fjroptkgqsdfsd5f7sdlp\",\"MD5-sdpohgnjkisqdj,fiokjz\"]";

@BeforeEach
void setUp() {
Expand All @@ -37,7 +38,9 @@ void setUp() {
void getDigest() throws IOException {
String res1 = digestCalculator.getSha512Digest(levelOneEntity.toString());
String res2 = digestCalculator.getSha512Digest(ARRAY_TEST);
String res3 = digestCalculator.getSha512Digest(sequences_array);
assertEquals(DIGEST, res1);
assertEquals(ARRAY_DIGEST, res2);
assertEquals("J8ovDQ2uLIxaOIQvDEQeGf4d5Yp5QJV-", res3);
}
}

0 comments on commit c7b9ebc

Please sign in to comment.