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

Remove deprecated manipulation2 #1208

Merged
merged 15 commits into from
Apr 29, 2022

Conversation

akaviaLab
Copy link
Contributor

  • fix Remove unused functions from manipulation module #530
  • description of feature/fix
    Removed deprecated manipulation functions including undelete_model_genes, get_compiled_gene_reaction_rules, find_gene_knockout_reactions
    Removed related functions from test_delete.py
    Removed trimmed field from model
    Added knock_out_model_genes()
  • tests modified
    Modified test_delete_genes to perform the same tests with the new functions.
  • [X} add an entry to the next release

This is a cleaner version of #1200

One decision that needs to be made is about `knock_out_model_genes() which is a simple helper function for people who want to knock out lots of genes, and aren't good with writing the list comprehension on their own.

Copy link
Member

@Midnighter Midnighter left a comment

Choose a reason for hiding this comment

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

Some minor suggestions, otherwise this looks good. I think the knock_out_model_genes function makes sense as it conveniently returns the list of affected reactions. I'm not super happy with the name but it's descriptive and I don't have a better suggestion. Good work 👍🏼

Comment on lines 92 to 100
new_bounds = model.reactions.list_attr("bounds")
reaction_list = list()
for i, rxn in enumerate(model.reactions):
if not (
np.isclose(orig_bounds[i][0], new_bounds[i][0])
and np.isclose(orig_bounds[i][1], new_bounds[i][1])
):
reaction_list.append(rxn)
return reaction_list
Copy link
Member

Choose a reason for hiding this comment

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

Even though it increases the computational work, I think a version more in line with the object-oriented design is:

Suggested change
new_bounds = model.reactions.list_attr("bounds")
reaction_list = list()
for i, rxn in enumerate(model.reactions):
if not (
np.isclose(orig_bounds[i][0], new_bounds[i][0])
and np.isclose(orig_bounds[i][1], new_bounds[i][1])
):
reaction_list.append(rxn)
return reaction_list
return [rxn for rxn in itertools.chain.from_iterable((gene.reactions for gene in gene_list)) if not rxn.functional]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why are there two parenthesis?

Copy link
Contributor Author

@akaviaLab akaviaLab Apr 27, 2022

Choose a reason for hiding this comment

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

Also, why set? In the get_by_any above?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure gene.reactions as written would work, since it can accept strings

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pushed a version with list comprehension that works. You can pick if the most recent one [
24cbb5e] makes sense , or 66d0428 makes more sense.

Copy link
Member

Choose a reason for hiding this comment

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

Double parenthesis was outer for the function call and the inner for a generator statement. This was assuming that gene_list would be the output of get_by_any, sorry, my comment wasn't clear.

I used a set to avoid duplicates which are in principle possible with a list and get_by_any.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

for gene in model.genes.get_by_any(set(gene_list)): fails due to type error

  return the_id in self._dict

E TypeError: unhashable type: 'set'

../manipulation/delete.py:86: in knock_out_model_genes
for gene in model.genes.get_by_any(set(gene_list)):
../core/dictlist.py:108: in get_by_any
return [get_item(item) for item in iterable]
../core/dictlist.py:108: in
return [get_item(item) for item in iterable]
../core/dictlist.py:101: in get_item
../core/dictlist.py:379: TypeError

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the current version [https://github.com//pull/1208/commits/ae1fdbe5beea58cc453253111914a1bd27e7b750] is the best, and object-oriented. Fixed other comments.

src/cobra/manipulation/delete.py Outdated Show resolved Hide resolved
src/cobra/manipulation/delete.py Outdated Show resolved Hide resolved
src/cobra/manipulation/delete.py Outdated Show resolved Hide resolved
src/cobra/manipulation/delete.py Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented Apr 27, 2022

Codecov Report

Merging #1208 (705c278) into devel (f5a1b96) will decrease coverage by 0.60%.
The diff coverage is 78.57%.

❗ Current head 705c278 differs from pull request most recent head 3ef855d. Consider uploading reports for the commit 3ef855d to get more accurate results

@@            Coverage Diff             @@
##            devel    #1208      +/-   ##
==========================================
- Coverage   84.23%   83.62%   -0.61%     
==========================================
  Files          65       65              
  Lines        5549     5497      -52     
  Branches     1287     1263      -24     
==========================================
- Hits         4674     4597      -77     
- Misses        564      598      +34     
+ Partials      311      302       -9     
Impacted Files Coverage Δ
src/cobra/core/model.py 87.80% <ø> (-0.07%) ⬇️
src/cobra/manipulation/__init__.py 100.00% <ø> (ø)
src/cobra/manipulation/delete.py 93.50% <76.92%> (+10.44%) ⬆️
src/cobra/core/gene.py 81.15% <100.00%> (+0.61%) ⬆️
src/cobra/util/process_pool.py 39.53% <0.00%> (-27.91%) ⬇️
src/cobra/sampling/optgp.py 75.38% <0.00%> (-16.93%) ⬇️
src/cobra/sampling/core.py 78.78% <0.00%> (-15.16%) ⬇️
src/cobra/flux_analysis/deletion.py 82.45% <0.00%> (-7.02%) ⬇️
src/cobra/flux_analysis/variability.py 85.41% <0.00%> (-5.21%) ⬇️
src/cobra/io/sbml.py 80.21% <0.00%> (-0.24%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f5a1b96...3ef855d. Read the comment docs.

Copy link
Contributor Author

@akaviaLab akaviaLab left a comment

Choose a reason for hiding this comment

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

One question about the list comprehension left

Comment on lines 92 to 100
new_bounds = model.reactions.list_attr("bounds")
reaction_list = list()
for i, rxn in enumerate(model.reactions):
if not (
np.isclose(orig_bounds[i][0], new_bounds[i][0])
and np.isclose(orig_bounds[i][1], new_bounds[i][1])
):
reaction_list.append(rxn)
return reaction_list
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why are there two parenthesis?

@akaviaLab akaviaLab mentioned this pull request Apr 27, 2022
4 tasks
Added tests to make sure that int and cobra.Gene will work as well
@akaviaLab akaviaLab mentioned this pull request Apr 28, 2022
3 tasks
@akaviaLab akaviaLab closed this Apr 28, 2022
@akaviaLab akaviaLab reopened this Apr 28, 2022
@Midnighter Midnighter merged commit b628572 into opencobra:devel Apr 29, 2022
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