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 ):
#queryConsensus = [ qc for i,qc in enumerate(hhm.consensus) ] # if hhm.conserved[i] ]
#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
with open( "{}/{}.fas".format( args.fasDir, queryName ), 'r' ) as fas:
fas_str = ""
for rec in SeqIO.parse(fas,'fasta'):
seq = ''.join([ c for i,c in enumerate(rec.seq) if hhm.conserved[i] ])
fas_str += ">{}\n{}\n".format(rec.id,seq)
loptions = weblogo.LogoOptions(
logo_title="{} ({})".format(hhmNameDict[queryName],queryName),
unit_name="bits",
yaxis_label="",
#show_yaxis=False,
color_scheme=weblogo.std_color_schemes["chemistry"],
annotate=[ i+1 for i,b in enumerate(hhm.conserved) if b ],
rotate_numbers=True,
stack_aspect_ratio=3,
stack_width=weblogo.std_sizes["large"],
stacks_per_line=hhm.conserved.count_bits(),
show_fineprint=False )
ldata = weblogo.LogoData.from_seqs( weblogo.read_seq_data(io.StringIO(fas_str)) )
lformat = weblogo.LogoFormat(ldata,loptions)
with open( os.path.join(args.outDir, "{}.conserved.pdf".format(hhmNameDict[queryName])), 'wb' ) as ofh:
ofh.write( weblogo.pdf_formatter(ldata,lformat) )
if hhm.conserved.count_bits() > 0:
with open( "{}/{}.fas".format( args.fasDir, queryName ), 'r' ) as fas:
fas_str = ""
for rec in SeqIO.parse(fas,'fasta'):
seq = ''.join([ c for i,c in enumerate(rec.seq) if hhm.conserved[i] ])
fas_str += ">{}\n{}\n".format(rec.id,seq)
loptions = weblogo.LogoOptions(
logo_title="{} ({})".format(hhmNameDict[queryName],queryName),
unit_name="bits",
yaxis_label="",
#show_yaxis=False,
color_scheme=weblogo.std_color_schemes["chemistry"],
annotate=[ i+1 for i,b in enumerate(hhm.conserved) if b ],
rotate_numbers=True,
stack_aspect_ratio=3,
stack_width=weblogo.std_sizes["large"],
stacks_per_line=hhm.conserved.count_bits(),
show_fineprint=False )
ldata = weblogo.LogoData.from_seqs( weblogo.read_seq_data(io.StringIO(fas_str)) )
lformat = weblogo.LogoFormat(ldata,loptions)
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:
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