Giter Site home page Giter Site logo

ndb_adapter's Introduction

image

image

image

image

image

Adapter for easy access to NDB resources directly from python (3.*).

Usage

Adapter offers 4 types of search: summary, advanced, dna and rna.

Summary

To get summary of structure, type:

>>> from ndb_adapter import NDB
>>> res = NDB.summary('4Z4B')
>>> res.ndb_id
'4Z4B'
>>> res.title
'2-PYRIDYL HOECHST - A NEW GENERATION DNA-BINDING RADIOPROTECTOR'
>>> res.description
"DNA (5'-D(*CP*GP*CP*AP*AP*AP*TP*TP*TP*GP*CP*G)-3')"
>>> res.get_dict()
{'Molecular Description': "DNA (5'-D(*CP*GP*CP*AP*AP*AP*TP*TP*TP*GP*CP*G)-3')", ...}

As you see some properties are available for summary result. Full list of them is here.

To perform advanced search you should use AdvancedOptions object and pass it as argument to advanced_search function from NDB, however it's not required. That object has a lot of setters for modify search query. Look at them to search what you want. It's also possible to change result report type, just pass wanted type into constructor.

>>> from ndb_adapter import *
# options preparation
>>> opt = AdvancedSearchOptions()   # default report type NDBStatus
>>> opt.set_crystal_structure(yes_no_ignore=YesNoIgnore.Yes)    # default and_or=AndOr.And
>>> opt.set_dna(and_or=AndOr.Or, yes_no_ignore=YesNoIgnore.Yes)

# search
>>> res = NDB.advanced_search(opt)
>>> print(res.count)
4695
>>> print(res.report)
[<ndb_adapter.search_report.NDBStatusReport object at 0x00000248F9E02128>, ...]

# working on result
>>> first = res.report[0] # first structure from search
# if you want have annotations in IDE (i.e. Pycharm) do something like this:
>>> first = res.report[0] # type: ReportType.NDBStatus
>>> print(first.title)
"2-Pyridyl Hoechst - a New Generation DNA-Binding Radioprotector"

Every report type result is different - you can examine theirs properties or use typing.

Some of them has statistics also, for example:

>>> from ndb_adapter import *

>>> opt = AdvancedSearchOptions(ReportType.RNABasePairRelFreq)
>>> opt.set_hybrid(yes_no_ignore=YesNoIgnore.Yes)

>>> res = NDB.advanced_search(opt)
>>> print(res.statistics)
Min: {'Relative cWW': 0.5, 'Relative tWW': 0.0, 'Relative cHS': 0.0, 'Relative tWS': 0.0, ...}
Max: {'Relative cWW': 1.0, 'Relative tWW': 0.05, 'Relative cHS': 0.06, 'Relative tWS': 0.06, ...}
Mean: {'Relative cWW': 0.8, 'Relative tWW': 0.01, 'Relative cHS': 0.01, 'Relative tWS': 0.01, ...}
Standard Deviation: {'Relative cWW': 0.12, 'Relative tWW': 0.01, 'Relative cHS': 0.02, 'Relative tWS': 0.02, ...}
>> print(res.statistics.min)
{'Relative tWS': 0.0, 'Relative tWW': 0.0, 'Relative cHH': 0.0, 'Relative cWW': 0.5, ...}

Dna search is very similar to advanced search, but with DnaSearchOptions and smaller amount of setters.

>>> from ndb_adapter import *
# options preparation
>>> opt = DnaSearchOptions()
>>> opt.set_structural_features(StructuralFeatures.A_DNA)

# search
>>> result = NDB.dna_search(opt)
>>> print(result.count)
393
>>> str(result.report)
[<ndb_adapter.search_report.SimpleReport object at 0x00000152D0FCB438>, ...]

# working on result
>>> first = result.report[0]   # type: SimpleReport
>>> print(first.title)
"Crystal structure of 60-mer BFDV Capsid Protein ..."

Rna search is just like dna search. Options: RnaSearchOptions.

>>> from ndb_adapter import *
# search
>>> result = NDB.rna_search()   # default is empty RnaSearchOptions object
>>> print(result.count)
3014
>>> str(result.report)
[<ndb_adapter.search_report.SimpleReport object at 0x0000018B3C877E48>, ...]

# working on result
>>> first = result.report[0]   # type: SimpleReport
>>> print(first.title)
"Crystal structure of the bacterial A1408C-mutant ..."

Structure Download

Almost on every result of search you can download related files (.pdb, .cif, .xml etc.) to buffer or save.

>>> from ndb_adapter import NDB
>>> res = NDB.summary('4Z4B')
>>> res.download()  # .pdb is default
"HEADER DNA 01-APR-15 4Z4B ..."

>>> from ndb_adapter import DownloadType
>>> res.download(download_type=DownloadType.Cif)
'data_4Z4B\n# \n_entry.id   4Z4B ...'

>>> res = NDB.advanced_search()
>>> res.download(save=True) # saves n files in current directory
>>> res.download(save=True, target_dir='/home/user/Downloads/')  # saves n files in ~/Downloads/

>>> res.report[0].download(save=True) # saves first structure file in current directory

You can also search and download in one line:

>>> from ndb_adapter import NDB
>>> res = NDB.download('4Z4B')   # like above .pdb is default
"HEADER DNA 01-APR-15 4Z4B ..."
# save and target dir is also available

Requirements

Installation

To install, simply:

$ pip install ndb_adapter

Documentation

Documentation is available at https://michsior14.github.io/ndb_adapter/.

Licence

Software is distributed under the MIT Licence.

ndb_adapter's People

Contributors

michsior14 avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar  avatar  avatar

Forkers

bipuj

ndb_adapter's Issues

Pypi github URL is wrong

On Pypi, the url is pointing to nba_adapter. Probably you just need to update it in setup.py, though I suppose you could rename the project on github insteadl

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.