Skip to content

Commit

Permalink
Update to new bedtool intersect query (#363)
Browse files Browse the repository at this point in the history
* Updated the bedUpload file to use new GraphQL query

* Updated bedUpload to work on both assemblies and have output limit

* Removed unnecessary imports

* Removed unncesary log statements

* bedUpload ignores header and empty lines on file upload

---------

Co-authored-by: Jonathan Fisher <[email protected]>
  • Loading branch information
GannaMohit and jpfisher72 authored Jul 11, 2024
1 parent c1ff685 commit 7af9aa1
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 32 deletions.
55 changes: 35 additions & 20 deletions screen2.0/src/app/_mainsearch/bedupload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,43 @@ import { useRouter } from 'next/navigation'
import UploadFileIcon from '@mui/icons-material/UploadFile';
import { Cancel, Search } from "@mui/icons-material"
import { LoadingButton } from "@mui/lab"
import config from "../../config.json"
import { client } from "../search/_ccredetails/client"
import { useLazyQuery } from "@apollo/client"
import { BED_INTERSECT_QUERY } from "./queries"

const BedUpload = (props: { assembly: "mm10" | "GRCh38", header?: boolean }) => {
const router = useRouter()

const [files, setFiles] = useState<File[]>([])
const [loading, setLoading] = useState(false)
const [getOutput] = useLazyQuery(BED_INTERSECT_QUERY)

const onDrop = useCallback(acceptedFiles => {
// setFiles([...files, ...acceptedFiles])
// Currently only accepting 1 file
setFiles([acceptedFiles[0]])
}, [])



const { getRootProps, getInputProps, isDragActive } = useDropzone({ onDrop })

const getIntersect = (jq, successF, errF) => {
//Need to put this url in config file
const url = config.BED_intersect.url
fetch(url, {
headers: {
Accept: "application/json",
"Content-Type": "application/json",
const getIntersect = (allLines, successF, errF) => {
getOutput({
variables: {
user_ccres: allLines,
assembly: props.assembly,
maxOutputLength: 1000 // Not required technically as server side defaults to 1000, here if it needs to be changed in the future
},
client: client,
fetchPolicy: 'cache-and-network',
onCompleted(data) {
successF(data)
},
onError(error) {
errF(error)
},
method: "POST",
body: jq,
})
.then((response) => response.json())
.then(successF)
.catch(errF)
}

//TODO Warn based on file size, support multiple files
Expand All @@ -51,19 +58,27 @@ const BedUpload = (props: { assembly: "mm10" | "GRCh38", header?: boolean }) =>
reader.onload = (r) => {
const contents = r.target.result
const lines = contents.toString().split("\n")
lines.forEach((e) => {
allLines.push(e)
lines.forEach((line) => {
// The if statement checks if the BED file has a header and does not push those
// Also checks for empty lines
if (!(line.startsWith("#") ||
line.startsWith("browser") ||
line.startsWith("track") ||
line.length === 0
)) {
allLines.push(line.split("\t"))
}
})
console.log(allLines);

}
reader.onabort = () => console.log("file reading was aborted")
reader.onerror = () => console.log("file reading has failed")
reader.onloadend = (e) => {
const j = { uuid: "", assembly: props.assembly, allLines }
const jq = JSON.stringify(j)
getIntersect(
jq,
(r) => {
accessions = r.accessions
allLines,
(data) => {
accessions = data['intersection'].map((elem) => elem[4])
sessionStorage.setItem("filenames", filenames)
sessionStorage.setItem("bed intersect", accessions.join(' '))
if (accessions.length === 1000){
Expand Down
35 changes: 23 additions & 12 deletions screen2.0/src/app/_mainsearch/queries.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { gql } from "@apollo/client"

export const CCRE_AUTOCOMPLETE_QUERY = `
query cCREQuery($accession_prefix: [String!], $limit: Int, $assembly: String!) {
Expand Down Expand Up @@ -27,15 +28,25 @@ query ($assembly: String!, $name_prefix: [String!], $limit: Int, $version: Int)
}
`

export const SNP_AUTOCOMPLETE_QUERY = `
query snpAutocompleteQuery($snpid: String!, $assembly: String!) {
snpAutocompleteQuery(snpid: $snpid, assembly: $assembly) {
id
coordinates {
chromosome
start
end
}
}
}
`
export const SNP_AUTOCOMPLETE_QUERY = `
query snpAutocompleteQuery($snpid: String!, $assembly: String!) {
snpAutocompleteQuery(snpid: $snpid, assembly: $assembly) {
id
coordinates {
chromosome
start
end
}
}
}
`

export const BED_INTERSECT_QUERY = gql`
query bedIntersectCCRE ($user_ccres: [cCRE]!, $assembly: String!, $max_ouput_length: Int) {
intersection (
userCcres: $user_ccres,
assembly: $assembly,
maxOutputLength: $max_ouput_length
)
}
`

0 comments on commit 7af9aa1

Please sign in to comment.