Irev-Dev / MRI-Volume-Slice

Tools for view MRI Volumes in the browser
6 stars 7 forks source link

Use openneuro.org's GraphQL API #31

Open Irev-Dev opened 6 years ago

Irev-Dev commented 6 years ago

open neuro has a GraphQL interface, which is great πŸ‘. https://openneuro.org/crn/graphql

Currently we fetch a dataset from openneuro, but it's hard coded, we're always grabbing the same one. It would be good if we instead used the API and grabbed a random dataset each time, we could also add a button for 'load random MRI' to get a new one (but the botton can be done later).

Extra info

I have never used graphQL before so I was really flaying about but I did have a little play and using the query below I was able to get it to return a number of url's for files. We would be interested in files ending in .nii.gz, so filtering and probably limiting the number per files return per dataset seems appropriate.

{
  datasets {
    id
    draft {
      id
      partial
      files {
            urls
        }
      summary {
        modalities
        totalFiles
        tasks
        size
        __typename
      }
      __typename
    }
    analytics {
      views
      downloads
      __typename
    }
    __typename
  }
}
gowrimanoharir commented 6 years ago

@Irev-Dev I would like to give this a try, please let me know.

codegagan commented 6 years ago

Looks like their graphql does not provide filters.

The only filter they have is on dataset id. May be we can query by randomly generating ids.


  dataset(id: "ds000001") {
    id
    draft {
      id
      partial
      files {
        urls
        filename
      }
      summary {
        totalFiles
        __typename
      }
      __typename
    }
  }
}
gowrimanoharir commented 6 years ago

@Irev-Dev Actually if we are worried about only the urls then the query you added can be reduced to below that way we are only getting the required data and so it would be little faster. { datasets { id draft { files { urls } } } }

With respect to limiting results i could not find a query param in their schema to mention number of records. But another way, would be to first send the query only to get the ids as below.

Get all Ids: { datasets { id public }

Then from that set randomize to pick one id and send a query by passing that id to get the file urls which we can then be filtered for required file type.

{dataset(id: "ds000117") { id draft { id partial files { urls filename } } } }

Irev-Dev commented 6 years ago

@gowrimanoharir Sounds like a good approach.

gowrimanoharir commented 6 years ago

@Irev-Dev thanks i will work on it

gowrimanoharir commented 6 years ago

@Irev-Dev I implemented the randomize functionality, got below questions while testing those:

  1. There is caching functionality which means the randomize will work only for first time users or when user cleared the cache, assume that what is needed?

  2. some of the files seems to come with different sizes for example below is a smaller one:

image

gowrimanoharir commented 6 years ago

one more example: direct url for this https://openneuro.org/crn/datasets/ds001529/files/sub-iso2239:ses-1:func:sub-iso2239_ses-1_task-rest_acq-EPI_bold.nii.gz

image

Irev-Dev commented 6 years ago

Awesome @gowrimanoharir πŸ‘‘ Really good points you're bringing up here.

Question 1)

Correct, I think it makes sense to give a random dataset, but because it takes a while to fetch a data set from open neuro I wanted the caching, so you get the last data set you were looking at.

The way I see this working is 1) Like you said, random for the first time (or when cache is cleared) 2) have a button on the UI "load new random MRI" which would then run your query and fetch a new random dataset.

If you want I can get a button ready in the HTML/CSS❓

Question 2)

TL:DR version

We want datasets with files names that end in .nii.gz (as previously mentioned) AND have T1w in the name. The second image you posted looks like it definitely 'functional data' I can tell by looking at it and the file name with EPI_bold gives it away, we should avoid this type of data by looking for T1w. But besides that the data will tend to come in different dimensions

Verbose version

Something I forgot about, in neuro science there are typically two types of data loosely referred to as functional and anatomical data, anatomical data is what we want, these are higher resolution, normally of the entire brain and better contrast i.e. they will look better in the viewer. If you are interested functional MRI or fMRI is what is used to scan the brain multiple times to learn something from the brain activity (a scan every two seconds is typical), but normally only the part of the brain that is of interest to the researchers is scanned (to make the scan times faster) and hence they won't look very good on the our viewer πŸ˜” . Both types of data still come in the nifti format .nii but fortunately the datasets on open neuro use the BIDS structure (brain imaging data structure) which means the data sets that we want will have T1w in the name πŸŽ‰ , link if interested.

I did my honours thesis on fMRI, and it's all coming back to me now haha, I forgot about the two different types of data.

Thanks for battling through all this @gowrimanoharir. πŸ‹οΈβ€β™€οΈ

Irev-Dev commented 6 years ago

I'm not the best with regular expressions, so this could probably do done in a more concise way, but you could use T1w.+\.?nii\.gz$ to match against the file name.

image
gowrimanoharir commented 6 years ago

@Irev-Dev Thanks for the detailed explanation, that helps. Though not an expert, i have worked with regex that is a good idea to filter the required file. I will start with what you have suggested and if can be improved will do so.

Also with respect to the Load new MRI button I can add it, please let me know where in the UI it needs to be added and specific styling if any you want?

Irev-Dev commented 6 years ago

Yup sounds good πŸ™‡β€β™‚οΈ

Not too fussed about the button, I guess put it to the right of the cross hair toggle switch and use the same styling as the file browse button i.e. same corner radius and same green.

gowrimanoharir commented 6 years ago

@Irev-Dev Opened a pull request with required changes, please review and let me know for any questions or any fixes/changes

https://github.com/Irev-Dev/MRI-Volume-Slice/pull/39

PS: sorry couldnt get to this during the week days.