Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
karel-brinda committed Jun 20, 2017
1 parent 82c53e8 commit d79f875
Show file tree
Hide file tree
Showing 8 changed files with 459 additions and 461 deletions.
106 changes: 53 additions & 53 deletions rnftools/rnfformat/FqCreator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import rnftools
import os


class FqCreator:
"""Class for writing RNF reads to FASTQ files.
Expand All @@ -21,25 +22,25 @@ class FqCreator:
"""

def __init__(
self,
fastq_fo,
read_tuple_id_width=16,
genome_id_width=2,
chr_id_width=2,
coor_width=8,
info_reads_in_tuple=True,
info_simulator=None,
):
self._info_simulator=info_simulator
self._info_reads_in_tuple=info_reads_in_tuple
self._rnf_profile=rnftools.rnfformat.RnfProfile(
read_tuple_id_width=read_tuple_id_width,
genome_id_width=genome_id_width,
chr_id_width=chr_id_width,
coor_width=coor_width,
)
self._fq_file=fastq_fo
self.current_read_tuple_id=None
self,
fastq_fo,
read_tuple_id_width=16,
genome_id_width=2,
chr_id_width=2,
coor_width=8,
info_reads_in_tuple=True,
info_simulator=None,
):
self._info_simulator = info_simulator
self._info_reads_in_tuple = info_reads_in_tuple
self._rnf_profile = rnftools.rnfformat.RnfProfile(
read_tuple_id_width=read_tuple_id_width,
genome_id_width=genome_id_width,
chr_id_width=chr_id_width,
coor_width=coor_width,
)
self._fq_file = fastq_fo
self.current_read_tuple_id = None
self.empty()

def __del__(self):
Expand All @@ -49,35 +50,35 @@ def flush_read_tuple(self):
"""Flush the internal buffer of reads.
"""
if not self.is_empty():
suffix_comment_buffer=[]
suffix_comment_buffer = []
if self._info_simulator is not None:
suffix_comment_buffer.append(self._info_simulator)
if self._info_reads_in_tuple:
#todo: orientation (FF, FR, etc.)
#orientation="".join([])
# todo: orientation (FF, FR, etc.)
# orientation="".join([])
suffix_comment_buffer.append("reads-in-tuple:{}".format(len(self.seqs_bases)))
if len(suffix_comment_buffer)!=0:
suffix_comment="[{}]".format(",".join(suffix_comment_buffer))
if len(suffix_comment_buffer) != 0:
suffix_comment = "[{}]".format(",".join(suffix_comment_buffer))
else:
suffix_comment=""

rnf_name=self._rnf_profile.get_rnf_name(
rnftools.rnfformat.ReadTuple(
segments=self.segments,
read_tuple_id=self.current_read_tuple_id,
suffix=suffix_comment,
)
)
suffix_comment = ""

rnf_name = self._rnf_profile.get_rnf_name(
rnftools.rnfformat.ReadTuple(
segments=self.segments,
read_tuple_id=self.current_read_tuple_id,
suffix=suffix_comment,
)
)
fq_reads = [
os.linesep.join([
"@{rnf_name}{read_suffix}".format(
rnf_name=rnf_name,
read_suffix="/{}".format(str(i+1)) if len(self.seqs_bases)>1 else "",
),
self.seqs_bases[i],
"+",
self.seqs_qualities[i],
])
"@{rnf_name}{read_suffix}".format(
rnf_name=rnf_name,
read_suffix="/{}".format(str(i + 1)) if len(self.seqs_bases) > 1 else "",
),
self.seqs_bases[i],
"+",
self.seqs_qualities[i],
])
for i in range(len(self.seqs_bases))
]
self._fq_file.write(os.linesep.join(fq_reads))
Expand All @@ -87,22 +88,21 @@ def flush_read_tuple(self):
def empty(self):
"""Empty all internal buffers.
"""
self.seqs_bases=[]
self.seqs_qualities=[]
self.segments=[]
self.seqs_bases = []
self.seqs_qualities = []
self.segments = []

def is_empty(self):
"""All internal buffer empty?
"""
return self.seqs_bases==[] and self.seqs_qualities==[] and self.segments==[]

return self.seqs_bases == [] and self.seqs_qualities == [] and self.segments == []

def add_read(self,
read_tuple_id,
bases,
qualities,
segments,
):
read_tuple_id,
bases,
qualities,
segments,
):

"""Add a new read to the current buffer. If it is a new read tuple (detected from ID), the buffer will be flushed.
Expand All @@ -117,9 +117,9 @@ def add_read(self,
assert type(qualities) is str, "Wrong type of qualities: '{}'".format(qualities)
assert type(segments) is tuple or type(segments) is list

if self.current_read_tuple_id!=read_tuple_id:
if self.current_read_tuple_id != read_tuple_id:
self.flush_read_tuple()
self.current_read_tuple_id=read_tuple_id
self.current_read_tuple_id = read_tuple_id

self.seqs_bases.append(bases)
self.seqs_qualities.append(qualities)
Expand Down

0 comments on commit d79f875

Please sign in to comment.