# Using the ADAT

ADATs can be analyzed in R or Python using parsers created by Somalogic.

DRAGEN Protein Quantification v2.0.0 is compatible with SomaData v1.0.0 (Python - formerly called Canopy) and SomaDataIO v6.1.0 (R).

* Python: <https://github.com/SomaLogic/Canopy>
* R: <https://github.com/SomaLogic/SomaDataIO>

Somadata creates an ADAT object, which is an extension of a Pandas DataFrame.

* rows correspond to samples
* columns correspond to SOMAmers
* values are normalized counts

Below are examples on parsing an ADAT in Python and R.

### Parsing ADAT in Python

```python
import somadata

# read the adat
my_adat = somadata.read_adat('/path/to/my/file1.adat')

# retrieve sample metadata
sample_meta = my_adat.index.to_frame(index=False)

# retrieve SOMAmer metadata
soma_meta = my_adat.columns.to_frame(index=False)

# retrieve the scale factors for all plates
plate_scale_factors_dict = my_adat.header_metadata['PlatformSpecificPlateScale_ScaleFactor']

### additional optional manipulation 

# concatenate multiple adats into a single adat
my_adat2 = somadata.read_adat('/path/to/my/file2.adat')
my_merged_adat = soma.smart_adat_concatenation([my_adat, my_adat2])

# write it to a file 
my_merged_adat = my_merged_adat.to_adat('/path/to/merged/adat')
```

### Parsing ADAT in R

```r
library(SomaDataIO)

# check all package functions
ls("package:SomaDataIO")

#read the adat
my_adat <- read_adat('/path/to/my/file1.adat')

# retrieve sample metadata
sample_meta <- my_adat[getMeta(my_adat)]

# retrieve SOMAmer metadata
soma_meta <- my_adat[getAnalytes(my_adat)]

# create a function that parses the header
parse_adat_header <- function(adat_file, max_lines = 500) {
  header_lines <- readLines(adat_file, n = max_lines)
  table_row <- grep("TABLE_BEGIN", header_lines)
  header_lines[1:(table_row-1)] %>% 
    strsplit("\t") %>% 
    {
      values <- map(., 2) # Get values from key value pairs
      keys <- map_chr(., 1) # Get keys...
      setNames(values, keys)
    }
}

my_adat_header <- parse_adat_header('/path/to/my/file1.adat')

# retrieve the scale factors for all plates
plate_scale_factors_dict = my_adat_header$PlatformSpecificPlateScale_ScaleFactor

### additional optional manipulation 
my_adat2 = read_adat('/path/to/my/file2.adat')
my_merged_adat = rbind(my_adat, my_adat2)

# write it to a file 
my_merged_adat = write_adat(my_merged_adat, '/path/to/merged/adat')

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://help.connected.illumina.com/dragen-protein-quantification/after-counting-and-normalization/using-the-adat.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
