Skip to content

Commit

Permalink
add RC
Browse files Browse the repository at this point in the history
  • Loading branch information
theosanderson committed Jul 28, 2023
1 parent 36ac6b5 commit 6861ab5
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import Tooltip from "./components/Tooltip";
import { getReverseComplement, filterFeatures } from "./utils";
import SingleRow from "./components/SingleRow";



function SearchPanel({
searchPanelOpen,
setSearchPanelOpen,
Expand All @@ -35,7 +37,9 @@ function SearchPanel({
setSearchType,
curSeqHitIndex,
sequenceHits,
setCurSeqHitIndex
setCurSeqHitIndex,
includeRC,
setIncludeRC
}) {
const handleInputChange = (event) => {
setCurSeqHitIndex(0);
Expand Down Expand Up @@ -111,12 +115,21 @@ function SearchPanel({
</div>
{
searchType === "sequence" && (
<div className="my-2 text-gray-800 text-center px-3">
<div className="my-2 text-gray-400 text-left px-3">
<input type="checkbox" value={includeRC} onChange={() => {

setIncludeRC(!includeRC);
setCurSeqHitIndex(0);
}

}/>
<label className="ml-2 text-gray-900">Include reverse complement</label>

{sequenceHits.length > 0 && (
<>
<button>
<BsArrowLeftCircleFill onClick={() => setCurSeqHitIndex((x) => x==0? sequenceHits.length-1: x-1)}
className="mx-3 text-gray-400" />
className="mx-3 text-gray-600" />
</button>


Expand Down Expand Up @@ -187,6 +200,7 @@ function GensploreView({ genbankString, searchInput, setSearchInput }) {
const [genbankData, setGenbankData] = useState(null);
const [sequenceHits, setSequenceHits] = useState([]);
const [curSeqHitIndex, setCurSeqHitIndex] = useState(0);
const [includeRC, setIncludeRC] = useState(false);

// safely convert searchInput to int
const intSearchInput = searchType === "nuc" ? parseInt(searchInput) : null;
Expand Down Expand Up @@ -423,8 +437,13 @@ function GensploreView({ genbankString, searchInput, setSearchInput }) {
// we want to find all locations that match and store them with setSequenceHits as [start,end]
const seqHits = [];
let start = 0;
const rc = getReverseComplement(strippedSequenceInput);
console.log("rc", rc);
while (true) {
const hit = fullSequence.indexOf(strippedSequenceInput, start);
const hit1 = fullSequence.indexOf(strippedSequenceInput, start);
const hit2 = includeRC ? fullSequence.indexOf(rc, start) : -1;
const hit = hit1 === -1 ? hit2 : (hit2 === -1 ? hit1 : Math.min(hit1, hit2));

if (hit === -1) break;
seqHits.push([hit, hit + strippedSequenceInput.length]);
start = hit + 1;
Expand All @@ -435,7 +454,7 @@ function GensploreView({ genbankString, searchInput, setSearchInput }) {
console.log("row", row);
rowVirtualizer.scrollToIndex(row + 1, { align: "center" });
setLastSearch(sequenceSearchInput);
}, [sequenceSearchInput, curSeqHitIndex]);
}, [sequenceSearchInput, curSeqHitIndex,includeRC]);


//console.log("virtualItems", virtualItems);
Expand Down Expand Up @@ -467,6 +486,8 @@ function GensploreView({ genbankString, searchInput, setSearchInput }) {
curSeqHitIndex={curSeqHitIndex}
setCurSeqHitIndex={setCurSeqHitIndex}
sequenceHits={sequenceHits}
includeRC={includeRC}
setIncludeRC={setIncludeRC}
/>
</div>
)}
Expand Down

0 comments on commit 6861ab5

Please sign in to comment.