Exemple #1
0
def test_DocHelper_compose_correctly():
    doc = DocHelper(arg1='Docstring for arg1',
                    arg2=('Docstring for arg2'),
                    arg3=('type for arg3', 'Docstring for arg3'))
    output = doc.get(['arg1'])
    assert output == "arg1: Docstring for arg1"
    output = doc.get(['arg1', 'arg3'])
    assert output == "arg1: Docstring for arg1\n    arg3 (type for arg3): Docstring for arg3"
Exemple #2
0
def test_string_strip_func_works():
    docstring = ('This is docstring\n'
                 '    with multiple lines of args:\n'
                 '<< arg1,arg2,  arg3 >>\n'
                 '<<arg1, arg3>>\n')

    doc = DocHelper(arg1='Docstring for arg1',
                    arg2=('Docstring for arg2'),
                    arg3=('type for arg3', 'Docstring for arg3'))

    split = doc.split_string(docstring)
    assert split[0] == "This is docstring\n    with multiple lines of args:\n"
    assert split[1] == ('arg1', 'arg2', 'arg3')
    assert split[2] == '\n'
    assert split[3] == ('arg1', 'arg3')
Exemple #3
0
def parseAndImport(url, html):
    md5 = CryptHelper.getMD5Hash(url)
    if html != None and len(html) > 0:
        found, doc = DocHelper.parseDoc(html)
        article, errorCode = DocHelper.doc2Article(doc, url)
        if errorCode != "OK" or article == None:
            article = {
                'id': md5,
                'status': article['status'],
            }
    else:
        if len(url) >= 1000:
            url = url[0:1000]
        article = {
            'id': md5,
            'status': article['status'],
        }

    articleList = []
    articleDoc = {
        'id': article['md5'],
        'title': article['title'],
        'excerpt': article['excerpt'],
        'content': article['content'],
        'author': article['author'],
        'domain': article['domain'],
        'categories': article['categories'],
        'tags': article['tags'],
        'url': article['url'],
        'status': article['status'],
        'key': article['key'],
    }
    articleList.append(articleDoc)
    errorCode, rsp = HttpHelper.post(IMPORT_URL, articleList)
    if errorCode == "OK" and rsp != None and 'isOk' in rsp and rsp['isOk'] == True:
        print ("import article ok, id=" + article['md5'])
    else:
        print ("import article error, id=" + article['md5'])
Exemple #4
0
def test_DocHelper_compose_doc_decorator_func_works():
    doc = DocHelper(arg1='Docstring for arg1',
                    arg2=('Docstring for arg2'),
                    arg3=('type for arg3', 'Docstring for arg3'))

    @doc.compose(
        """Here is an example of simple docstring to replace function's arguments
    Args:
        << >>
    """)
    def target_func(arg1):
        pass

    assert target_func.__doc__ == "Here is an example of simple docstring to replace function's arguments\n" \
                                  "Args:\n" \
                                  "    arg1: Docstring for arg1"
Exemple #5
0
def test_DocHelper_compose_doc_decorator_no_effect_works():
    doc = DocHelper(arg1='Docstring for arg1',
                    arg2=('Docstring for arg2'),
                    arg3=('type for arg3', 'Docstring for arg3'))

    @doc.compose(
        """Here is an example of simple docstring with no argument substitution
    Args:
        args1
    """)
    def target_func(arg1):
        pass

    assert target_func.__doc__ == "Here is an example of simple docstring with no argument substitution\n" \
                                  "Args:\n" \
                                  "    args1"
Exemple #6
0
def test_DocHelper_compose_doc_decorator_works_with_fstring():
    doc = DocHelper(arg1='Docstring for arg1',
                    arg2=('Docstring for arg2'),
                    arg3=('type for arg3', 'Docstring for arg3'))

    @doc.compose(
        """Here is an example of simple docstring to replace function's arguments
    {something}
    Args:
        << >>
    """.format(something='special things'))
    def target_func(arg1):
        pass

    assert target_func.__doc__ == "Here is an example of simple docstring to replace function's arguments\n" \
                                  "special things\n" \
                                  "Args:\n" \
                                  "    arg1: Docstring for arg1"
Exemple #7
0
def test_DocHelper_compose_doc_decorator_works():
    doc = DocHelper(arg1='Docstring for arg1',
                    arg2=('Docstring for arg2'),
                    arg3=('type for arg3', 'Docstring for arg3'))

    @doc.compose("""Here is an example
        <<arg1, arg2>>
    Args:
            <<arg2, arg3, 8>>
    """)
    def target_func(arg1):
        pass

    assert target_func.__doc__ == "Here is an example\n" \
                                  "    arg1: Docstring for arg1\n" \
                                  "    arg2: Docstring for arg2\n" \
                                  "Args:\n" \
                                  "        arg2: Docstring for arg2\n" \
                                  "        arg3 (type for arg3): Docstring for arg3"
Exemple #8
0
def test_DocHelper_compose_doc_decorator_works_with_beginning_indent_turned_on(
):
    doc = DocHelper(arg1='Docstring for arg1',
                    arg2=('Docstring for arg2'),
                    arg3=('type for arg3', 'Docstring for arg3'))

    @doc.compose("""Here is an example
    <<arg1, arg2>>
    Args:
    <<arg2, arg3, 8>>
    """,
                 indent_at_top=True)
    def target_func(arg1):
        pass

    assert target_func.__doc__ == "Here is an example\n" \
                                  "    arg1: Docstring for arg1\n" \
                                  "    arg2: Docstring for arg2\n" \
                                  "Args:\n" \
                                  "        arg2: Docstring for arg2\n" \
                                  "        arg3 (type for arg3): Docstring for arg3"
Exemple #9
0
        raise NotImplementedError()

    def __call__(self, target, **kwargs):
        return self.apply(target=target, **kwargs)


_spike_in_doc = DocHelper(
    radius=
    ('int',
     'Radius of spike-in peak, seqs less or equal to radius away from center are spike-in seqs'
     ),
    base_table=
    ('pd.DataFrame',
     'base_table includes spike-in sequences to calculate normalization factor'
     ),
    unit=('str', 'unit of spike-in amount'),
    dist_type=
    ('str',
     "'edit' or 'hamming' as distance measure. Default 'edit' to include insertion / deletion"
     ),
    spike_in_seq=('str', 'center sequence for spike-in'),
    spike_in_amount=(
        'list-like, dict, or pd.Series',
        'added spike_in amount, dict and pd.Series should have key of '
        'samples in base_table list-like should have same length as '
        'number of samples (cols) in base_table'))


@_spike_in_doc.compose(
    """Normalized counts to absolute amount using spike-in information

Attributes:
Exemple #10
0
def test_DocHelper_stores_doc():
    doc = DocHelper(arg1='Docstring for arg1',
                    arg2=('Docstring for arg2'),
                    arg3=('type for arg3', 'Docstring for arg3'))
    assert doc.var_lib.shape == (3, 2)
Exemple #11
0
from yutility import logging
from .transform import _spike_in_doc, _total_dna_doc
from doc_helper import DocHelper


_doc = DocHelper(
    x_values=('list-like, or dict', 'optional. value for controlled variables. If list-like, should have same length '
                                    'and order as samples; if dict, should have sample names as key'),
    x_unit=('str', "optional. Unit for controlled variable. e.g. 'uM'"),
    input_sample_name=('list of str', 'optional. Indicate input samples (unreacted)'),
    sample_metadata=('dict of objects', 'optional. Extra sample metadata'),
    seq_metadata=('dict of objects', 'optional. Extra seq metadata'),
    dataset_metadata=('dict of objects', 'optional. Extra dataset metadata'),
    note=('str', 'Note for dataset/seq_table'),
    data=('pd.DataFrame or np.ndarray', '2-D data with indices as sequences and columns as samples. '
                                        'If data is pd.DataFrame, values in index and column will be used as '
                                        'sequences and samples; if data is a 2-D np.ndarray, `sample_list` and '
                                        '`seq_to_fit` are needed with same length and order as data'),
    sample_list=('list-like', 'list of samples in the sample, should match the columns in the seq_table data'),
    seq_list=('list-like', 'list of seqs in the sample, should match the rows in the seq_table data'),
    data_unit=('str', 'The unit of seq_table values, e.g. counts, ng, M. Default counts.'),
    use_sparse=('bool', 'If store the seq_table value as sparse matrix'),
    data_note=('str', 'Note for data seq_table'),
    remove_empty=('bool', 'If remove the empty column/rows after filtering')

)


class SeqTable(pd.DataFrame):
    """Extended ``pd.DataFrame`` with added property and functions for SeqTable
Exemple #12
0
        mark_pdf = PDFHelper.create_word_mark(sys.argv[3], sys.argv[2])
        print('the watermark is saved as ' + str(mark_pdf))
        print('adding watermark...')
        PDFHelper.add_mark(sys.argv[2], mark_pdf)
    elif key == 'pdf-mark-img':
        print('creating image watermark...')
        mark_pdf = PDFHelper.create_image_mark(sys.argv[3], sys.argv[2])
        print('the watermark is saved as ' + str(mark_pdf))
        print('adding watermark...')
        PDFHelper.add_mark(sys.argv[2], mark_pdf)
    elif key == 'pdf-2-txt':
        PDFHelper.to_txt(sys.argv[2])
    elif key == 'pdf-2-word':
        PDFHelper.to_word(sys.argv[2])
    elif key == 'word-2-pdf':
        # DocHelper.word_2_pdf(sys.argv[2])
        DocHelper.convert(sys.argv[2:], fun=DocHelper.word_2_pdf)
    elif key == 'excel-2-pdf':
        # DocHelper.excel_2_pdf(sys.argv[2])
        DocHelper.convert(sys.argv[2:], fun=DocHelper.excel_2_pdf)
    elif key == 'ppt-2-pdf':
        # DocHelper.ppt_2_pdf(sys.argv[2])
        DocHelper.convert(sys.argv[2:], fun=DocHelper.ppt_2_pdf)
    elif key == 'dl-img':
        DLImg.dlImg(sys.argv[2])
    elif key == 'dl-video':
        DLVideo.dlVideos(sys.argv[2])
    else:
        print('Input error!!!')
        print('Errors may occur if the file path contains spaces!!!')
Exemple #13
0
Distance.__doc__ = """Accessor to `python-levenshtein` module for distance measure

Common functions:
  - distance(seq1, seq2): levenshtein distance between two sequences
  - hamming(seq1, seq2): hamming distance between two sequences 
"""

peak_doc = DocHelper(
    center_seq=('str', 'center sequence of the peak'),
    seqs=
    ('list-like of str, pd.DataFrame',
     'A list-like (list, np.ndarray, pd.Series) of str for a collect of '
     'sequences in the landscape to survey. Or a pd.DataFrame table with '
     'sequences as indices, samples as columns as quantity measures (e.g. counts'
     ),
    radius=
    ('int',
     'radius of the peak for a sequence to be considered as a member, optional'
     ),
    name=('str', 'peak name, optional'),
    dist_to_center=('pd.Series', 'Distance of sequences to the peak center'),
    letterbook_size=(
        'int',
        'Size of letter book (A, T, C, F) in the sequence space. Default 4.'))


class Scope:
    """Simple scope to contain relavent info"""
    def __init__(self, **kwargs):
        if kwargs != {}:
            for key, arg in kwargs.items():
Exemple #14
0
import json


__all__ = ['doc_helper', 'SingleFitter', 'FitResults']


doc_helper = DocHelper(
    x_data=('list', 'list of x values in fitting'),
    y_data=('list, pd.Series', 'y values in fitting'),
    x_label=('str', 'name of x data'),
    y_label=('str', 'name of y data'),
    model=('callable', 'model to fit'),
    name=('str', "Optional. Estimator's name"),
    sigma=('list, pd.Series, or pd.DataFrame', 'Optional, same size as y_data/y_dataframe.'
                                               'Sigma (variance) for data points for weighted fitting'),
    bounds=('2 by m `list` ', 'Optional, [[lower bounds], [higher bounds]] for each parameter'),
    opt_method=('str', "Optimization methods in `scipy.optimize`. Default 'trf'"),

    exclude_zero=('bool', "If exclude zero/missing data in fitting. Default False."),
    init_guess=('list of float or generator', "Initial guess estimate parameters, random value from 0 to 1 "
                                              "will be use if None"),
    metrics=('dict of callable', "Optional. Extra metric/parameters to calculate for each estimation"),
    rnd_seed=('int', "random seed used in fitting for reproducibility"),
    curve_fit_kwargs=('dict', 'other keyword parameters to pass to `scipy.optimize.curve_fit`'),
)

# add replicates/bootstrap related arguments
doc_helper.add(
    estimator=('Estimator', 'estimator for fitting'),
    replicates=('list of list', 'List of list of sample names for each replicates'),
    bootstrap_num=('`int`', 'Number of bootstrap to perform, 0 means no bootstrap'),