|
| 1 | +import Vue from "vue"; |
| 2 | +import Template from "./template.vue"; |
| 3 | + |
| 4 | +import "../../css/f-layout.css"; |
| 5 | +import "../../css/sysbio.css"; |
| 6 | + |
| 7 | +import { sysbioMixin } from "../../mixins/sysbioMixin.js"; |
| 8 | + |
| 9 | +new Vue({ |
| 10 | + mixins: [sysbioMixin], |
| 11 | + data() { |
| 12 | + return { |
| 13 | + convertedData: null, |
| 14 | + rawTsvData: `source_short field category n_donors |
| 15 | +CMD case_control Case 111 |
| 16 | +CMD case_control Unknown 80 |
| 17 | +CMD case_control Control 63 |
| 18 | +DiverseCohorts case_control Unknown 62 |
| 19 | +DiverseCohorts case_control Case 53 |
| 20 | +DiverseCohorts case_control Control 52 |
| 21 | +Mitrosmap case_control Control 23 |
| 22 | +Mitrosmap case_control Case 16 |
| 23 | +Mitrosmap case_control Unknown 9 |
| 24 | +PD case_control Case 69 |
| 25 | +PD case_control Control 24 |
| 26 | +PD case_control Unknown 4 |
| 27 | +RASLE case_control Case 156 |
| 28 | +RASLE case_control Control 30 |
| 29 | +ROSMAP case_control Unknown 153 |
| 30 | +ROSMAP case_control Control 152 |
| 31 | +ROSMAP case_control Case 146 |
| 32 | +CMD disease Unknown 106 |
| 33 | +CMD disease chronic kidney disease 37 |
| 34 | +CMD disease normal 37 |
| 35 | +CMD disease MASL 25 |
| 36 | +CMD disease MASH 23 |
| 37 | +CMD disease acute kidney failure 14 |
| 38 | +CMD disease MetALD 12 |
| 39 | +DiverseCohorts disease Unknown 125 |
| 40 | +DiverseCohorts disease MCI 42 |
| 41 | +Mitrosmap disease Unknown 48 |
| 42 | +PD disease Parkinson's Disease 69 |
| 43 | +PD disease No PD Nor Other Neurological Disorder 24 |
| 44 | +PD disease Parkinsonism 3 |
| 45 | +PD disease Dementia With Lewy Bodies 1 |
| 46 | +RASLE disease SLE 156 |
| 47 | +RASLE disease Unknown 30 |
| 48 | +ROSMAP disease Unknown 451 |
| 49 | +CMD ethnicity Unknown 199 |
| 50 | +CMD ethnicity Caucasian 55 |
| 51 | +DiverseCohorts ethnicity Unknown 167 |
| 52 | +Mitrosmap ethnicity Unknown 48 |
| 53 | +PD ethnicity Unknown 97 |
| 54 | +RASLE ethnicity Unknown 186 |
| 55 | +ROSMAP ethnicity Unknown 451 |
| 56 | +CMD race Unknown 180 |
| 57 | +CMD race White 52 |
| 58 | +CMD race Black or African-American 15 |
| 59 | +CMD race Asian 4 |
| 60 | +CMD race Other 2 |
| 61 | +CMD race White-Other 1 |
| 62 | +DiverseCohorts race Unknown 167 |
| 63 | +Mitrosmap race Unknown 48 |
| 64 | +PD race Unknown 97 |
| 65 | +RASLE race Unknown 186 |
| 66 | +ROSMAP race Unknown 451 |
| 67 | +CMD sex Male 92 |
| 68 | +CMD sex Female 82 |
| 69 | +CMD sex Unknown 80 |
| 70 | +DiverseCohorts sex Female 109 |
| 71 | +DiverseCohorts sex Male 58 |
| 72 | +Mitrosmap sex Female 24 |
| 73 | +Mitrosmap sex Male 24 |
| 74 | +PD sex Unknown 97 |
| 75 | +RASLE sex Unknown 186 |
| 76 | +ROSMAP sex Female 304 |
| 77 | +ROSMAP sex Male 146 |
| 78 | +ROSMAP sex Unknown 1 |
| 79 | +`, |
| 80 | + }; |
| 81 | + }, |
| 82 | + mounted() { |
| 83 | + this.convertedData = this.convertTsvToJson(this.rawTsvData); |
| 84 | + console.log("convertedData", this.convertedData); |
| 85 | + }, |
| 86 | + computed: {}, |
| 87 | + methods: { |
| 88 | + /** |
| 89 | + * Converts TSV (source_short, field, category, n_donors) into nested object: |
| 90 | + * { [source_short]: { [field]: { [category]: n_donors, ... }, ... }, ... } |
| 91 | + */ |
| 92 | + convertTsvToJson(rawTsvData) { |
| 93 | + const text = (rawTsvData || "").trim(); |
| 94 | + if (!text) return {}; |
| 95 | + const lines = text.split(/\r?\n/).filter((line) => line.trim()); |
| 96 | + if (lines.length < 2) return {}; |
| 97 | + const header = lines[0].split("\t").map((h) => h.trim()); |
| 98 | + const srcIdx = header.indexOf("source_short"); |
| 99 | + const fieldIdx = header.indexOf("field"); |
| 100 | + const categoryIdx = header.indexOf("category"); |
| 101 | + const nDonorsIdx = header.indexOf("n_donors"); |
| 102 | + if (srcIdx === -1 || fieldIdx === -1 || categoryIdx === -1 || nDonorsIdx === -1) { |
| 103 | + return {}; |
| 104 | + } |
| 105 | + const out = {}; |
| 106 | + for (let i = 1; i < lines.length; i++) { |
| 107 | + const cols = lines[i].split("\t"); |
| 108 | + const sourceShort = cols[srcIdx] != null ? String(cols[srcIdx]).trim() : ""; |
| 109 | + const field = cols[fieldIdx] != null ? String(cols[fieldIdx]).trim() : ""; |
| 110 | + const category = cols[categoryIdx] != null ? String(cols[categoryIdx]).trim() : ""; |
| 111 | + const nDonors = cols[nDonorsIdx] != null ? parseInt(cols[nDonorsIdx], 10) : 0; |
| 112 | + if (!sourceShort || !field) continue; |
| 113 | + if (!out[sourceShort]) out[sourceShort] = {}; |
| 114 | + if (!out[sourceShort][field]) out[sourceShort][field] = {}; |
| 115 | + out[sourceShort][field][category] = isNaN(nDonors) ? 0 : nDonors; |
| 116 | + } |
| 117 | + return out; |
| 118 | + }, |
| 119 | + }, |
| 120 | + render(h) { |
| 121 | + return h(Template); |
| 122 | + }, |
| 123 | +}).$mount("#app"); |
0 commit comments