Skip to content

Commit

Permalink
Definitely fix the "new-line error"
Browse files Browse the repository at this point in the history
  • Loading branch information
Davide Albanese committed Mar 31, 2017
1 parent ea5d561 commit 2ce9e7f
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions micca/api/_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ def add_phred_quality(records, defaultq):
"quality file")

# parse records
input_handle = open(input_fn, 'r')
input_handle = open(input_fn, 'rU')
if input_fmt == "fasta-qual":
qual_handle = open(qual_fn, 'r')
qual_handle = open(qual_fn, 'rU')
records = PairedFastaQualIterator(input_handle, qual_handle)
else:
records = SeqIO.parse(input_handle, input_fmt)
Expand Down
2 changes: 1 addition & 1 deletion micca/api/_filterstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def _stats(input_fn, topn=None, maxeerates=[0.25, 0.5, 0.75, 1, 1.25, 1.5],
eerate_minlen = np.array([], dtype=np.int, order='C')
eerate_trunclen = np.array([], dtype=np.int, order='C')

with open(input_fn, "r") as input_handle:
with open(input_fn, "rU") as input_handle:
for title, seq, qualstr in FastqGeneralIterator(input_handle):
seqlen = len(seq)
if (seqlen < 1):
Expand Down
2 changes: 1 addition & 1 deletion micca/api/_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def _stats(input_fn, topn=None):
qual_sum = np.array([], dtype=np.int, order='C')
eerate_sum = np.array([], dtype=np.float, order='C')

with open(input_fn, "r") as input_handle:
with open(input_fn, "rU") as input_handle:
for title, seq, qualstr in FastqGeneralIterator(input_handle):

seqlen = len(seq)
Expand Down
2 changes: 1 addition & 1 deletion micca/api/classify.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def get_cons_tax(tax, minfrac):
os.remove(hits_temp_fn)
raise

with open(hits_temp_fn, 'rb') as hits_temp_handle:
with open(hits_temp_fn, 'rU') as hits_temp_handle:
with open(output_fn, 'wb') as output_handle:
hits_temp_reader = csv.reader(hits_temp_handle, delimiter='\t')
output_writer = csv.writer(
Expand Down
8 changes: 4 additions & 4 deletions micca/api/msa.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def _nast_core(template, template_aln, candidate_aln):
def _msa_count_columns(input_fn):
"""Count columns in a MSA in FASTA format.
"""
with open(input_fn, "r") as input_handle:
with open(input_fn, "rU") as input_handle:
parser = SimpleFastaParser(input_handle)
try:
title, seq = parser.next()
Expand All @@ -127,7 +127,7 @@ def _msa_remove_gaps(input_fn, output_fn):
"""Write a new file without gap characters (-).
"""

input_handle = open(input_fn, "r")
input_handle = open(input_fn, "rU")
output_handle = open(output_fn, "wb")

for title, seq in SimpleFastaParser(input_handle):
Expand Down Expand Up @@ -233,7 +233,7 @@ def nast(input_fn, template_fn, output_fn, notaligned_fn=None, hits_fn=None,
hits_out_handle = open(hits_out_fn, "wb")

# set up hits reader
hits_temp_handle = open(hits_temp_fn, 'rb')
hits_temp_handle = open(hits_temp_fn, 'rU')
hits_temp_reader = csv.reader(hits_temp_handle, delimiter='\t')

# set MSA coverage to zero
Expand Down Expand Up @@ -313,7 +313,7 @@ def nast(input_fn, template_fn, output_fn, notaligned_fn=None, hits_fn=None,
if nofilter:
os.rename(output_temp_fn, output_fn)
else:
output_temp_handle = open(output_temp_fn, "r")
output_temp_handle = open(output_temp_fn, "rU")
output_handle = open(output_fn, "wb")
for title, seq in SimpleFastaParser(output_temp_handle):
seqout = "".join(np.array(list(seq))[msa_cov > 0])
Expand Down
18 changes: 9 additions & 9 deletions micca/api/otu.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def _rename_seqids(input_fn, otuids_fn, prefix=""):
output_dir = os.path.dirname(input_fn)

tmp_fn = micca.ioutils.make_tempfile(output_dir)
input_handle = open(input_fn, "r")
input_handle = open(input_fn, "rU")
otuids_handle = open(otuids_fn, "wb")
tmp_handle = open(tmp_fn, "wb")

Expand All @@ -65,14 +65,14 @@ def _rename_seqids(input_fn, otuids_fn, prefix=""):

def _hits_to_otutable(hits_fn, otuids_fn, otutable_fn):

with open(otuids_fn, 'rb') as otuids_handle:
with open(otuids_fn, 'rU') as otuids_handle:
otuids_reader = csv.reader(otuids_handle, delimiter='\t')
otuids = [(row[1], row[0]) for row in otuids_reader]
ordered_otuids = [otuid[1] for otuid in otuids]
otuids_dict = dict(otuids)

otutable_dict = {}
with open(hits_fn, 'rb') as hits_handle:
with open(hits_fn, 'rU') as hits_handle:
hits_reader = csv.reader(hits_handle, delimiter='\t')
for row in hits_reader:
match = re.search("(^|;)sample=([^;]+)", row[0])
Expand All @@ -97,7 +97,7 @@ def _uc_to_hitssqlite(uc_fn, sqlite_fn):
cur = con.cursor()
cur.execute('CREATE TABLE hits (query text, target text, ident real)')

with open(uc_fn, 'rb') as uc_handle:
with open(uc_fn, 'rU') as uc_handle:
uc_reader = csv.reader(uc_handle, delimiter='\t')
for row in uc_reader:
rtype, ident, query, target = row[0], row[3], row[8], row[9]
Expand Down Expand Up @@ -343,15 +343,15 @@ def open_ref(input_fn, ref_fn, output_dir, ident=0.97, threads=1, mincov=0.75,
raise

with open(otus_fn, 'a') as otus_handle:
with open(denovo_otus_fn, 'r') as denovo_otus_handle:
with open(denovo_otus_fn, 'rU') as denovo_otus_handle:
otus_handle.write(denovo_otus_handle.read())

with open(otuids_fn, 'a') as otuids_handle:
with open(denovo_otuids_fn, 'r') as denovo_otuids_handle:
with open(denovo_otuids_fn, 'rU') as denovo_otuids_handle:
otuids_handle.write(denovo_otuids_handle.read())

with open(hits_fn, 'a') as hits_handle:
with open(denovo_hits_fn, 'r') as denovo_hits_handle:
with open(denovo_hits_fn, 'rU') as denovo_hits_handle:
hits_handle.write(denovo_hits_handle.read())

os.remove(denovo_otus_fn)
Expand Down Expand Up @@ -462,7 +462,7 @@ def strip_size(s):

# write the OTUs file and store the OTU ids
otuids = []
otus_nochim_handle = open(otus_nochim_fn, "rb")
otus_nochim_handle = open(otus_nochim_fn, "rU")
otus_handle = open(otus_fn, "wb")
for i, (title, seq) in enumerate(SimpleFastaParser(otus_nochim_handle)):
otuid = strip_size(title.split()[0])
Expand All @@ -474,7 +474,7 @@ def strip_size(s):
os.remove(otus_nochim_fn)

# write the hits file
swarms_temp_handle = open(swarms_temp_fn, 'rb')
swarms_temp_handle = open(swarms_temp_fn, 'rU')
swarms_temp_reader = csv.reader(swarms_temp_handle, delimiter=' ')
hits_handle = open(hits_fn, 'wb')
hits_writer = csv.writer(hits_handle, delimiter='\t', lineterminator='\n')
Expand Down

0 comments on commit 2ce9e7f

Please sign in to comment.