From 96abd34657973418001c6473be2951f773600c52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sunny=20=28SunJae=29=20Lee=20=EC=9D=B4=EC=84=A0=EC=9E=AC?= Date: Mon, 9 Dec 2024 15:34:19 +0900 Subject: [PATCH 1/9] added taxonomyreport data to hits results --- backend/alignment.go | 75 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) diff --git a/backend/alignment.go b/backend/alignment.go index aed2a9c..3b4ca72 100644 --- a/backend/alignment.go +++ b/backend/alignment.go @@ -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:"cladeReads"` + TaxonReads int `json:"taxonReads"` + Rank string `json:"rank"` + TaxonID string `json:"taxonId"` + ScientificName string `json:"scientificName"` } func dbpaths(path string) (string, string) { @@ -320,13 +330,76 @@ 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_afsp_report") + taxonomyReport, err := ReadTaxonomyReport(taxonomyReportPath) + if err != nil { + return res, err + } + 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 nil, err + } + 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 { + return nil + } + + // Parse the fields + proportion, err := strconv.ParseFloat(fields[0], 64) + if err != nil { + return nil, err + } + + cladeReads, err := strconv.Atoi(fields[1]) + if err != nil { + return nil, err + } + + taxonReads, err := strconv.Atoi(fields[2]) + if err != nil { + return nil, err + } + + report := TaxonomyReport{ + Proportion: proportion, + CladeReads: cladeReads, + TaxonReads: taxonReads, + Rank: fields[3], + TaxonID: fields[4], + ScientificName: strings.TrimSpace(fields[5]), + } + reports = append(reports, report) + } + + if err := scanner.Err(); err != nil { + return nil, err + } + + return reports, nil +} + func Alignments(id Id, entry []int64, databases []string, jobsbase string) ([]SearchResult, error) { return ReadAlignments[AlignmentEntry, int64](id, entry, databases, jobsbase) } From adbd9c02b38d5bc3e808dae8b7e1c3383657515d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sunny=20=28SunJae=29=20Lee=20=EC=9D=B4=EC=84=A0=EC=9E=AC?= Date: Sun, 22 Dec 2024 17:00:17 +0900 Subject: [PATCH 2/9] Added svg canvas for rendering sankey --- backend/alignment.go | 10 +- frontend/ResultView.vue | 8 +- frontend/SankeyDiagram.vue | 724 +++++++++++++++++++++++++++++++++++++ frontend/rankUtils.js | 75 ++++ 4 files changed, 809 insertions(+), 8 deletions(-) create mode 100644 frontend/SankeyDiagram.vue create mode 100644 frontend/rankUtils.js diff --git a/backend/alignment.go b/backend/alignment.go index 3b4ca72..4f7bce1 100644 --- a/backend/alignment.go +++ b/backend/alignment.go @@ -195,11 +195,11 @@ type SearchResult struct { type TaxonomyReport struct { Proportion float64 `json:"proportion"` - CladeReads int `json:"cladeReads"` - TaxonReads int `json:"taxonReads"` + CladeReads int `json:"clade_reads"` + TaxonReads int `json:"taxon_reads"` Rank string `json:"rank"` - TaxonID string `json:"taxonId"` - ScientificName string `json:"scientificName"` + TaxonID string `json:"taxon_id"` + ScientificName string `json:"name"` } func dbpaths(path string) (string, string) { @@ -363,7 +363,7 @@ func ReadTaxonomyReport(filePath string) ([]TaxonomyReport, error) { line := scanner.Text() fields := strings.Split(line, "\t") if len(fields) < 6 { - return nil + return nil, err } // Parse the fields diff --git a/frontend/ResultView.vue b/frontend/ResultView.vue index 348f7ac..c0eb647 100644 --- a/frontend/ResultView.vue +++ b/frontend/ResultView.vue @@ -106,7 +106,9 @@ - + + +