1-
1+ from __future__ import print_function
22import numpy as np
33from matplotlib import use as mpl_use
44mpl_use(' Agg' ) # Must be before importing matplotlib.pyplot or pylab
55import matplotlib.pyplot as plt
6- from sys import stderr
6+ import sys
77import cjson
88import gzip
99import re
@@ -114,7 +114,7 @@ def plotBCdistribution(barcode_family_count, outputprefix):
114114 ax.spines[' right' ].set_visible(False )
115115 ax.spines[' top' ].set_visible(False )
116116 fig.savefig(figurename)
117- stderr.write (' Plotted %s .\n ' % figurename)
117+ print (' Plotted %s .' % figurename, file = sys.stderr )
118118 return 0
119119
120120def concensusPairs (table , float fraction_threshold ):
@@ -140,7 +140,7 @@ def concensusPairs(table, float fraction_threshold):
140140def dictToJson (barcode_dict , json_file ):
141141 with open (json_file,' w' ) as f:
142142 [f.write(cjson.encode(items) + ' \n ' ) for items in barcode_dict.iteritems()]
143- stderr.write (' written %s ' % (json_file) + ' \n ' )
143+ print (' written %s ' % (json_file) + ' \n ' , file = sys.stderr )
144144 return 0
145145
146146def errorFreeReads (int min_family_member_count , float fraction_threshold , str json_record ):
@@ -165,16 +165,16 @@ def errorFreeReads(int min_family_member_count, float fraction_threshold, str js
165165 member_count = table.shape[0 ]
166166 if member_count >= min_family_member_count:
167167 sequence_left, quality_left, sequence_right, quality_right = concensusPairs(table, fraction_threshold)
168- left_record = ' %s _%i _readCluster\n %s \n +\n %s \n ' % (index, member_count, sequence_left, quality_left)
169- right_record = ' %s _%i _readCluster\n %s \n +\n %s \n ' % (index, member_count, sequence_right, quality_right)
168+ left_record = ' %s _%i _readCluster\n %s \n +\n %s ' % (index, member_count, sequence_left, quality_left)
169+ right_record = ' %s _%i _readCluster\n %s \n +\n %s ' % (index, member_count, sequence_right, quality_right)
170170 return left_record, right_record
171171 else :
172172 return ' No'
173173
174174def writeSeqToFiles (read1 , read2 , output_cluster_count , result ):
175175 if result!= ' No' :
176- read1.write (' @cluster%i _%s ' % (output_cluster_count, result[0 ]))
177- read2.write (' @cluster%i _%s ' % (output_cluster_count, result[1 ]))
176+ print (' @cluster%i _%s ' % (output_cluster_count, result[0 ]), file = read1 )
177+ print (' @cluster%i _%s ' % (output_cluster_count, result[1 ]), file = read2 )
178178 return 1
179179 else :
180180 return 0
@@ -199,7 +199,7 @@ def writingAndClusteringReads(outputprefix, min_family_member_count, json_file,
199199 output_cluster_count += write_func(output_cluster_count, result)
200200 counter += 1
201201 if counter % 1000000 == 0 :
202- stderr.write (' Processed %i read clusters.\n ' % (counter))
202+ print (' Processed %i read clusters.' % (counter), file = sys.stderr )
203203 pool.close()
204204 pool.join()
205205 return output_cluster_count, read1File, read2File
@@ -317,7 +317,7 @@ def recordsToDict(str outputprefix, str inFastq1, str inFastq2, int idx_base, in
317317 for read_num, (read1,read2) in iterator:
318318 discarded_sequence_count += cluster_reads(read1, read2)
319319 if read_num % 10000000 == 0 :
320- stderr.write (' [%s ] Parsed: %i sequence\n ' % (programname,read_num))
320+ print (' [%s ] Parsed: %i sequence' % (programname,read_num), file = sys.stderr )
321321
322322 barcode_count = len (barcode_dict.keys())
323323 return barcode_dict, read_num, barcode_count, discarded_sequence_count
0 commit comments