Commit 3fc1e4da by Riccardo Vicedomini

skip logo generation if there are no conserved positions only for the appropriate logo

parent cfb5aa85
...@@ -241,32 +241,29 @@ def main( argv = None ): ...@@ -241,32 +241,29 @@ def main( argv = None ):
#queryConsensus = [ qc for i,qc in enumerate(hhm.consensus) ] # if hhm.conserved[i] ] #queryConsensus = [ qc for i,qc in enumerate(hhm.consensus) ] # if hhm.conserved[i] ]
#queryCovered = BitVector(size=len(hhm.master_seq)) #queryCovered = BitVector(size=len(hhm.master_seq))
# skip if no conserved positions
if hhm.conserved.count_bits() <= 0:
continue
# output sequence logo restricted to conserved positions # output sequence logo restricted to conserved positions
with open( "{}/{}.fas".format( args.fasDir, queryName ), 'r' ) as fas: if hhm.conserved.count_bits() > 0:
fas_str = "" with open( "{}/{}.fas".format( args.fasDir, queryName ), 'r' ) as fas:
for rec in SeqIO.parse(fas,'fasta'): fas_str = ""
seq = ''.join([ c for i,c in enumerate(rec.seq) if hhm.conserved[i] ]) for rec in SeqIO.parse(fas,'fasta'):
fas_str += ">{}\n{}\n".format(rec.id,seq) seq = ''.join([ c for i,c in enumerate(rec.seq) if hhm.conserved[i] ])
loptions = weblogo.LogoOptions( fas_str += ">{}\n{}\n".format(rec.id,seq)
logo_title="{} ({})".format(hhmNameDict[queryName],queryName), loptions = weblogo.LogoOptions(
unit_name="bits", logo_title="{} ({})".format(hhmNameDict[queryName],queryName),
yaxis_label="", unit_name="bits",
#show_yaxis=False, yaxis_label="",
color_scheme=weblogo.std_color_schemes["chemistry"], #show_yaxis=False,
annotate=[ i+1 for i,b in enumerate(hhm.conserved) if b ], color_scheme=weblogo.std_color_schemes["chemistry"],
rotate_numbers=True, annotate=[ i+1 for i,b in enumerate(hhm.conserved) if b ],
stack_aspect_ratio=3, rotate_numbers=True,
stack_width=weblogo.std_sizes["large"], stack_aspect_ratio=3,
stacks_per_line=hhm.conserved.count_bits(), stack_width=weblogo.std_sizes["large"],
show_fineprint=False ) stacks_per_line=hhm.conserved.count_bits(),
ldata = weblogo.LogoData.from_seqs( weblogo.read_seq_data(io.StringIO(fas_str)) ) show_fineprint=False )
lformat = weblogo.LogoFormat(ldata,loptions) ldata = weblogo.LogoData.from_seqs( weblogo.read_seq_data(io.StringIO(fas_str)) )
with open( os.path.join(args.outDir, "{}.conserved.pdf".format(hhmNameDict[queryName])), 'wb' ) as ofh: lformat = weblogo.LogoFormat(ldata,loptions)
ofh.write( weblogo.pdf_formatter(ldata,lformat) ) with open( os.path.join(args.outDir, "{}.conserved.pdf".format(hhmNameDict[queryName])), 'wb' ) as ofh:
ofh.write( weblogo.pdf_formatter(ldata,lformat) )
with open( "{}/{}.fas".format( args.fasDir, queryName ), 'r' ) as fas: with open( "{}/{}.fas".format( args.fasDir, queryName ), 'r' ) as fas:
loptions = weblogo.LogoOptions( loptions = weblogo.LogoOptions(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment