-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from glycojones/torsion_plots
Adding torsion plots to GlycanDetail display
- Loading branch information
Showing
8 changed files
with
272 additions
and
164 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { useEffect, useState } from "react"; | ||
import TorsionPlot from "./TorsionPlot"; | ||
|
||
|
||
function sortTorsions(torsions) { | ||
const linkage_set = new Set(); | ||
|
||
torsions.map((torsion) => { | ||
let linkage_string = "" | ||
if (torsion.sugar_1 == "ASN") { | ||
linkage_string = torsion.sugar_1 + "-" + torsion.atom_number_2 + "," + torsion.atom_number_1 + "-" + torsion.sugar_2 | ||
} | ||
else { | ||
linkage_string = torsion.sugar_2 + "-" + torsion.atom_number_2 + "," + torsion.atom_number_1 + "-" + torsion.sugar_1 | ||
} | ||
linkage_set.add(linkage_string) | ||
}) | ||
|
||
const linkage_array = Array.from(linkage_set) | ||
|
||
const sorted_linkage_array = {} | ||
|
||
linkage_array.map((item) => { | ||
sorted_linkage_array[item] = [] | ||
}) | ||
|
||
torsions.map((torsion) => { | ||
let linkage_string = "" | ||
if (torsion.sugar_1 == "ASN") { | ||
linkage_string = torsion.sugar_1 + "-" + torsion.atom_number_2 + "," + torsion.atom_number_1 + "-" + torsion.sugar_2 | ||
} | ||
else { | ||
linkage_string = torsion.sugar_2 + "-" + torsion.atom_number_2 + "," + torsion.atom_number_1 + "-" + torsion.sugar_1 | ||
} | ||
|
||
sorted_linkage_array[linkage_string].push({"phi": torsion.phi, "psi": torsion.psi}) | ||
}) | ||
|
||
return [linkage_array, sorted_linkage_array] | ||
} | ||
|
||
function TorsionMultiPlotTabs({torsions, setTab}) { | ||
|
||
const [linkage_array, sorted_linkage_array] = sortTorsions(torsions) | ||
|
||
return ( | ||
linkage_array.map((item, index) => { | ||
return ( | ||
|
||
<li class="mr-2"> | ||
<button class="inline-block p-4 border-b-2 border-transparent border-secondary rounded-t-lg hover:scale-105" onClick={() => {setTab(index)}}>{item}</button> | ||
</li> | ||
|
||
) | ||
}) | ||
) | ||
} | ||
|
||
export default function TorsionMultiPlot({torsions, tab, setTab}) { | ||
|
||
|
||
const [linkage_array, sorted_linkage_array] = sortTorsions(torsions) | ||
|
||
useEffect(() => { | ||
console.log(tab) | ||
setTab(0) | ||
}, []) | ||
|
||
return ( | ||
<div className="flex flex-col align-middle justify-center items-center space-y-6 "> | ||
<div class="text-sm font-medium text-center text-gray-500 border-gray-200 text-gray-400 border-gray-700"> | ||
<ul class="flex flex-wrap -mb-px"> | ||
<TorsionMultiPlotTabs torsions={torsions} setTab={setTab}/> | ||
</ul> | ||
</div> | ||
|
||
<TorsionPlot linkage_type={linkage_array[tab]} sorted_torsion_list={sorted_linkage_array}/> | ||
</div> | ||
) | ||
} |
Oops, something went wrong.