Skip to content

Commit 50cdc3a

Browse files
committed
Basic codon alignment example.
1 parent fcb1a23 commit 50cdc3a

File tree

7 files changed

+138
-133
lines changed

7 files changed

+138
-133
lines changed

src/app.jsx

+2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ function FASTALinks(props) {
5757
<Link to="/fasta-viewer" header="Viewer" />
5858
<Divider header="Examples" />
5959
<Link to="/fasta-aminoacid" header="Amino acid alignment" />
60+
<Link to="/fasta-codon" header="Codon alignment" />
6061
<Link to="/fasta-highlight" header="Highlight individual sites" />
6162
<Link to="/fasta-start" header="Start at a given sequence and site" />
6263
<Link to="/fasta-lowercase" header="Lower case alignment" />
@@ -127,6 +128,7 @@ class App extends Component {
127128

128129
<Route path="/fasta-viewer" render={props => <FASTA.FASTAViewer />} />
129130
<Route path="/fasta-aminoacid" component={FASTA.AminoAcid} />
131+
<Route path="/fasta-codon" component={FASTA.Codon} />
130132
<Route path="/fasta-highlight" component={FASTA.Highlight} />
131133
<Route path="/fasta-start" component={FASTA.StartAtSiteAndSequence} />
132134
<Route path="/fasta-lowercase" component={FASTA.Lowercase} />

src/app/FASTA.jsx

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Modal from "./Modal.jsx";
1111
import SVGAlignment from "../SVGAlignment.jsx";
1212
import { nucleotide_color, nucleotide_difference } from "../helpers/colors";
1313
import AminoAcid from "./FASTA/amino_acid.jsx";
14+
import Codon from "./FASTA/codon.jsx";
1415
import Highlight from "./FASTA/highlight.jsx";
1516
import SVGAlignmentExample from "./FASTA/svg_example.jsx";
1617
import StartAtSiteAndSequence from "./FASTA/start_at_site_and_sequence.jsx";
@@ -188,6 +189,7 @@ class FASTAViewer extends Component {
188189
export {
189190
FASTAViewer,
190191
AminoAcid,
192+
Codon,
191193
Highlight,
192194
StartAtSiteAndSequence,
193195
Lowercase,

src/app/FASTA/codon.jsx

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import React, { Component } from "react";
2+
import { text } from "d3";
3+
4+
import Alignment from "../../Alignment.jsx";
5+
import fastaParser from "../../helpers/fasta.js";
6+
import { codon_colorer } from "../../helpers/colors.js";
7+
8+
class Codon extends Component {
9+
constructor(props) {
10+
super(props);
11+
this.state = {
12+
sequence_data: null
13+
};
14+
}
15+
componentDidMount() {
16+
text("data/CD2.fasta").then(data => {
17+
const sequence_data = fastaParser(data);
18+
this.setState({ sequence_data });
19+
});
20+
}
21+
render() {
22+
const { sequence_data } = this.state;
23+
if (!sequence_data) return <div />;
24+
return (
25+
<div>
26+
<div>
27+
<h1>Codon Alignment</h1>
28+
</div>
29+
<Alignment
30+
fasta={sequence_data}
31+
site_color={codon_colorer(sequence_data)}
32+
/>
33+
</div>
34+
);
35+
}
36+
}
37+
38+
export default Codon;

src/components/BaseAlignment.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class BaseAlignment extends Component {
7878
y = site_size * (d.i - 1),
7979
mol = molecule(d.mol, d.j, d.header);
8080
context.beginPath();
81-
context.fillStyle = site_color(d.mol, d.j, d.header);
81+
context.fillStyle = site_color(d.mol, d.j, d.header, d.i);
8282
context.rect(x, y, site_size, site_size);
8383
context.fill();
8484
context.fillStyle = text_color(d.mol, d.j, d.header);

src/helpers/colors.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import translation from "./translation.js";
2+
13
const ambiguous_color = "DarkGrey",
24
ambiguous_text_color = "black";
35

@@ -137,6 +139,20 @@ const nucleotide_colors = {
137139
if (header == desired_header) return desired_color;
138140
return mol == desired_sequence[site - 1] ? "white" : desired_color;
139141
};
142+
},
143+
codon_colorer = (sequence_data, site_color) => {
144+
site_color = site_color || amino_acid_color;
145+
return (character, position, header, seq_index) => {
146+
if (character == "-") return amino_acid_colors["-"];
147+
const codon_start = 3 * Math.floor((position - 1) / 3),
148+
sequence = sequence_data[seq_index - 1].seq,
149+
first_nuc = sequence[codon_start],
150+
second_nuc = sequence[codon_start + 1],
151+
third_nuc = sequence[codon_start + 2],
152+
codon = first_nuc + second_nuc + third_nuc,
153+
amino_acid = translation[codon];
154+
return site_color(amino_acid);
155+
};
140156
};
141157

142158
export {
@@ -146,5 +162,6 @@ export {
146162
nucleotide_difference,
147163
amino_acid_color,
148164
amino_acid_colors,
149-
amino_acid_text_color
165+
amino_acid_text_color,
166+
codon_colorer
150167
};

src/helpers/translation.js

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
export default {
2+
AAA: "K",
3+
AAC: "N",
4+
AAG: "K",
5+
AAT: "N",
6+
ACA: "T",
7+
ACC: "T",
8+
ACG: "T",
9+
ACT: "T",
10+
AGA: "R",
11+
AGC: "S",
12+
AGG: "R",
13+
AGT: "S",
14+
ATA: "I",
15+
ATC: "I",
16+
ATG: "M",
17+
ATT: "I",
18+
CAA: "Q",
19+
CAC: "H",
20+
CAG: "Q",
21+
CAT: "H",
22+
CCA: "P",
23+
CCC: "P",
24+
CCG: "P",
25+
CCT: "P",
26+
CGA: "R",
27+
CGC: "R",
28+
CGG: "R",
29+
CGT: "R",
30+
CTA: "L",
31+
CTC: "L",
32+
CTG: "L",
33+
CTT: "L",
34+
GAA: "E",
35+
GAC: "D",
36+
GAG: "E",
37+
GAT: "D",
38+
GCA: "A",
39+
GCC: "A",
40+
GCG: "A",
41+
GCT: "A",
42+
GGA: "G",
43+
GGC: "G",
44+
GGG: "G",
45+
GGT: "G",
46+
GTA: "V",
47+
GTC: "V",
48+
GTG: "V",
49+
GTT: "V",
50+
TAA: "*",
51+
TAC: "Y",
52+
TAG: "*",
53+
TAT: "Y",
54+
TCA: "S",
55+
TCC: "S",
56+
TCG: "S",
57+
TCT: "S",
58+
TGA: "*",
59+
TGC: "C",
60+
TGG: "W",
61+
TGT: "C",
62+
TTA: "L",
63+
TTC: "F",
64+
TTG: "L",
65+
TTT: "F"
66+
};

0 commit comments

Comments
 (0)