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

Added sankey plot using taxonomy report #96

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 69 additions & 1 deletion backend/alignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,16 @@ type FastaEntry struct {
type SearchResult struct {
Database string `json:"db"`
Alignments interface{} `json:"alignments"`
TaxonomyReport interface{} `json:"taxonomyreport"`
}

type TaxonomyReport struct {
Proportion float64 `json:"proportion"`
CladeReads int `json:"clade_reads"`
TaxonReads int `json:"taxon_reads"`
Rank string `json:"rank"`
TaxonID string `json:"taxon_id"`
ScientificName string `json:"name"`
}

func dbpaths(path string) (string, string) {
Expand Down Expand Up @@ -320,13 +330,71 @@ func ReadAlignments[T any, U interface{ ~uint32 | ~int64 }](id Id, entries []U,
all = append(all, results)
}
reader.Delete()

// Read the taxonomy report
taxonomyReportPath := filepath.Join(base, "alis_" + db + "_report")
taxonomyReport, _ := ReadTaxonomyReport(taxonomyReportPath)

base := filepath.Base(name)
res = append(res, SearchResult{strings.TrimPrefix(base, "alis_"), all})
res = append(res, SearchResult{
strings.TrimPrefix(base, "alis_"),
all,
taxonomyReport, // Include taxonomy report
})
}

return res, nil
}

func ReadTaxonomyReport(filePath string) ([]TaxonomyReport, error) {
file, err := os.Open(filePath)
if err != nil {
// Return an empty report for any error
return []TaxonomyReport{}, nil
}
defer file.Close()

var reports []TaxonomyReport
scanner := bufio.NewScanner(file)

for scanner.Scan() {
line := scanner.Text()
fields := strings.Split(line, "\t")
if len(fields) < 6 {
// Skip invalid lines
continue
}

// Parse the fields
proportion, err := strconv.ParseFloat(fields[0], 64)
if err != nil {
continue
}

cladeReads, err := strconv.Atoi(fields[1])
if err != nil {
continue
}

taxonReads, err := strconv.Atoi(fields[2])
if err != nil {
continue
}

report := TaxonomyReport{
Proportion: proportion,
CladeReads: cladeReads,
TaxonReads: taxonReads,
Rank: fields[3],
TaxonID: fields[4],
ScientificName: strings.TrimSpace(fields[5]),
}
reports = append(reports, report)
}

return reports, nil
}

func Alignments(id Id, entry []int64, databases []string, jobsbase string) ([]SearchResult, error) {
return ReadAlignments[AlignmentEntry, int64](id, entry, databases, jobsbase)
}
Expand Down
9 changes: 6 additions & 3 deletions frontend/ResultView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
<h2 style="margin-top: 0.5em; margin-bottom: 1em; display: inline-block;">
<span style="text-transform: uppercase;">{{ entry.db }}</span> <small>{{ entry.alignments ? Object.values(entry.alignments).length : 0 }} hits</small>
</h2>

<v-btn-toggle mandatory v-model="tableMode" class="ml-auto">
<v-btn>
Graphical
Expand All @@ -106,7 +107,9 @@
</v-btn>
</v-btn-toggle>
</v-flex>

<v-flex v-if="hits.results && hits.results[0].taxonomyreport">
<SankeyDiagram :rawData="hits.results[0].taxonomyreport"></SankeyDiagram>
Copy link
Member

Choose a reason for hiding this comment

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

Does this need a v-if for when hits is still null?

</v-flex>
<table class="v-table result-table" style="position:relativ; margin-bottom: 3em;">
<colgroup>
<template v-if="isComplex">
Expand Down Expand Up @@ -251,6 +254,7 @@
import Panel from './Panel.vue';
import AlignmentPanel from './AlignmentPanel.vue';
import Ruler from './Ruler.vue';
import SankeyDiagram from './SankeyDiagram.vue';

import { debounce } from './lib/debounce';

Expand All @@ -265,7 +269,7 @@ function getAbsOffsetTop($el) {

export default {
name: 'ResultView',
components: { Panel, AlignmentPanel, Ruler },
components: { Panel, AlignmentPanel, Ruler, SankeyDiagram },
data() {
return {
alignment: null,
Expand Down Expand Up @@ -424,7 +428,6 @@ src: url(assets/InconsolataClustal2.woff2),
}
}


.theme--dark {
.result-table {
a:not([href]) {
Expand Down
Loading