error first time running bioscripts.convert package for python
2
0
Entering edit mode
10.0 years ago
mosquitoes • 0

I just installed bioscripts.convert-0.4 package for python. I get the following error when I run a simple sequence conversion:

python ~/bin/bioscripts.convert-0.4/bioscripts/convert/convbioseq.py phylip ~/Dropbox/new.fasta

Traceback (most recent call last):
  File "/Users/eflannery/bin/bioscripts.convert-0.4/bioscripts/convert/convbioseq.py", line 76, in <module>
    if (_DEV_MODE):
NameError: name '_DEV_MODE' is not defined

Any help would be greatly appreciated.

Thanks!

Edit

This is the original script it calls. It looks like it does not define (_DEV_MODE): ?

I have not modified anything, this is what it looked like from installing. I don't know a lot of python though, so I'm not sure how to fix it.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Convert biosequences from one format to another.

"""
# TODO: all the format crap should be in one table

__docformat__ = 'restructuredtext en'
__author__ = 'Paul-Michael Agapow <agapow@bbsrc.ac.uk>'


### IMPORTS ###

from exceptions import BaseException

from Bio import SeqIO, AlignIO

from defs import *
import common

try:
    from bioscripts.convert import __version__
except:
    __version__ = 'unknown'


### CONSTANTS & DEFINES ###

### IMPLEMENTATION ###

def main():
    out_fmt, infiles, opts = common.parse_args('biosequence')

    for in_path in infiles:
        dir, base, ext = common.dir_base_ext (in_path)
        in_fmt = (opts.input_format or EXT_TO_FORMAT.get (ext, '')).lower()
        assert (in_fmt), "no known input format specified"

        # calculate output format and name
        out_path = common.make_out_path (dir, base,
            opts.output_extension or FORMAT_TO_EXT[out_fmt])

        # open & read infile
        in_hndl = open (in_path, 'rb')
        in_seqs = [x for x in SeqIO.parse (in_hndl, in_fmt)]
        in_hndl.close()
        assert (in_seqs), \
            '''No sequences read from %s. Perhaps the file is not in %s format.''' % (file_name, in_fmt)

        # write out
        out_hndl = open (out_path, 'wb')
        if opts.seqtype:
            for s in in_seqs:
                s.alphabet = opts.seqtype
        if out_fmt in ['nexus']:
            # need to hack to handle this crap
            from Bio.Align import MultipleSeqAlignment
            aln = MultipleSeqAlignment(in_seqs,
                alphabet=opts.seqtype or BIOSEQ_ALPHABET_PROTEIN)
            AlignIO.write (aln, out_hndl, out_fmt)
        else:
            SeqIO.write (in_seqs, out_hndl, out_fmt)
        out_hndl.close()



### TEST & DEBUG ###

### MAIN ###

if __name__ == '__main__':
    try:
        main()
    except BaseException, err:
        if (_DEV_MODE):
            raise
        else:
            print err
    except:
        print "An unknown error occurred.\n"

### END ######################################################################
sequencing software-error • 2.9k views
ADD COMMENT
2
Entering edit mode
10.0 years ago
SES 8.6k

I think the errors are about environment variables that must be defined. It looks like there is some logic to use them if they are defined, or not use them, but it doesn't seem to be working. Also, I'm not sure there is an SeqIO.PhylipIO but there is an AlignIO.PhylipIO, so the script might not work anyway. If you just want to convert you sequences, then this BioPerl one-liner will work:

perl \
  -MBio::AlignIO \
  -e '
      $fh = Bio::AlignIO->new(-fh => \*STDIN, -format => 'fasta');
      $out = Bio::AlignIO->new(-fh => \*STDOUT, -format => 'phylip', -interleave => 1);
      while ($aln = $fh->next_aln) {
        $out->write_aln($aln);
      }' < seqs.fasta

It should be clear that this reads from stdin and writes to stdout, so change the file names to whatever is appropriate (and redirect the output to a file by putting > seqs.phy after the command). You could put this in a script if you wanted but I never do for stuff like this. It saves so much time to use Perl/BioPerl's command line capabilities.

If I misunderstood and you are wanting to go the other way (phylip -> fasta), just switch the code inside of the new() constructors and then you have a phylip to fasta converter.

ADD COMMENT
0
Entering edit mode

Thank-you!!!

ADD REPLY
0
Entering edit mode

No problem! You can say thanks on the site by voting and/or accepting the answer. :)

ADD REPLY
0
Entering edit mode
10.0 years ago

I have not used bioscripts.convert, but I did write a tool to convert phylip to fasta. It's part of BBTools and requires Java to be installed.

phylip2fasta.sh in=x.phylip out=x.fasta

Note that I've only used it on interleaved phylip files; I'm not sure how it would behave on non-interleaved.

ADD COMMENT

Login before adding your answer.

Traffic: 1965 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6