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

Smiles import minor adaptions #13

Merged
merged 5 commits into from
Feb 22, 2024
Merged

Conversation

SamuelBehr
Copy link
Collaborator

Minor adaptions to the SMILES import: If no name for a structure is detected, the file name extended with the index of the line containing the SMILES code in the file (formerly extended with the count of so far parsed SMILES) is assigned as name to the structure; detected "invalid" lines are now being logged with their index in the file; the ParsableLinesCount and InvalidLinesCount are now only logged if "invalid" lines were encountered; added hyphen ("|") as possible SMILES file separator;

What do you two think of these changes?

Please review!

…etected, the file name extended with the index of the line containing the SMILES code in the file (formerly extended with the count of so far parsed SMILES) is assigned as name to the structure; the ParsableLinesCount and InvalidLinesCount are now only logged if "invalid" lines were encountered;
} catch (InvalidSmilesException | IndexOutOfBoundsException anException) {
//case: invalid line or SMILES code
//tmpContainsParsableSmilesCode stays false
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty catch block?

Copy link
Collaborator Author

@SamuelBehr SamuelBehr Aug 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I see, I probably shouldn't do that. Would you prefer this here? :

            boolean tmpContainsParsableSmilesCode;    //removed the initialization
            try {
                tmpProcessedLineArray = tmpSmilesFileNextLine.split(tmpSmilesFileDeterminedSeparator, 2);
                if (!tmpProcessedLineArray[tmpSmilesCodeExpectedPosition].isEmpty()) {
                    tmpMolecule = tmpSmilesParser.parseSmiles(tmpProcessedLineArray[tmpSmilesCodeExpectedPosition]);
                    tmpContainsParsableSmilesCode = true;
                    tmpSmilesFileParsableLinesCounter++;
                } else {
                    tmpContainsParsableSmilesCode = false;    //new
                }
            } catch (InvalidSmilesException | IndexOutOfBoundsException anException) {
                //case: invalid line or SMILES code
                tmpContainsParsableSmilesCode = false;       //new
            }

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the confusion comes from the expected SMILES position being empty (no exception) and the SMILES code being unparseable (exception) leading to the same code block which comes below. But yes, it is safer and more straightforward to understand to set these boolean values explicitly again in both cases, I'd say.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That causes the confusion.
Anyway, I find it a bit unusual to place the logging outside the catch block. Why not like this and get rid of the Boolean:

try {
     tmpProcessedLineArray = tmpSmilesFileNextLine.split(tmpSmilesFileDeterminedSeparator, 2);
     String tmpSmiles = tmpProcessedLineArray[tmpSmilesCodeExpectedPosition].isBlank() ? null : 
                                     tmpProcessedLineArray[tmpSmilesCodeExpectedPosition];
     tmpMolecule = tmpSmilesParser.parseSmiles(tmpSmiles);
     tmpSmilesFileParsableLinesCounter++;
 }
catch (InvalidSmilesException | IndexOutOfBoundsException anException) {
     int tmpIndexInFile = tmpSmilesFileParsableLinesCounter + tmpSmilesFileInvalidLinesCounter;
     Importer.LOGGER.info("Contains no parsable SMILES string: line " + tmpIndexInFile + " (index).");
     tmpSmilesFileInvalidLinesCounter++;
     continue;
}

This should cause an InvalidSmilesException if position in the file is blank or null.

Copy link
Owner

@FelixBaensch FelixBaensch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 4 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@JonasSchaub JonasSchaub changed the base branch from main to production February 21, 2024 15:25
Copy link

Quality Gate Passed Quality Gate passed

Issues
2 New issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@JonasSchaub
Copy link
Collaborator

@FelixBaensch I've made the changes you requested. Please review again (merging is blocked otherwise). Thank you!

@JonasSchaub JonasSchaub merged commit 740f4f1 into production Feb 22, 2024
2 checks passed
@JonasSchaub JonasSchaub deleted the SMILES_Import_minor_adaptions branch February 22, 2024 09:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants