Fixed merge conflict

This commit is contained in:
Celine Mercier
2016-08-10 15:05:37 +02:00
12 changed files with 177 additions and 39 deletions

View File

@ -7,7 +7,9 @@ Created on 27 mars 2016
'''
import sys
from ..utils cimport bytes2str
from ..utils import bytes2str,str2bytes
from .config cimport getConfiguration
cdef class ProgressBar:
cdef clock_t clock(self):
@ -23,7 +25,7 @@ cdef class ProgressBar:
def __init__(self,
off_t maxi,
dict config,
dict config={},
str head="",
double seconde=0.1):
self.starttime = self.clock()
@ -34,14 +36,18 @@ cdef class ProgressBar:
self.arrow = 0
self.lastlog = 0
if not config:
config=getConfiguration()
self.ontty = sys.stderr.isatty()
if (maxi<=0):
maxi=1
self.maxi = maxi
self.head = str2bytes(head)
self.chead= self.head
self._head = str2bytes(head)
self.chead= self._head
self.logger=config[config["__root_config__"]]["logger"]
@ -104,35 +110,43 @@ cdef class ProgressBar:
if self.ontty:
fraction=<int>(percent * 50.)
self.arrow=(self.arrow+1) % 4
self.diese[fraction]=0
self.spaces[50 - fraction]=0
if days:
<void>fprintf(stderr,b'\r%s %5.1f %% |%s%c%s] remain : %d days %02d:%02d:%02d',
<void>fprintf(stderr,b'\r%s %5.1f %% |%.*s%c%.*s] remain : %d days %02d:%02d:%02d',
self.chead,
percent*100,
self.diese,self.wheel[self.arrow],self.spaces,
fraction,self.diese,
self.wheel[self.arrow],
50-fraction,self.spaces,
days,hour,minu,sec)
else:
<void>fprintf(stderr,b'\r%s %5.1f %% |%s%c%s] remain : %02d:%02d:%02d',
<void>fprintf(stderr,b'\r%s %5.1f %% |%.*s%c%.*s] remain : %02d:%02d:%02d',
self.chead,
percent*100.,
self.diese,self.wheel[self.arrow],self.spaces,
fraction,self.diese,
self.wheel[self.arrow],
50-fraction,self.spaces,
hour,minu,sec)
self.diese[fraction]=b'#'
self.spaces[50 - fraction]=b' '
twentyth = int(percent * 20)
if twentyth != self.lastlog:
tenth = int(percent * 10)
if tenth != self.lastlog:
if self.ontty:
<void>fputs(b'\n',stderr)
self.logger.info('%s %5.1f %% remain : %02d:%02d:%02d' % (
bytes2str(self.head),
bytes2str(self._head),
percent*100.,
hour,minu,sec))
self.lastlog=twentyth
self.lastlog=tenth
else:
self.cycle+=1
property head:
def __get__(self):
return self._head
def __set__(self,str value):
self._head=str2bytes(value)
self.chead=self._head

View File

View File

@ -0,0 +1,10 @@
from ..utils cimport bytes2str
from .header cimport HeaderFormat
from cython.view cimport array as cvarray
cdef class FastaFormat:
cdef HeaderFormat headerFormater
cdef size_t sequenceBufferLength
cdef char* sequenceBuffer

View File

@ -0,0 +1,32 @@
cimport cython
from libc.stdlib cimport malloc, free, realloc
from libc.string cimport strncpy
cdef class FastaFormat:
def __init__(self, list tags=[], bint printNAKeys=False):
self.headerFormater = HeaderFormat(True,
tags,
printNAKeys)
@cython.boundscheck(False)
def __call__(self, dict data):
cdef bytes brawseq = data['sequence']
cdef size_t lseq = len(brawseq)
cdef size_t k=0
cdef list lines = []
for k in range(0,lseq,60):
lines.append(brawseq[k:(k+60)])
brawseq = b'\n'.join(lines)
return "%s\n%s" % (self.headerFormater(data),bytes2str(brawseq))

View File

@ -0,0 +1,7 @@
cdef class HeaderFormat:
cdef str start
cdef set tags
cdef bint printNaKeys
cdef size_t headerBufferLength

View File

@ -0,0 +1,60 @@
cdef class HeaderFormat:
def __init__(self, bint fastaHeader=True, list tags=[], bint printNAKeys=False):
'''
@param fastaHeader:
@type fastaHeader: `bool`
@param tags:
@type tags: `list` of `bytes`
@param printNAKeys:
@type printNAKeys: `bool`
'''
self.tags = set(tags)
self.printNaKeys = printNAKeys
if fastaHeader:
self.start=">"
else:
self.start="@"
self.headerBufferLength = 1000
#self.headerBuffer = []
def __call__(self, dict data):
cdef str header
cdef dict tags = data['tags']
cdef set ktags
cdef list lines = [""]
cdef str tagline
if self.tags is not None and self.tags:
ktags = self.tags
else:
ktags = set(tags.keys())
for k in ktags:
if k in tags:
value = tags[k]
if value is not None or self.printNaKeys:
lines.append("%s=%s;" % (k,tags[k]))
if len(lines) > 1:
tagline=" ".join(lines)
else:
tagline=""
if data['definition'] is not None:
header = "%s%s%s %s" % (self.start,data['id'],
tagline,
data['definition'])
else:
header = "%s%s%s" % (self.start,data['id'],
tagline)
return header

View File

@ -26,17 +26,26 @@ cdef class OBIDMS_column_seq(OBIDMS_column):
if value == OBISeq_NA :
result = None
else :
result = bytes2str(value)
free(value)
try:
result = <bytes> value
finally:
free(value)
return result
cpdef set_line(self, index_t line_nb, object value):
cdef bytes value_b
if value is None :
if obi_set_seq_with_elt_idx_and_col_p_in_view(self.view.pointer, (self.pointer)[0], line_nb, 0, OBISeq_NA) < 0:
raise Exception("Problem setting a value in a column")
else :
if obi_set_seq_with_elt_idx_and_col_p_in_view(self.view.pointer, (self.pointer)[0], line_nb, 0, str2bytes(value)) < 0:
raise Exception("Problem setting a value in a column")
value_b = OBISeq_NA
elif isinstance(value, bytes) :
value_b = value
elif isinstance(value, str) :
value_b = str2bytes(value)
else:
raise TypeError('Sequence value must be of type Bytes, Str or None')
if obi_set_seq_with_elt_idx_and_col_p_in_view(self.view.pointer, (self.pointer)[0], line_nb, 0, value_b) < 0:
raise Exception("Problem setting a value in a column")
cdef class OBIDMS_column_multi_elts_seq(OBIDMS_column_multi_elts):
@ -50,10 +59,13 @@ cdef class OBIDMS_column_multi_elts_seq(OBIDMS_column_multi_elts):
if value == OBISeq_NA :
result = None
else :
result = bytes2str(value)
free(value)
try:
result = <bytes> value
finally:
free(value)
return result
cpdef object get_line(self, index_t line_nb) :
cdef char* value
cdef object value_in_result
@ -69,8 +81,10 @@ cdef class OBIDMS_column_multi_elts_seq(OBIDMS_column_multi_elts):
if value == OBISeq_NA :
value_in_result = None
else :
value_in_result = bytes2str(value)
free(value)
try:
value_in_result = <bytes> value
finally:
free(value)
result[self.elements_names[i]] = value_in_result
if all_NA and (value_in_result is not None) :
all_NA = False
@ -92,7 +106,4 @@ cdef class OBIDMS_column_multi_elts_seq(OBIDMS_column_multi_elts):
if obi_set_seq_with_elt_name_and_col_p_in_view(self.view.pointer, (self.pointer)[0], line_nb, str2bytes(element_name), value_b) < 0:
raise Exception("Problem setting a value in a column")
# cpdef align(self, ): # TODO
# raise Exception("Columns with multiple sequences per line can't be aligned") # TODO discuss

View File

@ -1,5 +1,6 @@
#cython: language_level=3
from ..utils cimport str2bytes
from .header cimport parseHeader
from ..files.universalopener cimport uopen
from ..files.linebuffer cimport LineBuffer

View File

@ -6,12 +6,15 @@ Created on 30 mars 2016
@author: coissac
'''
def fastaIterator(lineiterator, int buffersize=100000000):
cdef LineBuffer lb
cdef str ident
cdef str definition
cdef dict tags
cdef list s
cdef bytes sequence
cdef bytes quality
if isinstance(lineiterator,(str,bytes)):
lineiterator=uopen(lineiterator)
@ -31,12 +34,12 @@ def fastaIterator(lineiterator, int buffersize=100000000):
try:
while line[0]!='>':
s.append(line[0:-1])
s.append(str2bytes(line)[0:-1])
line = next(i)
except StopIteration:
pass
sequence = "".join(s)
sequence = b"".join(s)
quality = None
yield { "id" : ident,

View File

@ -1,5 +1,7 @@
#cython: language_level=3
from ..utils cimport str2bytes
from .header cimport parseHeader
from ..files.universalopener cimport uopen
from ..files.linebuffer cimport LineBuffer

View File

@ -6,15 +6,13 @@ Created on 30 mars 2016
@author: coissac
'''
def fastqIterator(lineiterator, int buffersize=100000000):
cdef LineBuffer lb
cdef str ident
cdef str definition
cdef dict tags
cdef bytes sequence
cdef bytes quality
if isinstance(lineiterator,(str,bytes)):
lineiterator=uopen(lineiterator)
@ -27,9 +25,9 @@ def fastqIterator(lineiterator, int buffersize=100000000):
i = iter(lb)
for line in i:
ident,tags,definition = parseHeader(line)
sequence = next(i)[0:-1]
sequence = str2bytes(next(i)[0:-1])
next(i)
quality = next(i)[0:-1]
quality = str2bytes(next(i)[0:-1])
yield { "id" : ident,
"definition" : definition,

View File

@ -1,5 +1,5 @@
--extra-index-url https://pypi.python.org/simple/
Cython==0.23.5
Cython>=0.24
Sphinx>=1.2.0
ipython>=3.0.0
breathe>=4.0.0