Skip to content

Fix read_pdb_from_list for lines without trailing newlines - #165

Open
raashish1601 wants to merge 1 commit into
BioPandas:mainfrom
raashish1601:fix/130-read-pdb-from-list-newlines
Open

raashish1601 wants to merge 1 commit into
BioPandas:mainfrom
raashish1601:fix/130-read-pdb-from-list-newlines

Conversation

@raashish1601

Copy link
Copy Markdown
Contributor

Code of Conduct

OK

Description

read_pdb_from_list() joined the lines with "", so lines without a trailing newline (for example from pdb_text.split("\n"), as in the issue) gave a pdb_text that is one long line. There was a second, quieter problem: _construct_df used line[6:-1] for OTHERS entries to strip the newline, so without it the last real character was dropped. With lines that are not padded to 80 columns, the HEADER entry lost its last character and code came back as 3ei instead of 3eiy.

Changes:

  • read_pdb_from_list() adds the missing newlines when building pdb_text and then parses pdb_text.splitlines(True), the same as read_pdb(). Lists from readlines()/splitlines(True) give the same result as before.
  • _construct_df uses line[6:].rstrip(), which still removes the newline but keeps the last character when there is none.

Related issues or pull requests

Fixes #130

Pull Request Checklist

  • Added a note about the modification or contribution to the ./docs/sources/CHANGELOG.md file (if applicable)
  • Added appropriate unit test functions in the ./biopandas/*/tests directories (if applicable)
  • Modify documentation in the corresponding Jupyter Notebook under biopandas/docs/sources/ (if applicable)
  • Ran PYTHONPATH='.' pytest ./biopandas -sv and make sure that all unit tests pass (for small modifications, it might be sufficient to only run the specific test file, e.g., PYTHONPATH='.' pytest ./biopandas/classifier/tests/test_stacking_cv_classifier.py -sv)
  • Checked for style issues by running flake8 ./biopandas

The new test test_read_pdb_from_list_without_newlines fails on main and passes with the fix. The full tests/ suite passes locally, and flake8 reports nothing new on the changed lines. The changelog entry is in docs/CHANGELOG.md, which is where the current one lives. No notebook changes were needed.

This branch has not been deployed

No deployments
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.

read_pdb_from_list() not containing newlines

1 participant