Skip to content

New restriction analysis library, v2 - #268

Closed
anntzer wants to merge 2 commits into
biopython:masterfrom
anntzer:restriction2
Closed

anntzer wants to merge 2 commits into
biopython:masterfrom
anntzer:restriction2

Conversation

@anntzer

@anntzer anntzer commented Dec 5, 2013

Copy link
Copy Markdown
Contributor

This supersedes #148. I created a new branch so that the emboss db doesn't appear in the history (and also to restart from the current master). Now, importing the library will have the side-effect of dowloading the db. Note, though, that setup.py may need to be modified so that the db is present before biopython is written to a directory owned by root (probably just an import is enough, but untested).
I also got rid of the custom Seq class, now I just rely on the standard Seq and pass circular as a kwarg.
Finally, I removed the patch for the old restriction library as it doesn't seem to apply cleanly and I have little interest in figuring out why -- but you can still get it from #148 and give it a try.

@merenlin

merenlin commented Jun 3, 2014

Copy link
Copy Markdown

Hi guys, any news on when the new version will be incorporated in the official biopython? how stable is this version? Do you need help in testing it?

@peterjc

peterjc commented Jun 3, 2014

Copy link
Copy Markdown
Member

Having someone else test this and give feedback would be really helpful. Would you need any help with that @OxanaSachenkova - e.g. how to get this code installed? You'd need to checkout this branch using git and install Biopython from source. Feel free to ask about that on the Biopython development mailing list, so we can keep this pull request focussed on the code changes. Thanks!

@llrs

llrs commented Jun 7, 2014

Copy link
Copy Markdown

It could be possible to add the result of two (or more) restriction enzyme combinations?
This way it would help when wanting to select an specific fragment or when you just have two enzymes and want to compare the lab results (bands of weight) with the theoretical result. If it returned instead of different list just one list with both indexes I think it would be helpful. BTW If I can help on these module let me know

@anntzer

anntzer commented Jun 8, 2014

Copy link
Copy Markdown
Contributor Author

Analyses are just mappings of enzymes to lists of cut points, so they can be merged by

for k, v in d2.items(): d1.setdefault(k, []).extend(v)

@mwbudde

mwbudde commented Aug 7, 2014

Copy link
Copy Markdown

I'm not really qualified to help with this project, butI do use the restriction module frequently and have a few questions.

1 - Is it possible to add restriction enzymes? I'd like to add some homing endonucleases from NEB (i.e. http://rebase.neb.com/rebase/enz/I-SceI.html), but they don't seem to import with the regular restriction enzymes.

2 - If the restriction module is being updated, will it be possible to pass restriction names in as parameters? Currently you have to import each enzyme, which doesn't seem very pythonic. For instance, if I have a list of restriction enzymes that I want to use in my script, I currently have to use and exec statement, which feels weird. Has there been any thought to adding a function that could be used instead, such as Restriction.cut('EcoRI', seqrecord)?

@peterjc

peterjc commented Nov 13, 2014

Copy link
Copy Markdown
Member

I think @mwbudde raised some good points. On a more technical level, here are my thoughts on an initial code-review.

The new Seq class remains a problem (noted on the original PR) due to confusion with Bio.Seq

We're trying to use PEP8 compliant names for new modules (lower case), however due to the pre-existence of Bio.Restriction (which this would replace in the long term) we can't use Bio.restriction (it would break on case insensitive file systems). I suggest Bio.digest could work?

Furthermore you could rename Bio/Restriction2/Restriction.py --> Bio/digest/__init__.py (shorter imports) and since it only deals with REBASE, rename Bio/Restriction2/RestrictionDB.py --> Bio/digest/rebase.py maybe?

Rather than defining variables _codes and _complement use ambiguous_dna_values and ambiguous_dna_complement from Bio.Data.IUPACData.

In the REBASE code, you cannot use os.path.dirname(__file__) for storing the (EMBOSS format) REBASE files as this will typically be a system owned path where the user will not have write access. Instead use the same approach as Bio/Entrez/Parser.py for its DTD files (see code for local_dtd_dir) under the user's home directory.

I'm not entirely comfortable with import the module automatically (and silently) trying to download the REBASE files...

Crucially, there are no examples (or unit tests which we would need but can come later). How do I actually create an instance of a specific restriction enzyme, e.g. EcoRI, and then cut a sequence?

@peterjc

peterjc commented Nov 13, 2014

Copy link
Copy Markdown
Member

Also the new module needs to be added to setup.py to actually install it.

I had a little play with some of this on a personal branch https://github.com/peterjc/biopython/tree/digest but got stuck actually trying to use the code :(

@anntzer

anntzer commented Nov 13, 2014

Copy link
Copy Markdown
Contributor Author

I have stopped using biopython so won't do additional work on this PR, but am happy to share my thoughts.

Re: Adding new enzymes
The Restriction constructor can be called directly, e.g.

Restriction.all["I-SceI"] = Restriction(
    "I-SceI", # name
    "TAGGGATAACAGGGTAAT", # recongnized sequence
    [(9, 5)], # position of cuts on top and bottom strand
    [] # methylation sites,
    "") # one-letter codes for vendors

Arguably, this could be made slightly easier with a register classmethod that would save the enzyme in all and keep the methylation and vendor arguments optional.

Re: Using restriction names (a very good idea): the analyze function could easily be modified to take either a list of enzymes or of enzyme names as second argument, e.g.

enzymes = [Restriction.all[enzyme] if isinstance(enzyme, str) else enzyme for enzyme in enzymes]

Re: The Seq class: AFAICT I have removed the new Seq class (thus the reliance on an analyze function that takes a Seq and a list of enzymes as argument, rather than a method). So a typical use would be

seq = Seq(...)
Restriction.analyze(seq, [EcoRI, XhoI, ...]) # returns a mapping of enzyme names to cut sites.

or, for a single enzyme,

seq = Seq(...)
EcoRI.search(seq)

Re: Module name: A good idea, the current design basically came from the old Restriction package.

Re: _codes and _complement: Feel free to fix this.

Re: REBASE and autoloading: Yes, this is a poor design. The intent was that ensure_db only be called via setup.py at build time. The data can be stored either under the user home directory, or as package data (like matplotlib's mpl-data).

I don't really intend to write more code on that but let me know if I can be of additional help.

@peterjc

peterjc commented Nov 13, 2014

Copy link
Copy Markdown
Member

Thanks for those comments @anntzer - more food for thought :)

@vincentdavis

Copy link
Copy Markdown
Contributor

@peterjc looked through these comments and the #148. It seems the plan is to build a new restriction library and deprecate the old in the future? What are the goals for rewriting?

@peterjc

peterjc commented Oct 12, 2016

Copy link
Copy Markdown
Member

Multiple: Avoid the legal grey area about the REBASE files by downloading them either at install time or usage. Avoid what where with hindsight poor design choices in current implementation (overly complex implementation with classes for every enzyme which also hampers auto-generated documentation, and use of one-based counting rather than Python counting).

@mdehoon

mdehoon commented Aug 22, 2023

Copy link
Copy Markdown
Contributor

It would be nice to get this into the next Biopython release.

@peterjc

peterjc commented Aug 22, 2023

Copy link
Copy Markdown
Member

Replacing the restriction digest module is a worthy goal.

However, I feel Biopython 1.82 is already over due but ready to release - so wouldn't want to delay it any more.

@peterjc

peterjc commented Aug 22, 2023

Copy link
Copy Markdown
Member

Note sure wny there is a git merge conflict.

Relatively minor things: I'd change this to use PEP8 lower case module names, perhaps Bio.digest rather than a lower case version of Bio.Restriction2, and apply black. I would also be inclined to move the main class into the __init__.py file for easier end-user imports. And we can probably import the IUPAC ambiguity codes from Bio.Data rather then redefining them here.

More importantly, it would need some unit tests - the old module's ought to be a good guide.

@anntzer

anntzer commented Aug 22, 2023

Copy link
Copy Markdown
Contributor Author

I'll close this as I have little interest in reviving a 9y old PR; feel free to take over the code as desired.

@anntzer anntzer closed this Aug 22, 2023
@anntzer
anntzer deleted the restriction2 branch August 22, 2023 15:10
@peterjc

peterjc commented Aug 22, 2023

Copy link
Copy Markdown
Member

Thank you @anntzer - while we have your attention, in case we do eventually use this or something based on it, would you agree to dual licence this code under both the Biopython License Agreement and the 3-clause BSD license - see #898 - thanks!

@anntzer

anntzer commented Aug 22, 2023

Copy link
Copy Markdown
Contributor Author

Yes, I do agree.

@peterjc

peterjc commented Aug 23, 2023

Copy link
Copy Markdown
Member

Thank you!

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.

7 participants