seqenv.common package

Submodules

seqenv.common.autopaths module

class seqenv.common.autopaths.DirectoryPath(path)[source]

Bases: str

absolute_path

The absolute path starting with a /

classmethod clean_path(path)[source]

Given a path, return a cleaned up version for initialization.

create(safe=False, inherit=True)[source]
create_if_not_exists()[source]
directory

The full path of directory containing this one

exists

Does it exist in the file system?

Is this directory a symbolic link to an other directory?

name

Just the directory name

permissions

Convenience object for dealing with permissions.

remove()[source]
class seqenv.common.autopaths.FilePath(path)[source]

Bases: str

I can never remember all those darn os.path commands, so I made a class that wraps them with an easier and more pythonic syntax.

path = FilePath(‘/home/root/text.txt’) print path.extension print path.directory print path.filename

You can find lots of the common things you would need to do with file paths. Such as: path.make_executable() etc etc.

absolute_path

The absolute path starting with a /

classmethod clean_path(path)[source]

Given a path, return a cleaned up version for initialization

count_bytes

The number of bytes

count_lines
directory

The directory containing this file

exists

Does it exist in the file system. Returns True or False.

extension

The extension with the leading period

filename

Just the filename with the extension

Make a link here pointing to another file somewhere else. The destination is hence self.path and the source is path.

Create a link somewhere else pointing to this file. The destination is hence path and the source is self.path.

must_exist()[source]

Raise an exception if the path doesn’t exist.

prefix

Just the filename without the (last) extension and trailing period

prefix_path

The full path without the (last) extension and trailing period

remove()[source]
size

Human readable file size

unzip_to(destination=None, inplace=False)[source]

Make an unzipped version of the file at a given path

write(contents)[source]
writelines(contents)[source]
class seqenv.common.autopaths.FilePermissions(path)[source]

Bases: object

Container for reading and setting a files permissions

make_executable()[source]
number

The permission bits as an octal integer

only_readable()[source]

Remove all writing privileges

class seqenv.common.autopaths.Filesize(size)[source]

Bases: object

Container for a size in bytes with a human readable representation Use it like this:

>>> size = Filesize(123123123)
>>> print size
'117.4 MiB'
chunk = 1000
format(unit)[source]
precisions = [0, 0, 1, 2, 2, 2]
units = ['bytes', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB']

seqenv.common.cache module

seqenv.common.cache.cached(f)[source]

Decorator for functions evaluated only once.

class seqenv.common.cache.class_property[source]

Bases: property

You can use this like this: class Foo(object):

@class_property @classmethod @cached def bar(cls):

return 1+1
seqenv.common.cache.property_cached(f)[source]

Decorator for properties evaluated only once. It can be used to created a cached property like this:

class Employee(object):

@property_cached def salary(self):

print “Evaluating...” return time.time()

bob = Employee() print bob.salary bob.salary = “10000$” print bob.salary

seqenv.common.color module

class seqenv.common.color.Color[source]

Shortcuts for the ANSI escape sequences to control formatting, color, etc. on text terminals. Use it like this:

print Color.red + “Hello world” + Color.end
b_blk = '\x1b[1;30m'
b_blu = '\x1b[1;34m'
b_cyn = '\x1b[1;36m'
b_grn = '\x1b[1;32m'
b_pur = '\x1b[1;35m'
b_red = '\x1b[1;31m'
b_wht = '\x1b[1;37m'
b_ylw = '\x1b[1;33m'
blk = '\x1b[0;30m'
blu = '\x1b[0;34m'
bold = '\x1b[1m'
cyn = '\x1b[0;36m'
end = '\x1b[0m'
f_blk = '\x1b[40m'
f_blu = '\x1b[44m'
f_cyn = '\x1b[46m'
f_grn = '\x1b[42m'
f_pur = '\x1b[45m'
f_red = '\x1b[41m'
f_wht = '\x1b[47m'
f_ylw = '\x1b[43m'
flash = '\x1b[5m'
g_blk = '\x1b[5;30m'
g_blu = '\x1b[5;34m'
g_cyn = '\x1b[5;36m'
g_grn = '\x1b[5;32m'
g_pur = '\x1b[5;35m'
g_red = '\x1b[5;31m'
g_wht = '\x1b[5;37m'
g_ylw = '\x1b[5;33m'
grn = '\x1b[0;32m'
i_blk = '\x1b[3;30m'
i_blu = '\x1b[3;34m'
i_cyn = '\x1b[3;36m'
i_grn = '\x1b[3;32m'
i_pur = '\x1b[3;35m'
i_red = '\x1b[3;31m'
i_wht = '\x1b[3;37m'
i_ylw = '\x1b[3;33m'
italic = '\x1b[1m'
l_blk = '\x1b[2;30m'
l_blu = '\x1b[2;34m'
l_cyn = '\x1b[2;36m'
l_grn = '\x1b[2;32m'
l_pur = '\x1b[2;35m'
l_red = '\x1b[2;31m'
l_wht = '\x1b[2;37m'
l_ylw = '\x1b[2;33m'
light = '\x1b[2m'
pur = '\x1b[0;35m'
red = '\x1b[0;31m'
u_blk = '\x1b[4;30m'
u_blu = '\x1b[4;34m'
u_cyn = '\x1b[4;36m'
u_grn = '\x1b[4;32m'
u_pur = '\x1b[4;35m'
u_red = '\x1b[4;31m'
u_wht = '\x1b[4;37m'
u_ylw = '\x1b[4;33m'
underline = '\x1b[4m'
wht = '\x1b[0;37m'
ylw = '\x1b[0;33m'

seqenv.common.database module

class seqenv.common.database.Database(path, factory=None, text_fact=None, isolation=None, retrieve=None, md5=None)[source]

Bases: seqenv.common.autopaths.FilePath

add(entries, table=None, columns=None, ignore=False)[source]

Add entries to a table. The entries variable should be an iterable.

add_by_steps(entries_by_step, table=None, columns=None)[source]

Add entries to the main table. The entries variable should be an iterable yielding iterables.

add_column(name, kind=None, table=None)[source]

Add add a new column to a table.

add_table(name, columns, type_map=None, if_not_exists=False)[source]

Add add a new table to the database. For instance you could do this: self.add_table(‘data’, {‘id’:’integer’, ‘source’:’text’, ‘pubmed’:’integer’})

check_format()[source]
close()[source]
columns

The list of columns available in every entry.

connection

To be used externally by the user.

count_entries(table=None)[source]

How many rows in a table.

create(columns, type_map=None, overwrite=False)[source]

Create a new database with a certain schema.

cursor

To be used externally by the user.

detailed_error(sql_command, columns, entries, err)[source]
execute(*args, **kwargs)[source]

Convenience shortcut.

first

Just the first entry.

frame

The main table as a blaze data structure. Not ready yet.

get(table, column, key)[source]
get_and_order(ids, column=None, table=None)[source]

Get specific entries and order them in the same way.

get_columns_of_table(table=None)[source]

Return the list of columns for a particular table by querying the SQL for the complete list of column names.

get_entry(key, column=None, table=None)[source]

Get a specific entry.

get_first(table=None)[source]

Just the first entry.

get_last(table=None)[source]

Just the last entry.

get_number(num, table=None)[source]

Get a specific entry by it’s number.

index(column='id', table=None)[source]
last

Just the last entry.

main_table
new_connection()[source]

Make a new connection.

open()[source]

Reopen a database that was closed, useful for debugging.

own_connection

To be used internally in this object.

own_cursor

To be used internally in this object.

prepare()[source]

Check that the file exists, optionally downloads it. Checks that the file is indeed an SQLite3 database. Optionally check the MD5.

tables

The complete list of SQL tables.

uniquify(name, kind=None, table=None)[source]

Remove entries that have duplicate values on a specific column.

vacuum()[source]

Compact the database, remove old transactions.

seqenv.common.git module

class seqenv.common.git.GitRepo(path)[source]

Bases: object

A git repository with some convenience methods.

branch

For instance: u’master’

hash

For instance: u’f0c796dae64a5a118d88e60523c011d535e8c476’

remote_branch

For instance: u’origin/master’

short_hash

For instance: u’f0c796dae64a5a118d88e60523c011d535e8c476’

tag

For instance: u‘1.0.3-69-gf0c796d-dirty’

seqenv.common.timer module

class seqenv.common.timer.Timer[source]

Bases: object

Useful for timing the different steps in a pipeline

color

Should we use color or not ? If we are not in a shell like ipython then not

prefix
print_elapsed(reset=True)[source]
print_end()[source]
print_start()[source]
print_total_elapsed(reset=True)[source]
suffix

seqenv.common.tmpstuff module

class seqenv.common.tmpstuff.TmpFile(path=None, content=None, **kwargs)[source]

Bases: seqenv.common.autopaths.FilePath

classmethod empty(**kwargs)[source]
classmethod from_string(string, **kwargs)[source]
seqenv.common.tmpstuff.new_temp_file(**kwargs)[source]

A new temporary file

seqenv.common.tmpstuff.new_temp_path(**kwargs)[source]

A new temporary path

Module contents

class seqenv.common.GenWithLength(gen, length)[source]

Bases: object

A generator with a length attribute

seqenv.common.download_from_url(source, destination, progress=False, uncompress=True)[source]

Download a file from an URL and place it somewhere. Like wget. Uses requests and tqdm to display progress if you want. By default it will uncompress files.

seqenv.common.flatter(x)
seqenv.common.md5sum(file_path, blocksize=65536)[source]

Compute the md5 of a file. Pretty fast.

seqenv.common.new_temp_path(**kwargs)[source]

A new temporary path

seqenv.common.pretty_now()[source]

Returns some thing like ‘2014-07-24 11:12:45 CEST+0200’

seqenv.common.unzip(source, destination=None, inplace=False, single=True)[source]

Unzip a standard zip file. Can specify the destination of the uncompressed file, or just set inplace=True to delete the original.