Repository: biopython/biopython

Issue:
Bio.SeqIO: AttributeError when parsing GenBank file
### Setup

I am reporting a problem with Biopython version, Python version, and operating
system as follows:

```text
3.10.10 (main, Feb  8 2023, 00:00:00) [GCC 13.0.1 20230208 (Red Hat 13.0.1-0)]
CPython
Linux-6.2.9-300.fc38.x86_64-x86_64-with-glibc2.37
1.81
```

### Steps to reproduce

```python
import urllib.request
from io import StringIO
from Bio import SeqIO

# download file
gbk_content = urllib.request.urlopen('https://cloud.bioinformatics.unibe.ch/index.php/s/eD7ycWjz6p628C3/download/assembly.phages_combined.gbk').read().decode()

# try to parse file
for seq_record in SeqIO.parse(StringIO(gbk_content), "genbank"):
    pass
```

### Expected behaviour

GenBank file is parsed normally.

### Actual behaviour

```text
Traceback (most recent call last):
  File "/opt/JetBrains/apps/PyCharm-P/ch-0/231.8109.197/plugins/python/helpers/pydev/pydevconsole.py", line 364, in runcode
    coro = func()
  File "<input>", line 1, in <module>
  File "/home/username/PycharmProjects/venvs/vibr_annotate/lib64/python3.10/site-packages/Bio/SeqIO/Interfaces.py", line 72, in __next__
    return next(self.records)
  File "/home/username/PycharmProjects/venvs/vibr_annotate/lib64/python3.10/site-packages/Bio/GenBank/Scanner.py", line 516, in parse_records
    record = self.parse(handle, do_features)
  File "/home/username/PycharmProjects/venvs/vibr_annotate/lib64/python3.10/site-packages/Bio/GenBank/Scanner.py", line 499, in parse
    if self.feed(handle, consumer, do_features):
  File "/home/username/PycharmProjects/venvs/vibr_annotate/lib64/python3.10/site-packages/Bio/GenBank/Scanner.py", line 470, in feed
    self._feed_feature_table(consumer, self.parse_features(skip=False))
  File "/home/username/PycharmProjects/venvs/vibr_annotate/lib64/python3.10/site-packages/Bio/GenBank/Scanner.py", line 420, in _feed_feature_table
    consumer.location(location_string)
  File "/home/username/PycharmProjects/venvs/vibr_annotate/lib64/python3.10/site-packages/Bio/GenBank/__init__.py", line 727, in location
    location = Location.fromstring(location_line, length, is_circular, stranded)
  File "/home/username/PycharmProjects/venvs/vibr_annotate/lib64/python3.10/site-packages/Bio/SeqFeature.py", line 859, in fromstring
    loc.strand = strand
AttributeError: 'NoneType' object has no attribute 'strand'
import sys; print(sys.version)
import platform; print(platform.python_implementation()); print(platform.platform())
import Bio; print(Bio.__version__)
3.10.10 (main, Feb  8 2023, 00:00:00) [GCC 13.0.1 20230208 (Red Hat 13.0.1-0)]
CPython
Linux-6.2.9-300.fc38.x86_64-x86_64-with-glibc2.37
1.81
```

### Workaround

Downgrade biopython from `1.81` to `1.79`. (`1.80` has the same bug.)

### More info

The ugly .gbk file was generated by [VIBRANT 1.2.1](https://github.com/AnantharamanLab/VIBRANT).



Discussion:
This breaks on the current code too, so the current release Biopython 1.81 would be affected too. The problem is a very messed up first feature:

```
LOCUS       scaffold_0_fragment_5                 35432 bp    DNA     linear   VRL 2023-04-03
DEFINITION  scaffold_0_fragment_5.
COMMENT     Annotated using VIBRANT v1.2.1
FEATURES             Location/Qualifiers
     source          /organism="scaffold_0_fragment_5"
     CDS             1..684
                     /locus_tag="scaffold_0_fragment_5_145"
                     /protein_id="PF07553.11"
                     /product="Host cell surface-exposed lipoprotein"
                     /translation="MQQERQSWYQKSWFIILTLLFIFPLGLFLMWRYAHWKNWLKLIV
                     SSVYIISLVLILLFQVSLLNENKTNQIEHASTMKEKSNINNVKTTKNKNIEKSTQTDK
                     QNSVNLKQNTKDQNNNANDEETSTTSEQNVAIAQAKSYANTLPISKKSLYKQLTSEYG
                     EKYPADVAQYAVDHISVDYKMNALRLAKSYVKNINISNQALYDQLVSENGEGFTPEEA
                     QYAINHLDR*"
...
```

This should probably be:

```
LOCUS       scaffold_0_fragment_5                 35432 bp    DNA     linear   VRL 2023-04-03
DEFINITION  scaffold_0_fragment_5.
COMMENT     Annotated using VIBRANT v1.2.1
FEATURES             Location/Qualifiers
     source          1..35432
                     /organism="scaffold_0_fragment_5"
     CDS             1..684
                     /locus_tag="scaffold_0_fragment_5_145"
                     /protein_id="PF07553.11"
                     /product="Host cell surface-exposed lipoprotein"
                     /translation="MQQERQSWYQKSWFIILTLLFIFPLGLFLMWRYAHWKNWLKLIV
                     SSVYIISLVLILLFQVSLLNENKTNQIEHASTMKEKSNINNVKTTKNKNIEKSTQTDK
                     QNSVNLKQNTKDQNNNANDEETSTTSEQNVAIAQAKSYANTLPISKKSLYKQLTSEYG
                     EKYPADVAQYAVDHISVDYKMNALRLAKSYVKNINISNQALYDQLVSENGEGFTPEEA
                     QYAINHLDR*"...
```

With Biopython 1.79 this gave a warning, ``BiopythonParserWarning: Couldn't parse feature location: '/organism="scaffold_0_fragment_5"'``, and continued - with lots more warnings.



Resolving patch:
diff --git a/Bio/SeqFeature.py b/Bio/SeqFeature.py
--- a/Bio/SeqFeature.py
+++ b/Bio/SeqFeature.py
@@ -1077,7 +1077,7 @@ def fromstring(text, length=None, circular=False):
             ref = None
         m = _re_location_category.match(text)
         if m is None:
-            return None
+            raise LocationParserError(f"Could not parse feature location '{text}'")
         for key, value in m.groupdict().items():
             if value is not None:
                 break


Test patch: