Skip to content

Commit

Permalink
Merge branch 'master' into release-1.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Johansson authored Mar 4, 2021
2 parents 09d6cd2 + 6c45c1c commit f55ba36
Show file tree
Hide file tree
Showing 18 changed files with 236 additions and 149 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ About changelog [here](https://keepachangelog.com/en/1.0.0/)
- Shift - Click now Zoom in
### Changed
- Refactored page definitions into blueprint module
- Removed entrypoint script
### Fixed
- Navigation shortcuts does not trigger in text fields
- Fixed crash when searching for only chromosome
- Restored ability to search for transcripts by gene name
- Fixed crash when Shift - Click in interactive canvas
- Fixed checking of api return status in drawInteractiveContent
- Aligned highlight in interactive canvas

## [1.1.1]
### Fixed
Expand Down
5 changes: 2 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ COPY --from=node-builder /usr/src/app/build/*/gens.min.* gens/blueprints/gens/st
# Chown all the files to the app user
COPY gens gens
COPY utils utils
COPY entrypoint.sh ./
RUN chown -R app:app /home/app/app
# make mountpoints and change ownership of app
RUN mkdir -p /media /access /fs1 && chown -R app:app /home/app/app /media /access /fs1
# Change the user to app
USER app
ENTRYPOINT ["./entrypoint.sh"]
31 changes: 31 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Instructions to release a new version of Gens

1. Create a release branch with the release name, e.g. `release-1.1.1` and checkout the branch

```bash
git checkout -b release-1.1.1
```

2. Update version to, e.g. 1.1.1

- in `gens/__version__.py`
- in `package.json`

3. Make sure `CHANGELOG.md`is up to date for the release


4. Commit changes, push to github and create a pull request

```bash
git add gens/__version__.py
git add package.json CHANGELOG.md
git commit -m "Release notes version 1.1.1"
git push -u origin release-1.1.1
```

5. On github click **create pull request**.

6. After getting the pull request approved by a reviewer merge it to master.

7. Draft a new release on GitHub, add some text - e.g. and abbreviated CHANGELOG - and release.
This adds a version tag, builds docker image.
5 changes: 2 additions & 3 deletions assets/css/gens.scss
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,8 @@ html, body {
}

#region_field.error:disabled {
outline: 1px dotted red;
outline: 5px auto red;
background-color: $default-bg-color;
outline: 5px dotted red;
background-color: red;
}

#times {
Expand Down
104 changes: 58 additions & 46 deletions assets/js/interactive.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class InteractiveCanvas extends FrequencyTrack {
// Initialize marker div
this.markerElem = document.getElementById('interactive-marker');
this.markerElem.style.height = `${this.plotHeight * 2}px`;
this.markerElem.style.top = `${this.y + 58}px`;
this.markerElem.style.top = `${this.y + 82}px`;

// State values
const input = inputField.value.split(/:|-/);
Expand Down Expand Up @@ -209,7 +209,13 @@ class InteractiveCanvas extends FrequencyTrack {
// numerical sort
const [start, end] = [this.start + Math.round((this.dragStart.x - this.x) / scale),
this.start + Math.round((this.dragEnd.x - this.x) / scale)].sort((a, b) => a - b);
this.loadChromosome(this.chromosome, start, end)
// if shift - click, zoom in a region 10
// fix for slowdown when shift clicking
if ( ( end - start ) < 10 ) {
this.zoomIn();
}
//
this.loadChromosome(this.chromosome, start, end + 1);
}
// reload window when stop draging
if (this.drag) {
Expand All @@ -233,52 +239,55 @@ class InteractiveCanvas extends FrequencyTrack {
const keystrokeDelay = 2000;
document.addEventListener('keyevent', event => {
const key = event.detail.key;
const excludeFileds = ['input', 'select', 'textarea'];

if ( key === 'Enter' ) {
// Enter was pressed, process previous key presses.
const recentKeys = this.keyLogger.recentKeys(keystrokeDelay);
recentKeys.pop(); // skip Enter key
const lastKey = recentKeys[recentKeys.length - 1];
const numKeys = parseInt((recentKeys
.slice(lastKey.length - 2)
.filter(val => parseInt(val.key))
.map(val => val.key)
.join('')))
// process keys
if ( lastKey.key == 'x' || lastKey.key == 'y' ) {
this.loadChromosome(lastKey.key);
} else if ( numKeys && 0 < numKeys < 23 ) {
this.loadChromosome(numKeys);
} else {
return;
// dont act on key presses in input fields
const excludeFileds = ['input', 'select', 'textarea'];
if ( !excludeFileds.includes(event.detail.target.toLowerCase()) ) {
if ( key === 'Enter' ) {
// Enter was pressed, process previous key presses.
const recentKeys = this.keyLogger.recentKeys(keystrokeDelay);
recentKeys.pop(); // skip Enter key
const lastKey = recentKeys[recentKeys.length - 1];
const numKeys = parseInt((recentKeys
.slice(lastKey.length - 2)
.filter(val => parseInt(val.key))
.map(val => val.key)
.join('')))
// process keys
if ( lastKey.key == 'x' || lastKey.key == 'y' ) {
this.loadChromosome(lastKey.key);
} else if ( numKeys && 0 < numKeys < 23 ) {
this.loadChromosome(numKeys);
} else {
return;
}
}
switch (key) {
case 'ArrowLeft':
this.nextChromosome()
break;
case 'ArrowRight':
this.previousChromosome()
break;
case 'a':
this.panTracksLeft();
break;
case 'd':
this.panTracksRight();
break;
case 'ArrowUp':
case 'w':
case '+':
this.zoomIn();
break;
case 'ArrowDown':
case 's':
case '-':
this.zoomOut();
break;
default:
return;
}
}
switch (key) {
case 'ArrowLeft':
this.nextChromosome()
break;
case 'ArrowRight':
this.previousChromosome()
break;
case 'a':
this.panTracksLeft();
break;
case 'd':
this.panTracksRight();
break;
case 'ArrowUp':
case 'w':
case '+':
this.zoomIn();
break;
case 'ArrowDown':
case 's':
case '-':
this.zoomOut();
break;
default:
return;
}
});
});
Expand Down Expand Up @@ -346,6 +355,9 @@ class InteractiveCanvas extends FrequencyTrack {
reduce_data: 1,
}).then( (result) => {
console.timeEnd('getcoverage');
if ( result.status == "error" ) {
throw result;
}
// Clear canvas
this.contentCanvas.getContext('2d').clearRect(0, 0,
this.contentCanvas.width, this.contentCanvas.height);
Expand Down
17 changes: 10 additions & 7 deletions assets/js/track.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,17 @@ class Track {
const chromosomes = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10',
'11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21',
'22', 'X', 'Y']
const chromosome = regionString.split(':')[0];
if ( !chromosomes.includes(chromosome) ) {
throw `${chromosome} is not a valid chromosome`;
if ( regionString.includes(':') ) {
const [chromosome, position] = regionString.split(':');
// verify chromosome
if ( !chromosomes.includes(chromosome) ) {
throw `${chromosome} is not a valid chromosome`;
}
let [start, end] = position.split('-');
start = parseInt(start);
end = parseInt(end);
return [chromosome, start, end];
}
let [start, end] = regionString.split(':')[1].split('-');
start = parseInt(start);
end = parseInt(end);
return [chromosome, start, end];
}

tracksYPos(heightOrder) {
Expand Down
18 changes: 0 additions & 18 deletions entrypoint.sh

This file was deleted.

2 changes: 1 addition & 1 deletion gens/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .app import create_app
from .__version__ import VERSION as version
from .app import create_app
67 changes: 33 additions & 34 deletions gens/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,19 @@
from typing import List

import attr
from flask import abort, current_app, jsonify, request

import cattr
import connexion
from flask import abort, current_app, jsonify, request

from gens.db import RecordType, VariantCategory, query_records_in_region, query_variants
from gens.exceptions import RegionParserException
from gens.graph import REQUEST, get_cov, overview_chrom_dimensions, parse_region_str

from .constants import CHROMOSOMES, HG_TYPE
from .io import get_overview_json_path, get_tabix_files

LOG = logging.getLogger(__name__)

CHROMOSOMES = [
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"11",
"12",
"13",
"14",
"15",
"16",
"17",
"18",
"19",
"20",
"21",
"22",
"X",
"Y",
]

HG_TYPE = (38, 19)


@attr.s(auto_attribs=True, frozen=True)
class ChromosomePosition:
Expand Down Expand Up @@ -173,9 +145,6 @@ def get_transcript_data(region, hg_type, collapsed):
LOG.error("Could not find transcript in database")
return abort(404)

with current_app.app_context():
collection = current_app.config["GENS_DB"][f"transcripts{hg_type}"]

# Get transcripts within span [start_pos, end_pos] or transcripts that go over the span
transcripts = list(
query_records_in_region(
Expand All @@ -201,6 +170,36 @@ def get_transcript_data(region, hg_type, collapsed):
)


def search_annotation(query: str, hg_type, annotation_type):
"""Search for anntations of genes and return their position."""
# Lookup queried element
collection = current_app.config["GENS_DB"][annotation_type]
db_query = {"gene_name": re.compile("^" + re.escape(query) + "$", re.IGNORECASE)}

if hg_type and int(hg_type) in HG_TYPE:
db_query['hg_type'] = hg_type

elements = collection.find(db_query, sort=[("start", 1), ("chrom", 1)])
# if no results was found
if elements.count() == 0:
msg = f"Did not find gene name: {query}"
LOG.warning(msg)
data = {'message': msg}
response_code = 404
else:
start_elem = elements.next()
end_elem = max(elements, key=lambda elem: elem.get('end'))
data = {
'chromosome': start_elem.get('chrom'),
'start_pos': start_elem.get('start'),
'end_pos': end_elem.get('end'),
'hg_type': start_elem.get('hg_type'),
}
response_code = 200

return jsonify({**data, 'status': response_code})


def get_variant_data(sample_id, variant_category, **optional_kwargs):
"""Search Scout database for variants associated with a case and return info in JSON format."""
default_height_order = 0
Expand Down
7 changes: 3 additions & 4 deletions gens/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@
from datetime import date
from logging.config import dictConfig

import connexion
from flask import abort, render_template, request
from flask_compress import Compress
from flask_debugtoolbar import DebugToolbarExtension

import connexion

from .__version__ import VERSION as version
from .blueprints import gens_bp, about_bp
from .blueprints import about_bp, gens_bp
from .cache import cache
from .db import init_database
from .errors import generic_error, sample_not_found
from .graph import parse_region_str
from .io import BAF_SUFFIX, COV_SUFFIX, _get_filepath
from .utils import get_hg_type
from .errors import generic_error, sample_not_found

toolbar = DebugToolbarExtension()
dictConfig(
Expand Down
2 changes: 1 addition & 1 deletion gens/blueprints/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .gens.views import gens_bp
from .about.views import about_bp
from .gens.views import gens_bp
1 change: 0 additions & 1 deletion gens/blueprints/about/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import gens


LOG = logging.getLogger(__name__)

about_bp = Blueprint("about", __name__, template_folder="templates")
Expand Down
Loading

0 comments on commit f55ba36

Please sign in to comment.