`` bash`
``pip install requests``
:raw-html-m2r:```` `
``Once you've installed requests, you can import it into your Python code. Here's an example of a basic API request:``
:raw-html-m2r:```` python`
``import requests``
``# Replace API_ENDPOINT_HERE with the actual API endpoint URL``
``response = requests.get("API_ENDPOINT_HERE").json()``
``# Process the data in the response object``
:raw-html-m2r:```` `
In this code, we first import the requests library. Then, we use the requests.get() function to send a GET request to the specified API endpoint URL. The .json() method is used to parse the JSON response from the API into a Python dictionary that we can easily work with in our code.
**Example: Accessing NASA data**
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Let's look at a concrete example. Suppose we want to retrieve some data from NASA's Open Science Data Repository (OSDR). Here's how we can use the requests library to fetch a specific file:
:raw-html-m2r:````Python`
``import requests``
``# API endpoint URL for a specific file in OSDR``
``url = "https://osdr.nasa.gov/osdr/data/osd/files/87"``
``response = requests.get(url).json()``
``# Now you have the data from the file in the response object``
:raw-html-m2r:```` `
By replacing API_ENDPOINT_HERE with the actual URL of the API endpoint you want to access, you can use this code template to retrieve data from a variety of web services.
Summary of Study Metadata API :raw-html-m2r:``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
**Syntax:** *“a set of rules for or an analysis of the syntax of a language.”*
``https://osdr.nasa.gov/osdr/data/osd/meta/{OSD_STUDY_ID}``
.. list-table::
:header-rows: 1
* - Parameters
- Data Type
- Notes
- Values
- Required
* - {OSD_STUDY_ID}
- Integer
- Single study accession number
- Example: 137
- Yes
Single Study Metadata Request:
**Example:** `https://osdr.nasa.gov/osdr/data/osd/meta/137 Any text to search for, can be augmented by the keywords:
`\ :raw-html-m2r:`If no conjunctive or disjunctive operator specified, the default is "AND"
` * - DATA-SOURCE - cgene, nih_geo_gse, ebi_pride, mg_rast - :raw-html-m2r:```` `\ **
``library(httr)``
``get.csv <- function(url, ...) {``
``response <- GET(url, add_headers(Authorization = paste("Bearer", TOKEN)))``
``return(read.csv(text = content(response), ...))``
``}``
``# Replace "TOKEN" with your actual token (if needed)``
``GLOPENAPI <- "https://visualization.genelab.nasa.gov/GLOpenAPI/"``
``query <- URLencode("id=OSD-569&study.factor value")``
``metadata <- get.csv(paste0(GLOPENAPI, "metadata/?", query), skip = 1)``
``summary(metadata) # View metadata column information``
:raw-html-m2r:```` `
**1.3 Data Retrieval:**
We'll retrieve unnormalized RNA-Seq counts data (suitable for differential expression analysis) for OSD-569.
**Code snippet**
query <- URLencode("id=OSD-569\&file.datatype=unnormalized counts")
url <- paste0(GLOPENAPI, "data/?", query)
data <- get.csv(url, check.names = FALSE, skip = 2, row.names = 1)
**Step 2: Differential Expression Analysis** :raw-html-m2r:``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
**2.1 Data Preparation:**
Ensure gene names are set as row names and sample names as column names. You might need to perform additional preprocessing steps like normalization and filtering depending on the chosen analysis data type.
**2.2 Performing Differential Expression Analysis:**
This example utilizes DESeq2 for differential expression analysis with unnormalized counts. Here, we classify timestamps into preflight, postflight, and recovery based on specific criteria.
**Code snippet**
**\ :raw-html-m2r:```` R`\ **
``rownames(metadata) <- metadata$sample.name``
``metadata$status <- sapply(metadata$timestamp, function(t) {``
``ifelse(t == "R+1", "postflight",``
``ifelse(startsWith(t, "R+"), "recovery",``
``"preflight"))``
``})``
``library(DESeq2)``
``dds <- DESeqDataSetFromMatrix(round(na.omit(data)),``
``# Ensure integer values and no NaNs``
``metadata, ~status + subject,``
``)``
``lrt <- DESeq(dds, test = "LRT", reduced = ~subject)``
``deg <- results(lrt, contrast = c("status", "postflight", "preflight"))``
``# Consider adding functionalities for multiple contrasts here.``
:raw-html-m2r:```` `
**Step 3: Pathway Enrichment Analysis** :raw-html-m2r:``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
There are many R packages to visualize pathway enrichment based on the results of the differential expression analysis and the subsequent clustering and intersect analysis.
:raw-html-m2r:```` R`
``library(msigdbr)``
``C2 = msigdbr(species="human", category="C2")``
``pathways = split(x=C2$ensembl_gene, f=C2$gs_name)``
``library(fgsea)``
``deg$rank = deg$padj * sign(deg$log2FoldChange)``
``ranks = with(na.omit(deg), setNames(rank, rownames(na.omit(deg))))``
``plotEnrichment(pathways$DIAZ_CHRONIC_MYELOGENOUS_LEUKEMIA_UP, ranks)``
:raw-html-m2r:```` `
**Conclusions**
By following this tutorial, researchers can effectively access, analyze, and derive insights from the rich biological datasets available through the NASA Open Science Data Repository. This tutorial serves as a foundational guide for bioinformatics professionals aiming to explore space-induced biological responses and advance research in understanding the impact of space travel on human health.
**Citation:**
[1] Sylvain Costes, Lauren Sanders, Kirill Grigorev et al. Inspiration4 Data Access through the NASA Open Science Data Repository, 05 January 2024, PREPRINT (Version 1) available at Research Square [https://doi.org/10.21203/rs.3.rs-3755391/v1]
Getting Started with OSDR Data in AWS S3 buckets :raw-html-m2r:``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This how-to guide is for new users who would like to access and work with the Open Science Data Repository (OSDR) data available on the Registry of Open Data on AWS. This initiative, as part of the Science Mission Directorate (SMD) Open-Source Science Initiative, aims to enhance data accessibility for open science within the NASA space biology community. Through the OSDR S3 bucket, users can access a diverse range of data including microbe, plant, fruit fly, rodent, human cell culture, ground study, and commercial astronaut studies. This guide will walk you through the steps of installing the AWS Command Line Interface (CLI) and utilizing it to access OSDR data.
Introduction to OSDR Data on AWG :raw-html-m2r:``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
**A Universe of Data at Your Fingertips: The OSDR S3 Bucket**
The OSDR data resides within a special storage unit on AWS called an S3 bucket. This bucket holds a vast collection of data types, ready to fuel your research endeavors. It encompasses data related to experiments, missions, organisms, and more, all relevant to space biosciences.
**Two Keys to Unlock the Data: Your Access Options**
To access and explore this wealth of information, you have two primary methods:
**AWS S3 Browser Interface:** This user-friendly web interface allows you to visually navigate the OSDR data. It's a fantastic starting point for getting acquainted with the data and exploring its organization. Simply visit the following URL to launch the browser interface:\
Link:\ ` http://nasa-osdr.s3-website-us-west-2.amazonaws.com/ ``` `
This reveal subfolders containing data from the SpaceX-12 mission, allowing you to pinpoint specific datasets of interest.
Automating Your Workflow: Scripting with the AWS CLI :raw-html-m2r:``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The true power of the AWS CLI lies in its ability to be integrated into scripts. By stringing together commands and incorporating conditional statements, you can automate repetitive tasks such as downloading multiple datasets or filtering data based on specific criteria. Learning basic scripting principles will unlock this advanced functionality.
Exploring OSDR Data :raw-html-m2r:``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Now that you have the AWS CLI installed, you can use it to explore OSDR data in the S3 bucket.
Here are some basic commands to help you get started:
To list the contents of the OSDR S3 bucket (command line):
:raw-html-m2r:````bash`
``aws s3 ls --no-sign-request s3://nasa-osdr/``
:raw-html-m2r:```` `
To list the contents of a specific OSDR dataset (e.g., OSD-96):
:raw-html-m2r:````bash`
``aws s3 ls --no-sign-request s3://nasa-osdr/OSD-96/ --recursive``
:raw-html-m2r:```` `
Copying Data Locally :raw-html-m2r:``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To copy specific files from the OSDR S3 bucket to your local machine, you can use the aws s3 cp command. For example:
* To copy a specific file to your local directory:
```bash
aws s3 cp --no-sign-request s3://nasa-osdr/OSD-96/version-6/rna_seq/GLDS-96_rna_seq_Dmel_Can-S_wo_GC_5th-gen-GC-der_1.5hr_GSM2350418_R2_raw.fastq.gz_trimming_report.txt
```
* To copy all files within a specific dataset to your local directory:
```bash
aws s3 cp --no-sign-request s3://nasa-osdr/OSD-96/ --recursive
```
Additional Resources :raw-html-m2r:``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
If you're looking to delve deeper into OSDR data access and AWS capabilities, consider exploring the following resources:
* `AWS CLI Documentation: source
`\ :raw-html-m2r:`source=DORELI
`\ :raw-html-m2r:``\ source=DORELI - BAS
* - spacecraft - string - name of spacecraft - - :raw-html-m2r:`spacecraft
`\ :raw-html-m2r:`spacecraft=ISS
` - * - instrument - string - name of instrument - - :raw-html-m2r:`instrument
`\ :raw-html-m2r:`instrument=Liulin-5-1D
`\ :raw-html-m2r:``\ instrument=Lidal - REM
- * - timestamp - :raw-html-m2r:`ISO-formatted string
`\ :raw-html-m2r:`(or Unix epoch)
` - timestamp of recorded value(s) - - :raw-html-m2r:`Note: can be used more than once in a single query.
`\ :raw-html-m2r:`Note: special characters (<, >, :) may need to be URL-encoded (see "Notes" below).
` - :raw-html-m2r:`timestamp
`\ :raw-html-m2r:`timestamp=2021-01-01T15:25
`\ :raw-html-m2r:`timestamp<=2021-01-01T15:25
`\ :raw-html-m2r:`timestamp>=2022-01-01T00:00×tamp<2023-01-01T00:00
`\ :raw-html-m2r:`timestamp>1683786900
` * - dose_rate_total - number - total radiation dose rate - μGy/hour - :raw-html-m2r:`dose_rate_total
`\ :raw-html-m2r:`dose_rate_total>=2
` - * - flux_total - number - total particle flux - cm-2sr-1s-1 - :raw-html-m2r:`flux_total
`\ :raw-html-m2r:`flux_total<1
` - * - latitude - number - latitude of spacecraft at given timestamp - deg - :raw-html-m2r:`latitude
`\ :raw-html-m2r:`latitude<-10
` - * - longitude - number - longitude of spacecraft at given timestamp - deg - :raw-html-m2r:`longitude
`\ :raw-html-m2r:`longitude>30
` - * - altitude - number - altitude of spacecraft at given timestamp - km - :raw-html-m2r:`altitude
`\ :raw-html-m2r:`altitude>=420
` - * - B - number - B value - nT - :raw-html-m2r:`B
`\ :raw-html-m2r:`B<=50000
` - * - L - number - L value - - :raw-html-m2r:`L
`\ :raw-html-m2r:`L>3
` **Boolean expression syntax** .. list-table:: :header-rows: 1 * - **Key** - **Aliases** - **Type** - **Description** - **Examples** * - query - - string - a boolean query referencing fields described in the "data fields" table above, and using AND, OR, NOT, =, !=, <=, >= operators and parentheses ((, )) - :raw-html-m2r:`query=(timestamp>=2023-05-16)AND((instrument=REM)OR(spacecraft=LND))
`\ :raw-html-m2r:`Note: spaces inside the query string are allowed (e.g. spacecraft = LND); the query can be optionally encased in single or double quotes. However, spaces and quotes may need to be URL-encoded (see "Notes" below).
` * - fields+ - :raw-html-m2r:`fields
`\ :raw-html-m2r:`columns
`\ :raw-html-m2r:`columns+
` - string - a comma-separated list of additional fields to retrieve (i.e. fields not already implicated in the boolean query) - fields+=dose_rate_total,flux_total **Auxiliary keys (used with both syntaxes)** .. list-table:: :header-rows: 1 * - **Key** - **Type** - **Description** - **Unit** - **Value format** - **Examples** * - format - string - output format - - :raw-html-m2r:`format=tsv
`\ :raw-html-m2r:`format=json
` Notes * Special characters (spaces, |, <, >, :, ', ") may need to be URL-encoded *(although* e.g. *Python will only complain if spaces are not encoded and will accept all other characters as-is; therefore, this depends on the use case):* * → %20 (space) * | → %7C * < → %3C * > → %3E * : → %3A * ' → %27 * " → %22 * Therefore, if this reference describes a query like timestamp<=2021-01-01T15:25, it may need to be sent as timestamp%3C=2021-01-01T15%3A25. * Field *names* are case insensitive (\ *i.e.* timestamp is the same as TimeStamp); string *values* are not (\ *i.e.* REM is valid, but reM is not). * Boolean expression operators are case sensitive, *i.e.* AND is understood as an operator, while and will result in a syntax error. Only the operators listed in the tables above are accepted. **Examples** * Key-value pair syntax * Dose rate and flux readings from DOSTEL1 and DOSTEL2 on the ISS between 11 PM on 01 Apr 2022, inclusive, and 1:05 AM on 02 Apr 2022, non-inclusive, only where the dose rate is above 2 μGy/hour, together with the spatial and magnetic coordinates of the ISS and the data provider name, formatted as HTML: * Conceptually:\ https://visualization.osdr.nasa.gov/radlab/api/\ ?spacecraft=ISS\ \&instrument=DOSTEL1|DOSTEL2\ \&source\ \×tamp>=2022-04-01T23:00\ \×tamp2022-04-02T01:05\ \&dose\_rate\_total2\ \&flux_total\ \&latitude\ \&longitude\ \&altitude\ \&b\ \&l\ \&format=html * URL-encoded *(may not be necessary)*\ :\ https://visualization.osdr.nasa.gov/radlab/api/\ ?spacecraft=ISS\ \&instrument=DOSTEL1%7CDOSTEL2\ \&source\ \×tamp%3E=2022-04-01T23%3A00\ \×tamp%3C2022-04-02T01%3A05\ \&dose_rate_total%3E2\ \&flux_total\ \&latitude\ \&longitude\ \&altitude\ \&b\ \&l\ \&format=html * Full URL: `https://visualization.osdr.nasa.gov/radlab/api/?spacecraft=ISS\&instrument=DOSTEL1%7CDOSTEL2\&source\×tamp%3E=2022-04-01T23%3A00\×tamp%3C2022-04-02T01%3A05\&dose\_rate\_total%3E2\&flux\_total\&latitude\&longitude\&altitude\&b\&l\&format=html