Skip to content

Commit

Permalink
Merge pull request #33 from theosanderson/sweep/refactor/color-and-co…
Browse files Browse the repository at this point in the history
…don-mapping

Refactor getColor and codon mapping into separate files
  • Loading branch information
theosanderson authored Aug 3, 2023
2 parents c35a32b + 3d28ae0 commit 8391e35
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 154 deletions.
157 changes: 3 additions & 154 deletions src/components/SingleRow.jsx
Original file line number Diff line number Diff line change
@@ -1,160 +1,9 @@
import ColorHash from "color-hash";
import { getReverseComplement, filterFeatures } from "../utils";
import { getReverseComplement, filterFeatures, } from "../utils";
import getColor from "../utils/getColor";
import codonToAminoAcid from "../utils/codonMapping";
var colorHash = new ColorHash({ lightness: [0.75, 0.9, 0.7, 0.8] });

const getColor = (feature, product) => {
switch (feature.type) {
case "CDS":
switch (feature.name) {
case "S":
return "#ff7373";
case "nsp3":
return "#d3ffce";

case "leader":
return "#ff7f50";

case "nsp2":
return "#ddffdd";

case "nsp4":
return "#ff7373";

case "N":
return "#7fffd4";
case "E":
return "#ff7f50";
case "M":
return "#eeee88";
case "nsp12; RdRp":
return "#ff7f50";
case "nsp6":
return "#ee99ee";
case "nsp7":
return "#99ee99";

case "nsp8":
return "#ff7373";
case "nsp10":
return "#d3ffce";

case "nsp14":
return "#ff7f50";
case "nsp15":
return "#ddffdd";
case "nsp16":
return "#ffeeee";
case "nsp13":
return "#ff7f50";

default:
return colorHash.hex(feature.name + product + feature.type);
}
case "gene":
return "blue";
case "misc_feature":
return "green";
case "5'UTR":
return "orange";
case "3'UTR":
return "orange";
default:
return colorHash.hex(feature.name + product + feature.type);
}
};

const codonToAminoAcid = (codon) => {
switch (codon) {
case "TTT":
case "TTC":
return "F";
case "TTA":
case "TTG":
case "CTT":
case "CTC":
case "CTA":
case "CTG":
return "L";
case "ATT":
case "ATC":
case "ATA":
return "I";
case "ATG":
return "M";
case "GTT":
case "GTC":
case "GTA":
case "GTG":
return "V";
case "TCT":
case "TCC":
case "TCA":
case "TCG":
case "AGT":
case "AGC":
return "S";
case "CCT":
case "CCC":
case "CCA":
case "CCG":
return "P";
case "ACT":
case "ACC":
case "ACA":
case "ACG":
return "T";
case "GCT":
case "GCC":
case "GCA":
case "GCG":
return "A";
case "TAT":
case "TAC":
return "Y";
case "TAA":
case "TAG":
case "TGA":
return "*";
case "CAT":
case "CAC":
return "H";
case "CAA":
case "CAG":
return "Q";
case "AAT":
case "AAC":
return "N";
case "AAA":
case "AAG":
return "K";
case "GAT":
case "GAC":
return "D";
case "GAA":
case "GAG":
return "E";
case "TGT":
case "TGC":
return "C";
case "TGG":
return "W";
case "CGT":
case "CGC":
case "CGA":
case "CGG":
case "AGA":
case "AGG":
return "R";
case "GGT":
case "GGC":
case "GGA":
case "GGG":
return "G";
default:
return "X";
}
};

const SingleRow = ({
parsedSequence,
rowStart,
Expand Down
93 changes: 93 additions & 0 deletions src/utils/codonMapping.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
const codonToAminoAcid = (codon) => {
switch (codon) {
case "TTT":
case "TTC":
return "F";
case "TTA":
case "TTG":
case "CTT":
case "CTC":
case "CTA":
case "CTG":
return "L";
case "ATT":
case "ATC":
case "ATA":
return "I";
case "ATG":
return "M";
case "GTT":
case "GTC":
case "GTA":
case "GTG":
return "V";
case "TCT":
case "TCC":
case "TCA":
case "TCG":
case "AGT":
case "AGC":
return "S";
case "CCT":
case "CCC":
case "CCA":
case "CCG":
return "P";
case "ACT":
case "ACC":
case "ACA":
case "ACG":
return "T";
case "GCT":
case "GCC":
case "GCA":
case "GCG":
return "A";
case "TAT":
case "TAC":
return "Y";
case "TAA":
case "TAG":
case "TGA":
return "*";
case "CAT":
case "CAC":
return "H";
case "CAA":
case "CAG":
return "Q";
case "AAT":
case "AAC":
return "N";
case "AAA":
case "AAG":
return "K";
case "GAT":
case "GAC":
return "D";
case "GAA":
case "GAG":
return "E";
case "TGT":
case "TGC":
return "C";
case "TGG":
return "W";
case "CGT":
case "CGC":
case "CGA":
case "CGG":
case "AGA":
case "AGG":
return "R";
case "GGT":
case "GGC":
case "GGA":
case "GGG":
return "G";
default:
return "X";
}
};

export default codonToAminoAcid;
65 changes: 65 additions & 0 deletions src/utils/getColor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import ColorHash from "color-hash";
var colorHash = new ColorHash({ lightness: [0.75, 0.9, 0.7, 0.8] });

const getColor = (feature, product) => {
switch (feature.type) {
case "CDS":
switch (feature.name) {
case "S":
return "#ff7373";
case "nsp3":
return "#d3ffce";

case "leader":
return "#ff7f50";

case "nsp2":
return "#ddffdd";

case "nsp4":
return "#ff7373";

case "N":
return "#7fffd4";
case "E":
return "#ff7f50";
case "M":
return "#eeee88";
case "nsp12; RdRp":
return "#ff7f50";
case "nsp6":
return "#ee99ee";
case "nsp7":
return "#99ee99";

case "nsp8":
return "#ff7373";
case "nsp10":
return "#d3ffce";

case "nsp14":
return "#ff7f50";
case "nsp15":
return "#ddffdd";
case "nsp16":
return "#ffeeee";
case "nsp13":
return "#ff7f50";

default:
return colorHash.hex(feature.name + product + feature.type);
}
case "gene":
return "blue";
case "misc_feature":
return "green";
case "5'UTR":
return "orange";
case "3'UTR":
return "orange";
default:
return colorHash.hex(feature.name + product + feature.type);
}
};

export default getColor;

1 comment on commit 8391e35

@vercel
Copy link

@vercel vercel bot commented on 8391e35 Aug 3, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.