Skip to content

Commit

Permalink
Added menu item to allow user to export DNA as FASTA when looking at …
Browse files Browse the repository at this point in the history
…a protein sequence to resolve TeselaGen#61
  • Loading branch information
ryan-stackwave committed Feb 27, 2024
1 parent bd91195 commit 8f1b721
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/bio-parsers/src/jsonToFasta.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default function jsonToFasta(jsonSequence, options) {
options = options || {};
let seqToUse = sequence;
let sizeToUse = size;
if (isProtein && proteinSequence) {
if (isProtein && proteinSequence && !options?.useDNA) {
seqToUse = proteinSequence;
sizeToUse = proteinSize;
}
Expand Down
1 change: 1 addition & 0 deletions packages/ove/src/MenuBar/defaultConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export default [
submenu: [
{ cmd: "exportSequenceAsGenbank" },
{ cmd: "exportSequenceAsFasta" },
{ cmd: "exportDNASequenceAsFasta" },
{ cmd: "exportSequenceAsTeselagenJson" }
]
},
Expand Down
5 changes: 3 additions & 2 deletions packages/ove/src/SimpleCircularOrLinearView.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ export default props => {
)
? CircularView
: _sequenceData.isOligo && _sequenceData.sequence
? SimpleOligoPreview
: LinearView;
? SimpleOligoPreview
: LinearView;
if (withChoosePreviewType && previewType === "row") {
Component = RowView;
tickSpacing = undefined;
Expand Down Expand Up @@ -292,6 +292,7 @@ const DownloadBtn = withHandlers({ exportSequenceToFile })(props => {
[
"exportSequenceAsGenbank",
"exportSequenceAsFasta",
"exportDNASequenceAsFasta",
"exportSequenceAsTeselagenJson"
],
[
Expand Down
1 change: 1 addition & 0 deletions packages/ove/src/ToolBar/downloadTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const Dropdown = withEditorProps(props => {
[
"exportSequenceAsGenbank",
"exportSequenceAsFasta",
"exportDNASequenceAsFasta",
"exportSequenceAsTeselagenJson"
],
getCommands({ props })
Expand Down
5 changes: 5 additions & 0 deletions packages/ove/src/commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,11 @@ const fileCommandDefs = {
name: "Download FASTA File",
handler: props => props.exportSequenceToFile("fasta")
},
exportDNASequenceAsFasta: {
name: "Download DNA FASTA File",
isHidden: props => !isProtein(props) || !props.sequenceData.sequence,
handler: props => props.exportSequenceToFile("fasta", { useDNA: true })
},
exportSequenceAsTeselagenJson: {
name: "Download Teselagen JSON File",
handler: props => props.exportSequenceToFile("teselagenJson")
Expand Down
30 changes: 16 additions & 14 deletions packages/ove/src/withEditorProps/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ const getUpperOrLowerSeq = defaultMemoize(
uppercaseSequenceMapFont === "uppercase"
? sequence.toUpperCase()
: uppercaseSequenceMapFont === "lowercase"
? sequence.toLowerCase()
: sequence
? sequence.toLowerCase()
: sequence
);

const getTypesToOmit = annotationsToSupport => {
Expand Down Expand Up @@ -284,7 +284,7 @@ export const importSequenceFromFile =
}
};

export const exportSequenceToFile = props => format => {
export const exportSequenceToFile = props => (format, options) => {
const { sequenceData } = props;
let convert, fileExt;

Expand All @@ -304,7 +304,9 @@ export const exportSequenceToFile = props => format => {
console.error(`Invalid export format: '${format}'`); // dev error
return;
}
const blob = new Blob([convert(sequenceData)], { type: "text/plain" });
const blob = new Blob([convert(sequenceData, options)], {
type: "text/plain"
});
const filename = `${sequenceData.name || "Untitled_Sequence"}.${fileExt}`;
FileSaver.saveAs(blob, filename);
window.toastr.success("File Downloaded Successfully");
Expand Down Expand Up @@ -441,16 +443,16 @@ export default compose(
selectionLayer.start > -1
? { ...selectionLayer, id: undefined }
: caretPosition > -1
? {
start: caretPosition,
end: sequenceData.isProtein
? caretPosition + 2
: caretPosition
}
: {
start: 0,
end: sequenceData.isProtein ? 2 : 0
};
? {
start: caretPosition,
end: sequenceData.isProtein
? caretPosition + 2
: caretPosition
}
: {
start: 0,
end: sequenceData.isProtein ? 2 : 0
};
showAddOrEditAnnotationDialog({
type: key.toLowerCase(),
annotation: {
Expand Down

0 comments on commit 8f1b721

Please sign in to comment.