I am trying to modify the location of features within a GenBank file. I know `feature.type` will give gene/CDS and `feature.qualifiers` will then give "db_xref"/"locus_tag"/"inference" etc. Is there a `feature.` object which will allow me to access the location (eg: `[5240:7267](+)`) directly?

This URL give a bit more info, though I can't figure out how to use it for my purpose... http://biopython.org/DIST/docs/api/Bio.SeqFeature.SeqFeature-class.html#location_operator

Essentially, I want to modify the following bit of a GenBank file:

     gene            5240..7267
                     /db_xref="GeneID:887081"
                     /locus_tag="Rv0005"
                     /gene="gyrB"
     CDS             5240..7267
                     /locus_tag="Rv0005"
                     /inference="protein motif:PROSITE:PS00177"
                     ...........................

to

     gene            5357..7267
                     /db_xref="GeneID:887081"
                     /locus_tag="Rv0005"
                     /gene="gyrB"
     CDS             5357..7267
                     /locus_tag="Rv0005"
                     /inference="protein motif:PROSITE:PS00177"
                     .............................
             
Note the changes from **5240** to **5357**

So far I have the following python script:

    from Bio import SeqIO
    gb_file = "mtbtomod.gb"
    gb_record = SeqIO.parse(open(gb_file, "r+"), "genbank")
    rvnumber = 'Rv0005'
    newstart = 5357

    final_features = []

    for record in gb_record:
      for feature in record.features:
        if feature.type == "gene":
            if feature.qualifiers["locus_tag"][0] == rvnumber:
                if feature.location.strand == 1:
                    # Amend feature location from current to 'newstart'
                else:
                    # do the reverse for the complementary strand
        final_features.append(feature)
      record.features = final_features
      with open("test.gb","w") as test:
        SeqIO.write(record, test, "genbank")

*Rv0005* is just an example of a locus_tag I need to update. I have about 600 more locations to update per GenBank file, and about 10-20 GenBank files to process (with more to come)
Where is the question? Do you get an error message?

Well I do get one: when I do something like:

    features.location.start.position = newstart

I get an error:

    seqfeature AttributeError can't set attribute

And it doesn't matter whether the genbank file was open read-only as you did, or in writing mode.

I suppose that you need to create a new genbank file, and copy all the attributes.

**Edit 1**:

Well modifying the start is possible after all.

```
from Bio import SeqIO
from Bio import SeqFeature
start_pos = SeqFeature.AfterPosition(newstart)
end_pos = SeqFeature.BeforePosition(feature.location.end.position)
my_location = SeqFeature.FeatureLocation(start_pos, end_pos)
features = my_location
```

But that does not solve the saving problem yet.

**Edit 2**:

Useful links:

 - https://www.biostars.org/p/57549/
 - [Dealing with GenBank files in Biopython][1]
 - [Parsing Genbank files with Biopython][2]

 [1]: http://www2.warwick.ac.uk/fac/sci/moac/people/students/peter_cock/python/genbank/
 [2]: http://wilke.openwetware.org/Parsing_Genbank_files_with_Biopython.html