---
# System prepended metadata

title: Electronic Traineeship Notebook
tags: [kevin-depelseneer, ' ETN', ' TDP']

---

---
title: "Electronic Traineeship Notebook"
author: "Kevin De Pelseneer"
tags: kevin-depelseneer, ETN, TDP
---

# Electronic Traineeship Notebook

## Traineeship Documentation Plan

The definitive version of the TDP can be found on the BIT sharepoint in folder _"2. Concept of TDP"_.

### Tentative Planning

> - Which tasks will be performed during the traineeship (briefly)?
> - When do you foresee to perform these tasks?

#### Time schedule


| Week nÂ° | Dates                   | Hours | Cumulative hours | info                                           |
| ------- | ----------------------- | ----- | ---------------- | ---------------------------------------------- |
| 40      | 27/09/2021 - 01/10/2021 | 40    | 40               | Start internship                               |
| 41      | 04/10/2021 - 08/10/2021 | 40    | 80               |                                                |
| 42      | 15/10/2021              | 8     | 88               |                                                |
| 43      | 22/10/2021              | 8     | 96               |                                                |
| 44      | 26/10/2021              | 8     | 104              |                                                |
| 45      | 05/11/2021              | 8     | 112              |                                                |
| 46      | 08/11/2021              | 8     | 120              |                                                |
| 47      | 19/11/2021              | 8     | 128              |                                                |
| 48      | 26/1/2021               | 8     | 136              |                                                |
| 49      | 03/12/2021              | 8     | 144              |                                                |
| 50      | 07/12/2021              | 8     | 152              |                                                |
| 51      | 13/12/2021              | 8     | 160              |                                                |
| 52      | 20/12/2021              | 8     | 168              |                                                |
| 1       | 07/01/2022              | 8     | 176              |                                                |
| 2       | 14/01/2022              | 8     | 184              |                                                |
| 3       | 18/01/2022              | 8     | 192              |                                                |
| 4       | 24/01/2022              | 8     | 200              |                                                |
| 5       | 31/01/2022              | 8     | 208              |                                                |
| 6       | 07/02/2022              | 8     | 216              |                                                |
| 7       | 14/02/2022              | 8     | 224              |                                                |
| 8       | 21/02/2022              | 8     | 232              |                                                |
| 9       | 04/03/2022              | 8     | 240              | Demo of the application to the Eyckerman group |
| 10      | 07/03/2022              | 8     | 248              |                                                |
| 11      | 17/03/2022              | 8     | 256              |                                                |
| 12      | 24/03/2022              | 4     | 260              |                                                |
| 13      | 25/03/2022              | 4     | 264              |                                                |
| 14      | 28/03/2022              | 8     | 272              |                                                |
| 15      | 04/04/2022              | 8     | 280              |                                                |
| 16      | 11/04/2022              | 8     | 288              |                                                |
| 17      | 19/04/2022              | 8     | 296              |                                                |
| 18      | 25/04/2022              | 8     | 304              | End of traineeship and                         |

#### Project Management
Topic	Deadline	Status
Brainstorming on the application		Completed
Design a mock-up for the UI + presentation		Completed
Make a Software Requirement Document and Software Design Document		Ongoing
Try out different frameworks for the UI		Ongoing
		
		
		2021-Nov-12: Finilise first draft of SDD (+ 1 week)
2021-Dec-10: Initial Demo with Sven and Delphine (+ 4 days)
2021-Dec-13: Mid-project review meeting



| Topic                                                             | Deadline   | Status    |
| ----------------------------------------------------------------- | ---------- | --------- |
| Brainstorming on the application                                  | 01/10/2021 | Completed |
| Design a mock-up for the UI + presentation                        | 07/10/2021 | Completed |
| Make a Software Requirement Document and Software Design Document | 12/11/2021 | Completed |
| Try out different frameworks for the UI                           | 12/11/2021 | Completed |
| Demo with Sven and Delphine                                       | 04/03/2022 | Completed |


#### Deadlines


| Week nÂ° | Date                | Info                                                                                                       |
| -------- | ------------------- | ---------------------------------------------------------------------------------------------------------- |
| After 41 | 18/10/2021          | First meeting after 76 h. Submiting the concept of the learning outcome. Submitting the concept of the TDP |
| After 50 | 13/12/2021          | traineship visit 1 halfway traineeship after 150 h                                                         |
| After 17 | Week of  25/04/2022 | Traineeship 2 - End of traineeship                                                                         |
| 25       | 14/06/2022          | Submission of the abstract                                                                                 |
| 25       | 17/06/2022          | Submission of the ETN                                                                                      |
| 25       | 17/06/2022          | Filling in the survey                                                                                      |
| 25       | 24h before defence  | Making sure the registration summary is signed by the external supervisor                                  |
| 25       | 24h before defence  | Submission of the definitive presentation                                                                  |
| 26       | 20/06/2022          | Week of the defences                                                                                       |
| 27       | 27/02/2022          | Feedback moment on presentation and defence                                                                |

### Data management

> How and where will the data be stored and structured, according to the FAIR principle?

![FAIR Principles](https://i.imgur.com/RYLlgPl.png)

The data will be provided by the Group Eyckerman in form of an excel (this is how they work up until today). The BITS core will provide a shared database with user access control to store the catalog of donor- and destination vectors and also the constructs which are created with the tool.

### Traceability of the steps and methods

The platform for documenting the steps and for storing other documentations like the ETN entries, interviews, System Requirement / Design Documents, will be stored in a HackMD.io repository. This is the platform used by the BITS core at VIB for sharing documents.

### Version control of the code

> - Which Git repository will be used to store the code?
> - How will the repository be made available for the internal and external supervisors?

Git Repositry isn't created yet but will be published under the organization VIB Bioinformatics Core.


## Background information on the traineeship topic

Golden Gateway cloning is a cloning method to combine several fragments into 1 construct. The Golden Gate cloning method can be a two-step process but not necessarily:
* Step 1: Level 0 to level 1
* Step 2: Level 1 to level 2

In some cases a level 1 construct is the final construct. In that case step 2 is not performed.

**GGW: From level 0 to a level1 construct:**

Several level 0 fragments are added to the reaction in combination with a destination vector or backbone. All these fragments are in a first instance digested so the overhangs between the inserts and the destination vector become complementary. Finally all the fragments are ligated to each other to form a level 1 construct or transcript unit.

The following illustration depicts the mechanism followed by the reactions.

![](https://i.imgur.com/mhxX3Qd.png)


**GGW: From level1 to a level2 contruct:**

To create a level2 construct 2-3 level 1 constructs are combined with each other in a similar reactions and form a level 2 construct.

![Golden gateway enzymatic reaction - Delhaye L.](https://i.imgur.com/KOaGR5C.png)

## Personal development

For the personal development, one learning outcome has been formulated published on the BIT sharepoint under the folder _"3. Concept of learning outcome"_.

After completing the traineeship, I reflected on the learning outcome that was defined at the beginning of the project. The goal was to develop a library that can be accessed by other applications.

In the end the library was replaced by an API because it will give even more flexibility in the future. Since the API will be accessible from any kind of application, like a desktop application or even a smart phone application.The application automates the golden gate process and stores the data in a database. Since the core application is in the form of an API it is reusable in all kinds of projects.

The project has been delivered without compiler errors, linter errors and all custom functionalities tested within the estimated timeframe.

Based on the outcome, I can conclude that the goals, defined in the learning outcome, were largely obtained at the end of this traineeship.

## Intermediate evaluation traineeship

The feedback orginating from the intermediate evaluation form can be found in the folder _"4. Electronic traineeship notebook"_.

The outcome of the evaluation was pretty much as expected. There were no critical issues that have addressed immediately.

Some remarks from the external traineeship supervisor:

- I should improve my knowledge of GIT:
    - Interactive rebase
    - Setting up CI pipelines
- I have the tendency to implement elements I end up not needing. If you don't need it right now, chance exists you won't need it at all... So in the end, it's possible a lot of time is wasted.
- I should be more confident. Apparently, I'm more often right than I think.

## Self assessment at the end of the traineeship

For the self assessment part, I used annex 5 to grade myself. This excel file can be found in BIT sharepoint folder _"4. Electronic traineeship notebook"_.

I feel that for most aspects, I could meet the expectations. On one learning outcome, I gave myself a "not applicable (N/A)" score for summarizing results in a scientifically corrrect way and to make a conclusion for the project. The project is about developing an application and not to answer scientifical or biological questions.

On the last learning outcome I gave myself an "Excellent" score because I think that really do a lot more than the bare minimum.

## Reflection on international and/or intercultural aspects

International / intercultural aspects:

- My external traineeship supervisor is Australian and living in the Netherlands
- Language in the work space is English:
    - mails
    - calls
    - presentations / demos
- English literature

## Small assignment: Try to access a rust function from C#

**Date:** 27-09-2021

The purpose of this exercise is to try to access a function, written in Rust, from an application written in C#.

### Resources

- [The Rustonomicon - FFI](https://doc.rust-lang.org/nomicon/ffi.html)
- [Calling Rust from C#](https://dev.to/living_syn/calling-rust-from-c-6hk)

### GitHub Repo's

- [Rust code](https://github.com/kdp-cloud/example_ffi_Rust.git)
- [C# code](https://github.com/kdp-cloud/AddNumbersFromRust.git) 

## Small assignment 2: Try to compile Rust code to WebAssembly

**Date:** 28-09-2021

The purpose of this exercise is to try to compile Rust-code into WebAssembly and interact with a website.

### Resources

[Compiling Rust to WebAssembly - Mozilla](https://developer.mozilla.org/en-US/docs/WebAssembly/Rust_to_wasm)

### GitHub Repo's

[hello-wasm](https://github.com/kdp-cloud/hello-wasm.git)

### Problems

1. Was able to compile the Rust code to WebAssembly but could not interact with the DOM using JS.

> **Date solved: 29-09-2021**
> 
> Something went wrong when serving the website using the python http.server package. When using the *Live-server* plugin in visual studio code the website showed the alert message like it was supposed to.

## Requirements Interview with Group Eyckerman

The Requirements Interview document can be found on this location:

[HackMD.io page](https://hackmd.io/@bits-interns/H1kunZkVK)

## Observinf the cloning design process in CLC with Delphine

**Date:** 29/10/2021

A teams meeting was organised with Delphine De Sutter from group Eyckerman to observe the cloning design process in CLC.

## Brainstorming on the application

**Date:** 29-09-2021

All information concerning this entry are found on the link beneath.

[HackMD.io page](https://hackmd.io/Y4aJehiLSxqTxykR07fgGg?view)

## Trying out Blazor

**Date:** 30-09-2021

During the brainstorm exercise some options were selected for a framework. The first one was Blazor. It uses the .Net-technology and has the advantage to be (almost) completely written in C#. It's ment for the web but can compile to webassembly.
The purpose of this exercise is to try to create a mock-up of the web-app with Blazor to experience how hard it is to add html-elements and implement other libraries, written in C#.

### GitHub repository

[Blazor_Test_UI](https://github.com/kdp-cloud/Blazor_UI_Test.git)

### Conclusions
- UI components are natively very limited
- Third party packages are available but not always very trustworthy.
- No native charting or other visualisation possible.
- Very slow at loading time (All C# libraries have to be loaded in the browser, several MB's...)
- Bindings between HTML and C# are easily made.

## Trying out React

**Date:** 01/10/2021

React.js is the second framework to be tested for the project. The idea is to try and make a UI in react.js.

### GitHub Repository:

[GGW First Test React.js](https://github.com/kdp-cloud/ggw-first-test-react.git)

## Working on a mock-up for the User Interface

**Date:** 04/10/2021 - 06/10/2021

In order to get as much feedback as possible, a meeting with Sven Eyckerman has been scheduled to show three proposition for a User Interface.

Each proposition should have these attributes:
- An attractive and user-friendly way of selecting the donor- and destination vectors, depending on their overhangs
- A section to add all needed information
  -  Construct Name
  -  Length
  -  ID
  -  Application
  -  Designer name
  -  Description
-  A visual representation of the construct after choosing the different modules
-  A way of downloading the information of the construct (annotations, sequence,...) as a Genbank File

### GitHub Repository

[UI Propositions](https://github.com/kdp-cloud/UI-Propositions.git)

## Haskell tutorial

In case we need to write an API, we might need to write it in Haskell. This tutorial was given by my external internship supervisor, James Collier.

### GitHub Repository

[Haskell Tutorial](https://github.com/kdp-cloud/Haskell-Tutorial.git)

## Meeting with Sven Eyckerman about the UI

The purpose of this meeting is to show and discuss the propositions for the UI.

### Remarks

> - Add a big "Start" button on the home page
> - After choosing a destination vector, the rest of the destination vectors should be hidden.
> - If possible: Drag the donor-vectors to the visualisation instead of a div-container.
> Instead of asking the user how many donor-vectors it will use, provide only these choices to the user as radio-buttons:
>     - 6 donor-vectors
>     - 5 donor-vectors
>     - 4 donor-vectors
>     - 3 donor-vectors

### Extra requirements

- Data in database should be shielded from people outside of a research group. Which means, the application requires user access management.
- The application should run on a mobile device (ipad / tablet, iphone / smartphone, ...) There are two approaches:
    - We use technology which enables us to write the code once, but can compile it as cross-platform application.
        - __Advantage__: App is not on the web so we have to worry less about security issues concerning the database. It could even run in first instance on local DB (like sqLite)
        - __Disadvantage__: This kind of technologies are not considered as the most robust solutions. It's still better to seperately write a desktop application and a mobile application. We also still need the internet (webview + socket that listens for requests) for the user access control which defeats the purpose of a desktop application.
        - __Technologies__:
            * Gluon mobile: Uses JavaFX that produces a desktop (windows & mac), android and ios app.
            * Xamarin: Uses C# that produces a windows UWP app, an android app and a ios app.
    * We make it a web application.
        * __Adantage__: We don't need to worry about cross-platform compatibility.
        * __Disadvantage__: We need to write an API for safe database access.
        * __Technologies__:
            * Blazor
            * React.js
            * Javascript
            * Elm

## Trying out JavaFX 

**Date:** 08/10/2021

### UI designing

UI designing is fairly simple and extremely fast when using tools like Scenebuilder. All UI-components can be stored in a fxml-file which is very similar to xml. All components can be styled, using CSS-files, so we have the same flexibility as in a webpage.

#### Conclusion

There are charting libraries available for the visual representation out of the box.

![](https://i.imgur.com/PuX4Nzf.png)


### Creating a webview and listening to HTTP requests

In order to implement the user access control (OpenID Connect), we need a webview element redirecting the user to the authentication server and we need to open a socket that listens to the reply of that authentication server to confirm the ID of the end-user.

#### Conclusion

This is obtained fairly simple in Java.

### Gluon Mobile

The gluon mobile plugin for java provides libraries that make it possible to make cross-platform applications using JavaFX.

#### Conclusion

Could not get the plugin to work properly.

### GitHub Repository

[JavaFX tests](https://github.com/kdp-cloud/Tests-JavaFX.git)

## The Software Design Document

**Date:** 11/10/2021

### Template

#### System architecture

* Describe the overall system architecture an define the major components and what they're responsible for
* Also identify data flows
For each component:
* Identify high-level design decisions
* GUI wireframes (screenshots of what you have)
* Interface points for other components (not specific names just what they do and what data)
* reference user stories/requirements
Outline the other design alternatives we considered and why they were rejected
* Technology choices for implementation and testing
User testing strategy

##### The User Interface

> The user interface lets the user interact with the application and pass on the information needed for the construct design process. The UI Should be intuitive and have a visual representation of the construct.
> The choice of technology for the UI has been made so that only one UI has to be designed that can both run as desktop applications as well as a mobile application.
> 
> **Wire Frames:**
> ![](https://i.imgur.com/PuX4Nzf.png)

> ##### Server application which can receive HTTP requests
> To implement User Access Control, the application should take HTTP Requests

##### The Core Application
> This is the part of the application that will perform the in silico experiments.

##### The Database & compatibility layer
> This is the part of the application that will perform the the database interactions (CRUD). The database will be SQL-based.


## Exploring Elm as a framework for the UI

**Date:** 15/10/2021

Elm is a functional language that compiles to javascript and is used to create responsive web applications.

### Resources

#### Guides

[Elm Lang guide](https://guide.elm-lang.org/)

[Elm Europe 2017 - Evan Czaplicki - The life of a file](https://youtu.be/XpDsk374LDE)

#### Videos

["Important!!!: Making Impossible States Impossible" by Richard Feldman](https://youtu.be/IcgmSRJHu_8)

["Make Data Structures" by Richard Feldman](https://youtu.be/x1FU3e0sT1I)

[Parse, don't validate](https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/)

["Building a Toolkit for Design" by Matthew Griffith](https://www.youtube.com/watch?v=Ie-gqwSHQr0)

### GitHub Repository

[Tests in Elm](https://github.com/kdp-cloud/Elm-Tests.git)

### Making Impossible States Impossible" by Richard Feldman

**Date:** 22/10/2021

* Elm CSS
    * CSS in Elm
    * Generate valid stylesheets
    * functions instead of @ statements, which can often be invalid
    * stylesheet is a type {charset (Maybe...), imports (List), namespaces (List), declarations (List)}
    * Can we make impossible CSS states impossible?
* Same strategy in Elm models
    * Making a List => {first: element, other = List of elements}
    * Better => Zip-list {current, previous, remaining}
    * expose functions to access data instead of the whole constructor
    * Rather use tailored union types instead of adding Maybe's.

## Designing the UI in Elm:

**Date:** 26/10/2021

### Resources:

[Elm-lang.org - Elm-UI](https://package.elm-lang.org/packages/mdgriffith/elm-ui/latest/)

[Korban.net - Elm - Elm-UI](https://korban.net/elm/elm-ui-patterns/)

[gampleman/Visualisation](https://package.elm-lang.org/packages/gampleman/elm-visualization/latest/)

### Github repository:

[GGW-Elm](https://github.com/kdp-cloud/GGW-Elm.git)

### To do:

* Download button => OK
* Visualisation => OK
* Sticky navbar => OK
* Interactively update the insertList in the model by appending the selection in inserts table =>OK
* Sorting the inserts in the visual representation => OK
* Reading the data and displaying it in the UI
* Get / Post Http requests.
* Feature: Filter backbones and inserts
* Write Data validation function before saving to the DB.
    * Check if construct has the correct number of inserts
    * Check if there is a backbone
    * Check if all fields are filled in
* 

### Questions for James:

**Date:** 05/11/2021

* Appending a record to a list of records in the model
    * List of inserts can be empty
    * Backbone can be empty
        * Using a dummy Backbone?
        * Better to use a Maybe
    * Inserts have to be sorted on overhang!
        * Better to write a function that does the sorting and validation before rendering the contruct
* Libraray for DB connection?
    * The DB-connection will happen through an API. Is more secure!
* Multiple pages?
* Which colors am I allowed to use?
* Do I transfer the ownership of the repo.

* Just for fun: How would you have done it to list the inserts in the model?

## Call with Sven and Delphine about data and constraints

**Date:** 05/11/2021 + 08/11/2021

* Data will be delivered in seperate Genbank files
    * To Do => Write script that reads a genbankfile and stores the information in a database
* Constraints mostly have a one-to-one relation
    * Working with blacklist?
    * Will deliver a description of all constraints in coming weeks.


[Poetry](https://python-poetry.org/docs/#osx--linux--bashonwindows-install-instructions)

## API - User authentication + Hello World - example

**Date:** 19/11/2021

### Prerequisites

* Linux machine (preferably)
* Docker engine installed
* Poetry installed
* Python ^3.8
* postman installed

### Launching the API:

1. cd into the root folder of the application GGW-Elm
2. `docker-compose up`creates the environment
    * creates the environment
    * Listens to localhost:8000
    * localhost:8000/docs contains all the information for postman
3.  in a seperate terminal: cd to the ./server/ folder
4.  `poetry install` => Will install the necessary dependencies
5.  `./run-dev-env.sh`
6.  In postman:
    * GET-method => localhost:8000/login
    * No parameters
    * Returns a URL for the user
7.  Open the URL from postman in a web browser
8.  If you have to login:
    * User = ggw
    * password = ggw
9.  a new URL opens with a state and code.
    * Link is only valid for 1 minute!
10. In Postman:
    * POST-method => localhost:8000/authorize
    * parameters in body:
        {
            "state": from URL
            "code": from URL
        }
    * Postman will return a token
11. Use the API:
    * GET-method => localhost:8000/hello (hello = example definition that returns "Hello World")
    * In tab "Authorization":
        * Type = "Bearer Token"
        * Token = token from postman

## Implementing login in the User Interface

**Date:** 3/12/2021 + 7/12/2021

### Resources

* [Elm-lang.org tutorial - HTTP](https://guide.elm-lang.org/effects/http.html)
* [Elm programming - fetching HTTP](https://elmprogramming.com/fetching-data-using-get.html)
* [Elm-lang.org - HTTP](https://package.elm-lang.org/packages/elm/http/latest/Http)

## Creating the vector catalog

**Date:** 13/12/2021 + 20/12/2021

The vector catalog should be able to add new vectors to the database and query the database for existing vectors and return them in a table.

The whole vector catalog should be in a modal dialog form that can be rendered visible from the home page. The dialog should have a table with all the vectors in it and some fields that filter the table on name, MPG-number and overhang type.

### Resources

* [Example code from James](https://bitbucket.org/kloostermannerflab/falcon-swr-client/src/fafead9946efeacc345be0e2fd80d4a7786efb5c/client/src/Main.elm#lines-623)
* [Publishing an Elm Package](https://korban.net/posts/elm/2018-10-02-basic-steps-publish-package-elm-19/)
* [Accordion panes in Elm](https://github.com/NoRedInk/elm-html-widgets/blob/master/src/Widget/Accordion.elm)

## Filtering the table of vectors

**Date:** 20/12/2021

The vector tables will become quite large at some point. So the user should be able to filter the tables based of the following principles:

1. Level 0 donor vectors:

    - Vector name
    - And / Or vector MP-G0 number (or location)
    - And overhang type

2. Backbones of destination vectors:

    - Vector name
    - And / Or vector MP-GB number (or location)
 
3. Level 1 vectors:

    - Vector name
    - And / Or vector MP-G1 number (or location)
 
### Resources

[Example code from James](https://github.com/vibbits/acinetobase-static/blob/master/src/Main.purs#L46)

### To do:

- [x] Adding level filter for backbones
- [x] Move accordion pane to "Vector 1 construction" page

## Adding Level 0 and backbone vectors to the vector tables

**Date:** 07/01/2022 + 14/01/2022

The user should be able to add new Level0 and backbone vectors to their respective tables. The user should fill in the basic information needed for this in a new page.

**Basic info for Level 0:**

- Name
- MP-G0 number
- Bacterial strain
- Responsible = current user
- Group = Group the user belongs to
- Selection
- Cloning technique
- BSAI overhang type
- Notes
- Restriction Sites present?
- Date (of creation)
- GenBank data (Submitted by a user by clicking a button a button)

**Basic info for Backbone:**

- Name
- MP-GB number
- Bacterial strain
- Responsible = current user
- Group = Group the user belongs to
- Selection
- Cloning technique
- BSAI overhang type
- BSMBI Overhang Type
- Vector Type
- Notes
- Date (of creation)
- GenBank data (Submitted by a user by clicking a button a button)

Next, the user clicks on a button to submit this information to the database. Afterwards, the vector should be visible in their respective tables.

### Assay on Github commits:

[Tim Pope](https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html)

[Commit.style](https://commit.style/)

## Popluating the database

**Date:** 18/01/2022

The Eyckerman group already has a vast number of donor-, destination-, and Level 1 constructs. These should be properly imported to the database when the application will be deployed.

Therefor, a new Python script is added to the server application that will only run once when the server app is deployed.

### Self-referencing relationship in SQLAlchemy

Since the different types of vectors contain approximately the same information, it makes a lot of sense to store all constructs in the same table. This will prevent us (the developers) to have to make complicated and time-consuming joins between tables.

The general idea is that a generic model object is created that can be parent to multiple child elements and be a child to other parent constructs. To meet these requirements, a Self-referencing table with a many-to-many relationship will be implemented in the database.

[SQLAlchemy - docs](https://docs.sqlalchemy.org/en/14/orm/join_conditions.html#self-referential-many-to-many)

![](https://i.imgur.com/mVSJ9x9.png)

To convert the datasubmitted by the user and convert

### Auto-generate alembic revision

```bash=
poetry run alembic revision --autogenerate -m <revsion message>
```

### Upgrade alembic version to head-version

```bash=
poetry run alembic upgrade head
```

## Retrieving the the vectors from the database

__Date:__ 24/01/2022

### Issue getting data from DB

__Error:__

```bash=
response  ->  16  ->  features  ->  8
  value is not a valid dict (type=type_error.dict)
```

__Solution:__

PyDantic converts SQLAlchemy representation to the schemas when you give a response_model argument to the annotation. Implicitly that's done which a schemas.Vector.from_orm(sqlalchemy_repr) which requires the orm_mode = True config.

In schemas.py:

```python=
class Reference(BaseModel):
    authors: str
    title: str

    class Config:
        orm_mode = True


class Qualifier(BaseModel):
    key: str
    value: str

    class Config:
        orm_mode = True


class Feature(BaseModel):
    type: str
    qualifiers: List[Qualifier]
    start_pos: int
    end_pos: int
    strand: int

    class Config:
        orm_mode = True


class Annotation(BaseModel):
    key: str
    value: str

    class Config:
        orm_mode = True

```

### f-String notation:
```pyhton=
>>> x = 5
>>> print(f"{x=}")
x=5
```

## Query vectors in DB and displaying them in the UI

__Date:__ 24/01/2022 - 11/04/2022

In order to  retrieve vectors from the database, the user sends an HTTP GET-request to the API. In return the API sends the data in JSON-format back as a response to the client.

The client then has to decode this response and update the elm-model in the browser.

### Making JSON Decoders in Elm

**Resources:** [Elm/Json/Json.Decode](https://package.elm-lang.org/packages/elm/json/latest/Json.Decode)

#### Issue with decoder

When making the decoder, the following error occurs:
```elm=
Level0Received Err
0 = BadStatus 401
```

This indicates that there is probably somthing wrong with the decoder...

BsaI and BsmbI fields are not always filled in. That's what causing the BadStatus HTTP response. Some additional feedback on this matter from the Eyckerman group is required.

#### Feedback Delphine

**Date:** 14/02/2022

> Backbones for making level 1 constructs:
> - Always have a Bsa1 Overhang
> - Always have a BsmB1 Overhang
> - Untill now Only have Bsa1 Overhang A__G

### Extra information BsaI digestion

**Date:** 27/02/2022

The idea is to perform a BsaI digestion before vectors are added to the database. This will make sure we don't overpopulate the database with all kinds of irelevant GenBank annotations.

#### Main principle of BsaI-digestion

One aspect will at **All times** be respected: Only the 5' :arrow_right: 3' strand will be used to represent the in-silico digestion. This also implies that genbank files can only contain the DNA-sequence of the 5' :arrow_right: 3' strand.

**BsaI restriction enzyme:**
- Has two recognition sites:
    - 5'...GGTCTC(N)<sub>1</sub>...3'
    - Reverse complement: 3'...CCAGAG(N)<sub>5</sub>...5'  :arrow_right:  5'...(N)<sub>5</sub>GAGACC...3'
- Creates sticky ends cuts 1 base after recognition site or  5 bases before the reverse complement of the recognition site.

**Illustration New England Biolabs:**

![NEB - Bsa1](https://i.imgur.com/9iceEbw.png)

NNNN**GGTCTC*N***|-*cut*-|NNNNNN...NNNNNN|-*cut*-|***NNNNN*GAGACC**

#### Difference between Level 0, Level 1 and Level 2 backbones

- Level 0 backbones:
    - Contains BsaI recognition sites
    - Used to make Level 0 elements
    - Are BsmbI free
    - Contain the BsaI-overhangs:
        - A__B
        - B__C
        - C__D 
        - C__G
        - D__E
        - D__G
        - E__F
        - E__G
        - F__G
- Level 1 backbones:
    - Contains BsaI recognition sites
    - Contains only the A__G BsaI-overhang
    - Used to make a level 1 contstruct or transcript unit
    - Not always BsmbI free:
        - If BsmbI free  :arrow_right:  Not possible to make a level 2 contruct. Reaction stops here. In the future those will be removed.
        - If not BsmbI free  :arrow_right: Level 1 can be used for making a level 2
    - Contains BsmbI-overhangs:
        - W__X
        - W__Z
        - X__Y
        - X__Z
        - Y__Z
- Level 2 backbones:
    - Contains BsmbI recognition sites
    - Contains BsmbI-overhang W__Z

#### BsaI digestion Level 0 backbones

**Cutting mechanism:**

...NNNN|NNNN<sub>overhang 1</sub>|***GGTCTC*N**|-*cut*-|NNNNNN...NNNNNN|-*cut*-|NNNN<sub>overhang 2</sub>|***NNNNN*GAGACC**NNNNNN...

- BsaI recognition sites are *facing the outside*.
- After BsaI digestion, the BsaI recognition site is still retained in the backbone for later reactions

#### BsaI digestion Level 1 backbones

**Cutting mechanism:**

...NNNNNNNN|-*cut*-|***NNNNN*GAGACC**|NNNN<sub>overhang A</sub>|NNNNNN...NNNNNN**GGTCTC*N***|-*cut*-|NNNNNN...

- BsaI recognition sites are in reversed order 
- After BsaI digestion, the BsaI recognition sites are also cut out of the backbone


### Explaination of `Maybe.andThen`

**Date:** 11/04/2022

andThen or Monadic bind : (a -> Maybe b) -> Maybe a -> Maybe b

Alternatively:

flatMap :(flatten << map)
map : (a -> b) -> Maybe a -> Maybe b

flatten Maybe Maybe a -> Maybe a
:arrow_right: Takes a Maybe field out of a Maybe Record

## Creating a Genbank Record (file)

__date:__ 19/04/2022 - 25/04/2022

One of the requirements for the projects is the generation of a genbank file.

### Resources back-end:

- [biopython.org](https://biopython.org/docs/1.75/api/Bio.GenBank.Record.html)
- [Biostars](https://www.biostars.org/p/364418/)

### Questions to ask James after his holidays

- [x]  When passing the genbank content from server-side to client-side, extra escape characters are created

__Server-Side__

```
LOCUS       MP-G1-798_pEN-W-EF1a-Kozak-ATG-VSVtag-eGFP-2xG4S-SARS-CoV2-"N"-3xSTOP-AarI stuffer-pA Bgh-X    5743 bp   ds-DNA circular            2021-08-30 00:00:00
DEFINITION  synthetic circular DNA.
SOURCE      .
  ORGANISM  synthetic DNA construct
            .
REFERENCE
  AUTHORS   Twistbioscience
  TITLE     Direct Submission
  JOURNAL   Generated Tue 19 Apr 2022 by GG2
FEATURES             Location/Qualifiers
type: Vector
location: [0:5743](+)
qualifiers:
    Key: origin, Value: ["MP-GB-20_pEN-W-A-ccdB-G-X (3,654bp circular)Target vector: from BsaI cut at 1580^1581 to BsaI cut at 141^142, 2,215bpOrientation: originalPlus strand 5':   no changePlus strand 3':   no changeMinus strand 5':  no changeMinus strand 3':  no change"]
type: primer_bind
location: [49:66](+)
qualifiers:
    Key: label, Value: ['M13 fwd']
    Key: note, Value: ['common sequencing primer, one of multiple similar variants']
```

__Client-side__

```
Genbank content: : "\"LOCUS       MP-G1-798_pEN-W-EF1a-Kozak-ATG-VSVtag-eGFP-2xG4S-SARS-CoV2-\\\"N\\\"-3xSTOP-AarI stuffer-pA Bgh-X    5743 bp   ds-DNA circular            2021-08-30 00:00:00\\nDEFINITION  synthetic circular DNA.\\nSOURCE      .\\n  ORGANISM  synthetic DNA construct\\n            .\\nREFERENCE   \\n  AUTHORS   Twistbioscience\\n  TITLE     Direct Submission\\n  JOURNAL   Generated Tue 19 Apr 2022 by GG2\\nFEATURES             Location/Qualifiers\\ntype: Vector\\nlocation: [0:5743](+)\\nqualifiers:\\n    Key: origin, Value: [\\\"MP-GB-20_pEN-W-A-ccdB-G-X (3,654bp circular)Target vector: from BsaI cut at 1580^1581 to BsaI cut at 141^142, 2,215bpOrientation: originalPlus strand 5':   no changePlus strand 3':   no changeMinus strand 5':  no changeMinus strand 3':  no change\\\"]\\ntype: primer_bind\\nlocation: [49:66](+)\\nqualifiers:\\n    Key: label, Value: ['M13 fwd']\\n    Key: note, Value: ['common sequencing primer, one of multiple similar variants']\\ntype: misc_feat
```

### Implementing the BsaI-digestion

When a vector - with all it's features and annotations - is digested, only the annotations and features of the "pieces" of interest should be retained.

### Issue with the BsaI digestion

The Level 1 gebank files, provided by lab Eyckerman, have a different sequence than when the BsaI-digestion is performed by the GG2-application.
When aligning the digested inserts and backbone against the genbank sequence of the Eyckerman lab, all pieces align except for the backbone. The picture below shows a multiple sequence alignment:

![](https://i.imgur.com/bGhO0KX.png)

The MSA shows that position 1 in somewhere at the end of the backbone.

### Questions for Delphine

- [x] Qualifiers have a "strand". Do I need to know this? I would assume the strand doesn't really matter...

### Steps BsaI digestion:

- Retrieve the inserts and backbone that make up the level 1 construct
- Perform a BSAI digest in silico
    - Cut our the relevant sequence parts
    - Only retain the relevant features
    - Change the start and end positions
- Concatenate the sequences
- Reformat the features
    - Change the start and end positions

### Retaining the right features:

- Is it a backbone?
    - If backbone :arrow_right: Backbones are always cut so that the inner part is removed!
        - Backbones used to make level 0 vectors should retain the Bsa1-site after digestion.
            - [see "BsaI digestion Level 0 backbones"](#BsaI-digestion-Level-1-backbones)
        - Backbones used to make level 1 vectors dont't need the bsa1-sites anymore!
            - [see "BsaI digestion Level 0 backbones"](#BsaI-digestion-Level-0-backbones)
    - Else :arrow_right: Depending on the orientation and start position, the outer or inner part is retained.
- Only complete features should be retained
    - E.g. BSAI enzyme cuts at position 50 but a feature spans from position 45 - 55. This feature will not be retained!

#### Details BSAI digestion backbones

|1------part 1------50|-|*Overhang A*|-**BSAI site 1**|51-------part 2-------100|**BSAI site 2**-|*Overhang G*|-|101-------part3------200|

|*Overhang G*|-1-------part3------100|-|101------part 1------150|-|*Overhang A*|