Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/imgag/ngs-bits
Browse files Browse the repository at this point in the history
  • Loading branch information
Ott-Alexander committed Feb 22, 2024
2 parents 02f9fff + d60719a commit 87eceb5
Show file tree
Hide file tree
Showing 14 changed files with 127 additions and 65 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linux_machine_gcc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: recursive
- name: Update OS repositories
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/mac_machine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: macos-13
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: recursive
- name: Update submodules
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/windows_machine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
run:
shell: msys2 {0}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: msys2/setup-msys2@v2
with:
msystem: MINGW64
Expand Down
3 changes: 2 additions & 1 deletion doc/GSvar/igv_integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ When IGV initialization was perfomed or when was skipped for the session, the in

### IGV gene track/genome

To generate a custom gene track with all genes from the NGSD to display in IGV you can use the tool `NGSDExportIgvGeneTrack`. This tool will create two gene track text files (one with all genes and one containing only MANE + Clinical transcripts). These files then can be (bg)zipped and manually loaded into IGV. Much easier is it to create a custom IGV genome with our megSAP script [`create_igv_genome.php`](https://github.com/imgag/megSAP/blob/master/src/Tools/create_igv_genome.php) which contains the genes/transcripts from your NGSD, the masked GRCh38 genome and additional tracks. This geneome should then be set in your `GSvar.ini` and then will always be loaded when you use IGV through GSvar.
To generate a custom genome for IGV with all Ensembl transcripts use the megSAP script [`create_igv_genome.php`](https://github.com/imgag/megSAP/blob/master/src/Tools/create_igv_genome.php).
The created JSON genome file must only be set as `igv_genome` in the `GSvar.ini` and then will always be loaded when you use IGV through GSvar.


## FAQ
Expand Down
7 changes: 7 additions & 0 deletions doc/install_win.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,10 @@ To make the tools executable outside *QtCreator* and portable, you have to copy
<td>libmysql.dll</td>
</tr>
</table>

## Building a custom genome for IGV

To generate a custom genome for IGV with all Ensembl transcripts use the megSAP script [`create_igv_genome.php`](https://github.com/imgag/megSAP/blob/master/src/Tools/create_igv_genome.php).
The created JSON genome file must only be set as `igv_genome` in the `GSvar.ini` and then will always be loaded when you use IGV through GSvar.


3 changes: 2 additions & 1 deletion src/GSvar/ImportDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,8 @@ void ImportDialog::addRow(SqlQuery& query, int r)
int c=0;
foreach (const QString& field, db_fields_)
{
QString value = ui_.table->item(r,c)->data(Qt::UserRole).toString();
QTableWidgetItem* item = ui_.table->item(r,c);
QString value = item==nullptr ? "" : item->data(Qt::UserRole).toString();
const TableFieldInfo& field_info = db_.tableInfo(db_table_).fieldInfo(field);
query.bindValue(c, value.isEmpty() && field_info.is_nullable ? QVariant() : value);
++c;
Expand Down
19 changes: 16 additions & 3 deletions src/GSvar/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,10 +467,23 @@ void MainWindow::userSpecificDebugFunction()
}
else if (user=="ahschul1")
{
//Test sample sheet
QString run_id = NGSD().getValue("SELECT id FROM sequencing_run WHERE name='#03178'").toString();
//Extract MANE transcript names
const TranscriptList transcripts = NGSD().transcripts();
const auto matches = NGSHelper::transcriptMatches(GenomeBuild::HG38);


foreach(const Transcript& trans, transcripts)
{
if (!trans.isManeSelectTranscript()) continue;
QByteArray enst = trans.name();
QByteArrayList nm;
foreach (const QByteArray& match, matches[enst])
{
if (match.startsWith("NM_")) nm << match;
}
if (!nm.isEmpty()) qDebug() << enst << nm.join(",");
}

QMessageBox::information(this, "SampleSheet", NGSD().createSampleSheet(run_id.toInt()));
}
else if (user=="ahott1a1")
{
Expand Down
52 changes: 47 additions & 5 deletions src/NGSDExportIgvGeneTrack/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,24 @@ class ConcreteTool
//determine new offset:
cds_offset = (cds_offset + coding_region.length()) % 3;

//update cds status
cds_status = "cmpl";

// if (((trans.strand()==Transcript::MINUS && i==0) || (trans.strand()==Transcript::PLUS && i==(coding_regions.count()-1))) && exon_ranges.size()>0)
// {
// //on first iteration: check if utr and exon are connected
// if (exon_ranges.last()[1] == coding_region.start())
// {
// exon_ranges.last()[1] = coding_region.end();
// exon_ranges.last()[2] = phase;
// continue;
// }
// }

//add (exon) start, end and frame offset
exon_ranges.append(QList<int>() << coding_region.start() << coding_region.end() << phase);

//update cds status
cds_status = "cmpl";


}

Expand All @@ -100,6 +113,16 @@ class ConcreteTool
{
// 5prime UTR LINEs
const BedLine& reg = utr5prime[i];

// if (((trans.strand()==Transcript::MINUS && i==0) || (trans.strand()==Transcript::PLUS && i==(coding_regions.count()-1))) && exon_ranges.size()>0)
// {
// //on first iteration: check if utr and exon are connected
// if (exon_ranges.last()[1] == (reg.start()-1))
// {
// exon_ranges.last()[1] = reg.end();
// continue;
// }
// }
//add (exon) start, end and frame offset
exon_ranges.append(QList<int>() << reg.start() << reg.end() << -1);
}
Expand All @@ -116,11 +139,30 @@ class ConcreteTool

//sort exons by coordinate
std::sort(exon_ranges.begin(), exon_ranges.end(),[](const QList<int>& a, const QList<int>& b)->bool{return a.at(0)<b.at(0);});

//merge regions (and convert to 0-based)
QList<QList<int>> merged_exon_ranges;
foreach(QList<int> exon, exon_ranges)
{
if (merged_exon_ranges.size() > 0)
{
if (merged_exon_ranges.last()[1] == (exon[0]-1))
{
merged_exon_ranges.last()[1] = exon[1];
merged_exon_ranges.last()[2] = std::max(merged_exon_ranges.last()[2], exon[2]);
continue;
}
}
exon[0] -= 1; //convert to 0-based
merged_exon_ranges.append(exon);
}


//format for columns
QByteArray exon_starts, exon_ends, exon_frames;
foreach(const QList<int>& exon, exon_ranges)
foreach(const QList<int>& exon, merged_exon_ranges)
{
exon_starts += QByteArray::number(exon.at(0)-1) + ","; // convert to 0-based
exon_starts += QByteArray::number(exon.at(0)) + ",";
exon_ends += QByteArray::number(exon.at(1)) + ",";
exon_frames += QByteArray::number(exon.at(2)) + ",";
}
Expand All @@ -136,7 +178,7 @@ class ConcreteTool
line.append(QByteArray::number(trans.end()));
line.append(cds_start);
line.append(cds_end);
line.append(QByteArray::number(exon_ranges.size()));
line.append(QByteArray::number(merged_exon_ranges.size()));
line.append(exon_starts);
line.append(exon_ends);
line.append("0"); //score
Expand Down
4 changes: 2 additions & 2 deletions src/cppREST/EndpointManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ HttpResponse EndpointManager::getUserTokenAuthStatus(const HttpRequest& request)
return HttpResponse(ResponseStatus::FORBIDDEN, HttpUtils::detectErrorContentType(request.getHeaderByName("User-Agent")), "You are not authorized with a valid user token");
}

if (SessionManager::isSessionExpired(getTokenIfAvailable(request)))
if (SessionManager::isSessionExpired(SessionManager::getSessionBySecureToken(getTokenIfAvailable(request))))
{
return HttpResponse(ResponseStatus::REQUEST_TIMEOUT, request.getContentType(), EndpointManager::formatResponseMessage(request, "Secure token has expired"));
}
Expand All @@ -105,7 +105,7 @@ HttpResponse EndpointManager::getDbTokenAuthStatus(const HttpRequest& request)
return HttpResponse(ResponseStatus::FORBIDDEN, HttpUtils::detectErrorContentType(request.getHeaderByName("User-Agent")), EndpointManager::formatResponseMessage(request, "You are not authorized with a valid database token"));
}

if (SessionManager::isSessionExpired(request.getFormUrlEncoded()["dbtoken"]))
if (SessionManager::isSessionExpired(SessionManager::getSessionBySecureToken(request.getFormUrlEncoded()["dbtoken"])))
{
return HttpResponse(ResponseStatus::REQUEST_TIMEOUT, request.getContentType(), EndpointManager::formatResponseMessage(request, "Database token has expired"));
}
Expand Down
57 changes: 25 additions & 32 deletions src/cppREST/SessionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,31 +56,31 @@ void SessionManager::addNewSession(QString id, Session in)

void SessionManager::removeSession(QString id)
{
if (instance().session_store_.contains(id))
{
instance().mutex_.lock();
instance().session_store_.remove(id);
instance().mutex_.unlock();
}
instance().mutex_.lock();
if (instance().session_store_.contains(id))
{
instance().session_store_.remove(id);
}
instance().mutex_.unlock();
}

Session SessionManager::getSessionBySecureToken(QString token)
{
QMapIterator<QString, Session> i(instance().session_store_);
while (i.hasNext())
{
i.next();
if (i.key() == token)
{
return i.value();
}
}
return Session();
Session found_session = {};
instance().mutex_.lock();
if (instance().session_store_.contains(token))
{
found_session = instance().session_store_[token];
}
instance().mutex_.unlock();
return found_session;
}

bool SessionManager::isSessionExpired(Session in)
{
// Session lifetime in seconds
if (in.isEmpty()) return false;

// Session lifetime in seconds
qint64 valid_period = ServerHelper::getNumSettingsValue("session_duration");
if (valid_period == 0) valid_period = DEFAULT_VALID_PERIOD; // default value, if not set in the config
if (in.login_time.addSecs(valid_period).toSecsSinceEpoch() < QDateTime::currentDateTime().toSecsSinceEpoch())
Expand All @@ -90,23 +90,16 @@ bool SessionManager::isSessionExpired(Session in)
return false;
}

bool SessionManager::isSessionExpired(QString token)
{
return isSessionExpired(getSessionBySecureToken(token));
}

bool SessionManager::isTokenReal(QString token)
{
QMapIterator<QString, Session> i(instance().session_store_);
while (i.hasNext())
{
i.next();
if (i.key() == token)
{
return true;
}
}
return false;
bool is_real = false;
instance().mutex_.lock();
if (instance().session_store_.contains(token))
{
is_real = true;
}
instance().mutex_.unlock();
return is_real;
}

QMap<QString, Session> SessionManager::removeExpiredSessions()
Expand Down
3 changes: 1 addition & 2 deletions src/cppREST/SessionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ class CPPRESTSHARED_EXPORT SessionManager
static void addNewSession(QString id, Session in);
static void removeSession(QString id);
static Session getSessionBySecureToken(QString token);
static bool isSessionExpired(Session in);
static bool isSessionExpired(QString token);
static bool isSessionExpired(Session in);

static bool isTokenReal(QString token);
static QMap<QString, Session> removeExpiredSessions();
Expand Down
28 changes: 17 additions & 11 deletions src/cppREST/UrlManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,36 +56,42 @@ void UrlManager::addNewUrl(QString id, UrlEntity in)

void UrlManager::removeUrl(const QString& id)
{
if (instance().url_storage_.contains(id))
{
instance().mutex_.lock();
instance().url_storage_.remove(id);
instance().mutex_.unlock();
instance().mutex_.lock();
if (instance().url_storage_.contains(id))
{
instance().url_storage_.remove(id);
}
instance().mutex_.unlock();
}

bool UrlManager::isInStorageAlready(const QString& filename_with_path)
{
QMapIterator<QString, UrlEntity> i(instance().url_storage_);
bool is_found = false;
instance().mutex_.lock();
QMapIterator<QString, UrlEntity> i(instance().url_storage_);
while (i.hasNext())
{
i.next();
if (i.value().filename_with_path == filename_with_path)
{
return true;
is_found = true;
}
}
instance().mutex_.unlock();

return false;
return is_found;
}

UrlEntity UrlManager::getURLById(const QString& id)
{
if (instance().url_storage_.contains(id))
UrlEntity found_entity = {};
instance().mutex_.lock();
if (instance().url_storage_.contains(id))
{
return instance().url_storage_[id];
found_entity = instance().url_storage_[id];
}
return UrlEntity{};
instance().mutex_.unlock();
return found_entity;
}

bool UrlManager::isUrlExpired(UrlEntity in)
Expand Down
6 changes: 3 additions & 3 deletions src/tools-TEST/data_out/NGSDExportIgvGeneTrack_out1.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
0 ENST00000352993 chr17 + 43044294 43125370 43045677 43124096 24 43044294,43045677,43047642,43049120,43051062,43057051,43063332,43063873,43067607,43070927,43074330,43076487,43082403,43090943,43095845,43097243,43099774,43104121,43104867,43106455,43115725,43124016,43124096,43125270, 43045677,43045802,43047703,43049194,43051117,43057135,43063373,43063951,43067695,43071238,43074521,43076614,43082575,43091032,43095922,43097289,43099880,43104261,43104956,43106533,43115779,43124096,43124115,43125370, 0 BRCA1 cmpl cmpl -1,0,2,0,2,0,0,2,2,0,2,1,2,0,2,1,2,0,2,1,1,1,-1,-1,
0 ENST00000591534 chr17 + 43045562 43125329 43045677 43074478 13 43045562,43045677,43047642,43049120,43051062,43057051,43063332,43063873,43067607,43070927,43074330,43074478,43125270, 43045677,43045802,43047703,43049194,43051117,43057135,43063373,43063951,43067695,43071238,43074478,43074521,43125329, 0 BRCA1 cmpl cmpl -1,0,2,0,2,0,0,2,2,0,2,-1,-1,
0 ENST00000352993 chr17 + 43044294 43125370 43045677 43124096 22 43044294,43047642,43049120,43051062,43057051,43063332,43063873,43067607,43070927,43074330,43076487,43082403,43090943,43095845,43097243,43099774,43104121,43104867,43106455,43115725,43124016,43125270, 43045802,43047703,43049194,43051117,43057135,43063373,43063951,43067695,43071238,43074521,43076614,43082575,43091032,43095922,43097289,43099880,43104261,43104956,43106533,43115779,43124115,43125370, 0 BRCA1 cmpl cmpl 0,2,0,2,0,0,2,2,0,2,1,2,0,2,1,2,0,2,1,1,1,-1,
0 ENST00000591534 chr17 + 43045562 43125329 43045677 43074478 11 43045562,43047642,43049120,43051062,43057051,43063332,43063873,43067607,43070927,43074330,43125270, 43045802,43047703,43049194,43051117,43057135,43063373,43063951,43067695,43071238,43074521,43125329, 0 BRCA1 cmpl cmpl 0,2,0,2,0,0,2,2,0,2,-1,
0 CCDS11459, ENST00000493795 chr17 + 43045677 43106526 43045677 43106526 20 43045677,43047642,43049120,43051062,43057051,43063332,43063873,43067607,43070927,43074330,43076487,43082403,43090943,43091434,43095845,43097243,43099774,43104121,43104867,43106455, 43045802,43047703,43049194,43051117,43057135,43063373,43063951,43067695,43071238,43074521,43076614,43082575,43091032,43094860,43095922,43097289,43099880,43104261,43104956,43106526, 0 BRCA1 cmpl cmpl 0,2,0,2,0,0,2,2,0,2,1,2,0,2,2,1,2,0,2,1,
0 CCDS11453, ENST00000357654 chr17 - 43045677 43124096 43045677 43124096 22 43045677,43047642,43049120,43051062,43057051,43063332,43063873,43067607,43070927,43074330,43076487,43082403,43090943,43091434,43095845,43097243,43099774,43104121,43104867,43106455,43115725,43124016, 43045802,43047703,43049194,43051117,43057135,43063373,43063951,43067695,43071238,43074521,43076614,43082575,43091032,43094860,43095922,43097289,43099880,43104261,43104956,43106533,43115779,43124096, 0 BRCA1 cmpl cmpl 1,0,1,0,0,1,1,0,1,2,1,0,1,1,2,1,0,1,2,2,2,0,
0 ENST00000354071 chr17 + 43091097 43125315 43091330 43124096 12 43091097,43091330,43095845,43097243,43099774,43104121,43104867,43106455,43115725,43124016,43124096,43125270, 43091330,43094860,43095922,43097289,43099880,43104261,43104956,43106533,43115779,43124096,43124115,43125315, 0 BRCA1 cmpl cmpl -1,0,2,1,2,0,2,1,1,1,-1,-1,
0 ENST00000354071 chr17 + 43091097 43125315 43091330 43124096 10 43091097,43095845,43097243,43099774,43104121,43104867,43106455,43115725,43124016,43125270, 43094860,43095922,43097289,43099880,43104261,43104956,43106533,43115779,43124115,43125315, 0 BRCA1 cmpl cmpl 0,2,1,2,0,2,1,1,1,-1,
4 changes: 2 additions & 2 deletions src/tools-TEST/data_out/NGSDExportIgvGeneTrack_out2.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
0 ENST00000591534 chr17 + 43045562 43125329 43045677 43074478 13 43045562,43045677,43047642,43049120,43051062,43057051,43063332,43063873,43067607,43070927,43074330,43074478,43125270, 43045677,43045802,43047703,43049194,43051117,43057135,43063373,43063951,43067695,43071238,43074478,43074521,43125329, 0 BRCA1 cmpl cmpl -1,0,2,0,2,0,0,2,2,0,2,-1,-1,
0 ENST00000354071 chr17 + 43091097 43125315 43091330 43124096 12 43091097,43091330,43095845,43097243,43099774,43104121,43104867,43106455,43115725,43124016,43124096,43125270, 43091330,43094860,43095922,43097289,43099880,43104261,43104956,43106533,43115779,43124096,43124115,43125315, 0 BRCA1 cmpl cmpl -1,0,2,1,2,0,2,1,1,1,-1,-1,
0 ENST00000591534 chr17 + 43045562 43125329 43045677 43074478 11 43045562,43047642,43049120,43051062,43057051,43063332,43063873,43067607,43070927,43074330,43125270, 43045802,43047703,43049194,43051117,43057135,43063373,43063951,43067695,43071238,43074521,43125329, 0 BRCA1 cmpl cmpl 0,2,0,2,0,0,2,2,0,2,-1,
0 ENST00000354071 chr17 + 43091097 43125315 43091330 43124096 10 43091097,43095845,43097243,43099774,43104121,43104867,43106455,43115725,43124016,43125270, 43094860,43095922,43097289,43099880,43104261,43104956,43106533,43115779,43124115,43125315, 0 BRCA1 cmpl cmpl 0,2,1,2,0,2,1,1,1,-1,

0 comments on commit 87eceb5

Please sign in to comment.