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

Fixed the digits verification for seqCol arrays to be digested - ingestion endpoint #46

Merged
merged 1 commit into from
Aug 31, 2023
Merged
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 @@ -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);
}
}