-
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatically detect and convert fastq to fasta in the search query
Automatically detect and convert FASTQ in the query If a user provides a valid FASTQ, it can be converted to FASTA that can then be consumed by BLAST algorithms. Currently BLAST errs given a fastq. This should save users time and effort manually converting FASTQ to FASTA. If FASTQ is invalid, no modifications to user query will be made. As part of this change notifications have also been moved to the top of the screen, as we may have 2 notifications at once e.g. FASTQ conversion notification + detected query type notification.
- Loading branch information
Showing
9 changed files
with
146 additions
and
28 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const convertChunk = (fastqChunk) => { | ||
fastqChunk[0] = '>' + fastqChunk[0].substring(1); | ||
return fastqChunk.slice(0, 2); | ||
}; | ||
|
||
const isValidFastq = (fastqChunk) => { | ||
if (fastqChunk.length !== 4) { | ||
return false; | ||
} | ||
|
||
return fastqChunk[0][0] === '@' && fastqChunk[2][0] === '+' && fastqChunk[1].length === fastqChunk[3].length; | ||
}; | ||
|
||
export const fastqToFasta = (sequence) => { | ||
let trimmedSequence = sequence.trim(); | ||
// return unmodified if sequence does not look like fastq | ||
if (!trimmedSequence.startsWith('@')) { | ||
return sequence; | ||
} | ||
|
||
const sequenceLines = trimmedSequence.split('\n'); | ||
const fastaChunks = []; | ||
|
||
for (let i = 0; i < sequenceLines.length; i += 4) { | ||
const fastqChunk = sequenceLines.slice(i, i + 4); | ||
if (isValidFastq(fastqChunk)) { | ||
fastaChunks.push(...convertChunk(fastqChunk)); | ||
} else { | ||
// return unmodified sequence if it does not look like valid fastq | ||
return sequence; | ||
} | ||
} | ||
|
||
return fastaChunks.join('\n'); | ||
}; |
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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.