Developer / Tutorials / Python

Update strain genotypes example

Last updated on 22-Dec-2020 by Troels Bagge Angelo
Troels Bagge Angelo

Student Developer
, Jakob Jakobsen Boysen
Jakob Jakobsen Boysen

Platform Lead

This document is an example of how you can use the Python interaction to edit your strain genotypes.

First we need to find the data of interest, this is done as explained in Interacting with python:


We add domain, username and password first

Then a token is generated


Dataset query is now used to access the strain SR124848 with genotypes:

Querying more than one set of data

If you need to extract more strains. You can use a list with the given strain names together with an empty list for rdata and files:

Files will be a dictionary or a list of dictionaries containing the entities for the given strain. This can easiely be displayed using the function:

Data manipulation examples:

Several different things can now be done to edit the data:

  1. Editing
  2. Deleting
  3. Adding

In all three cases. The string under the key strain.genotype will get "Edited" added on to the end, to help indicate that the strain has been modified. This is not strictly necessary and can be deleted.


When editing in genotypes, the function genotypeEditor can be used. It takes two values: oldvalue & newvalue. oldvalue is the value you want to update, if it is a gene "lacI" could be and example. newvalue is the value you want to replace it with.

The editor function is as follows:

The editing is not specific for genes, but can be used on any key in genotypeChanges. It will edit all genotypeChanges with the matching value.


When deleting, the following function is used. It takes the value genedeleted: genedeleted is refering to the gene that you want to removed from genotypeChanges.

This function only works on genes in genotypeChanges, it can be edited to work on other keys just change d['gene'].

Be aware that this function doesn't actually delete the genotype from the strain, but just adds a key "Deletion" with the value "true" and DELETED under the description of the genotype.


The following functions are used for adding a new genotype

When adding a new genotype the function is run as shown below, for the given genotypeChanges:

The new genotype will be added as a new dictionary under genotypeChanges at the end of the list. This new dictionary will only contain the key "gene" and "description". If more keys needs to be added this can be done under the geneeditor function by writing:


Now that the genotype has been edited it can be reuploaded:

The strain and genotypes should now be updated in your Scifeon domain.

If you have added a new genotypeChange the keys that you haven't filled in.

If you are making multiple updates, you can add a loop over parameters and requests.requests:

#Further editing This tutorial is aiming at giving a rough introduction to how editing of data can be done in Python. Be aware that dataupload of parameters needs to follow the JSON format strictly. The jprint function can be used debug issues on format.