Omic Python API

From Array Suite Wiki

Jump to: navigation, search

‏‎

Contents

Omic Python API Introduction

OmicPythonApi was designed to be a python package that allows Python users to perform Omicsoft analysis within Python environment. It allows users not only to query Land using its build-in APIs, but also run custom oscripts in Python Environment.

Query Land using built-in API

Python users may use the built-in APIs in the package for Omicsoft Land queries. We have currently wrapped most ArrayLand query oscript procs in OmicPythonApi as buit-in APIs. One example in the tutorial below shows how to perform a land query using the build-in APIs. More Land query examples can be found in a Jupyter Python Notebook in the Tutorial folder in the installation package.

Perform custom data analysis and server management

Python users may also use OmicPythonApi to run user-defined oscripts within Python environment. This allows users to perform highly customized data analysis using Omicsoft tools in Python. In addition, bioinformatitians and ArrayServer administrators may also perform systematic management of samples, projects and users in Array Server. One example in the tutorial below shows how to run a custom oscript to add a new user to Array Server.

Installation

Requirements

OmicPythonApi runs in both Windows and Linux.

In Windows, OmicPythonApi requires Oshell and Python 3.6.

In Linux, OmicPythonApi requires Oshell, Python 3.6 and Mono.

Installation

1. Download OmicPythonApi package from the link: [Download]

2. Save OmicPythonApi.zip to a location (called InstallationFolder).

3. Unzip OmicPythonApi.zip (Please do NOT rename the unzipped folder).

3. Update the mono and oshell path in OmicPythonApi.cfg file. If Oshell was installed in windows, either comment MonoPath line with //, or set it to a space character.

4. Import OmicPythonApi in the InstallationFolder in a Python script

Quick start

1. Open Jupyter Notebook (or any other interactive Python Environment), and include the following lines into your python script to import OmicPythonApi package:

InstallationFolder=r'C:\Users\chenwi\Desktop\tem\PythonAPI'
import site
site.addsitedir(InstallationFolder)
import OmicPythonApi as Oapi
import os
import pandas as pd

2. Load and Initialize an OmicPythonApi object, run the API with Run function, check output, and print Log

a1=Oapi.ListLands(ServerAddress=r'tcp://192.168.3.226:8065',ServerUserId='omicsoft',ServerUserPsw='omicsoft',OutputFolder=r'C:\test')
a1.Run()
os.listdir(a1.OutputFolder)
print(a1.Log)

Tutorial

Get help

1. import OmicPythonApi

InstallationFolder=r'Z:\Users\wilson\document\Script_Library\Python\OmicPythonApi_Development'
import site
site.addsitedir(InstallationFolder)
import OmicPythonApi as Oapi 


2. List all functions and objects in OmicPythonApi

dir(Oapi) 

DirOapi.png


3. Get help for built-in APIs

?Oapi.ListLands() 

ListLandsHelp.png


4. More help on the input and output parameters in the standard build-in APIs


The standard built-in APIs in OmicPythonApi package are wrappers of simple oscripts. The input and output are normally identical between in build-in APIs and the original oscripts. Original oscripts behind a built-in API is retrievable in Oapi.OscriptTemplate field (see example in tutorial below). User may search procs and oscripts in Omicsoft Wiki for more details of the input and output. OmicsoftWiki.

Use build-in API to query expression ratio data for given samples in TCGA_B37 Land

1. Load API

a1=Oapi.TextDumpArrayLandSampleData()


2. Initialize the API

a1.ServerAddress=r'tcp://192.168.3.226:9065'
a1.ServerUserId='omicsoft'
a1.ServerUserPsw='xxxx'
a1.Land='TCGA_B37'
a1.DataMode='Expression_Ratio'
a1.Sample=r'TCGA-01-0628-11A,TCGA-01-0629-11A'
a1.DownloadFullMetaData='True'
a1.OutputFolder='/local_data/tem'
a1.Output='TestSample'

Here is the output screenshot in Jupyter Notebook:

TextDumpArrayLandSampleData Initialize.png


3. View oscript template behind the API:

a1.OscriptTemplate

TextDumpArrayLandSampleData PrintTemplate.png


4. Run the API

a1.Run()

TextDumpArrayLandSampleData Run.png


5. View oshell log

print(a1.Log)

TextDumpArrayLandSampleData PrintLog.png


6. View output file lists

os.listdir(a1.OutputFolder)

TextDumpArrayLandSampleData ListOutput.png


7. Load output table in Pandas DataFrame

import pandas as pd
ExpressionTable1=pd.read_csv(os.path.join(a1.OutputFolder,'TestSample.Expression_Ratio.txt'),sep='\t')
ExpressionTable1.head()

TextDumpArrayLandSampleData ReadCsv.png

Customize OmicPython API to run user-defined oscripts: create new users in Array Server

Array Server Admin may want to systematicaly organize users. Here is one example:

1. Load OmicPythonApi

a1=Oapi.OmicPythonApi()

OmicPythonApi Load.png


2. Initialize Oscript field with custom oscript

a1.Oscript="""
Begin ExecuteCommand /Namespace=Server;
Server "tcp://192.168.3.226:9065" /UserID=omicsoft /Password=omicsoft;
Command ManageUsers_Add;
Options
"
UserID=wilson5
UserGroups={standard users,test,test2}
Password=omicsoft
FullName =Wilson Test
Organization=Omicsoft
Department=Support
Laboratory=lab1
Position=Scientist
Notes=notes
Email=test@qiagen.com
Phone=919-439-xxxx
Address=xxxx
";
End;
"""


3. Run the custom oscript

a1.Run()

OmicPythonApi Run.png

OmicPythonApi AddUser.png