FASTA Gene Extractor
FASTA Gene Extractor
FASTA Gene Extractor
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>FASTA Gene Extractor</title>
<link
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet" integrity="sha384-
rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65"
crossorigin="anonymous">
<link rel="stylesheet" href="./FASTA_style.css">
</head>
<body>
<div class="container">
<label for="fastaFile">Load fastaFile</label>
<input class="" type="file" id="fastaFile" accept=".fasta"/> <br>
<label for="fastaFile">Load Genes ID</label>
<input class="" type="file" id="GenesID" accept=".txt"/>
<textarea class="form-control" id="geneNames" placeholder="Enter gene IDs
separated by commas (e.g., gene1.1, gene2.3)"></textarea>
<button class="btn btn-primary extract-btn" onclick="extractGenes()">Extract
Genes</button>
<textarea class="form-control output_area" id="output"></textarea>
</div>
<script>
function extractGenes() {
const fileInput = document.getElementById('fastaFile');
const file = fileInput.files[0];
const geneIDs = document.getElementById('geneNames').value.split(',').map(id
=> id.trim());
if (!file) {
alert("Please select a FASTA file!");
return;
}
if (geneIDs.length === 0) {
alert("Please enter gene IDs!");
return;
}
reader.onload = function(event) {
const fastaContent = event.target.result;
const sequences = parseFasta(fastaContent);
const filteredSequences = sequences.filter(seq =>
geneIDs.includes(seq.id));
displayResults(filteredSequences);
};
reader.readAsText(file);
}
function parseFasta(fastaContent) {
const sequences = [];
const lines = fastaContent.split(/\r?\n/);
let currentSeq = null;
lines.forEach(line => {
if (line.startsWith('>')) {
if (currentSeq) {
sequences.push(currentSeq);
}
currentSeq = { id: line.slice(1).split(" ")[0], sequence: '' }; //
Extract gene ID (with numbers and dots)
} else if (currentSeq) {
currentSeq.sequence += line.trim();
}
});
if (currentSeq) {
sequences.push(currentSeq);
}
return sequences;
}
function displayResults(filteredSequences) {
const output = document.getElementById('output');
if (filteredSequences.length === 0) {
output.textContent = "No matching genes found!";
} else {
output.textContent = filteredSequences.map(seq => `>${seq.id}\n$
{seq.sequence}`).join("\n\n");
}
}
</script>
</body>
</html>