view commons/launcher/launchMafft.py @ 18:94ab73e8a190

Uploaded
author m-zytnicki
date Mon, 29 Apr 2013 03:20:15 -0400
parents
children
line wrap: on
line source

#!/usr/bin/env python

# DEPRECATED

import user, os, sys, getopt, exceptions

if not os.environ.has_key( "REPET_PATH" ):
    print "*** Error: no environment variable REPET_PATH"
    sys.exit(1)
sys.path.append( os.environ["REPET_PATH"] )

import pyRepet.launcher.programLauncher
import pyRepet.seq.fastaDB
from pyRepet.seq.BioseqDB import *

#------------------------------------------------------------------------------

def help():

    print
    print "DEPRECATED"
    print
    print "usage: ",sys.argv[0],"[ options ]"
    print "options:"
    print "     -h: this help"
    print "     -i: name of the input file (format='fasta')"
    print "     -o: name of the output file (default=inFileName+'.fa_aln')"
    print "     -v: verbose (default=0/1)"
    print

#------------------------------------------------------------------------------

def main():
    
    """
    This program launches MAFFT to build a multiple sequence alignment.
    """

    inFileName = ""
    outFileName = ""
    verbose = 0
    
    try:
        opts,args=getopt.getopt(sys.argv[1:],"hi:o:v:")
    except getopt.GetoptError:
        help()
        sys.exit(1)
    for o,a in opts:
        if o == "-h":
            help()
            sys.exit(0)
        elif o == "-i":
            inFileName = a
        elif o == "-o":
            outFileName = a
        elif o == "-v":
            verbose = int(a)
            
    if inFileName == "":
        print "*** Error: missing compulsory options"
        help()
        sys.exit(1)
        
    if verbose > 0:
        print "beginning of %s" % (sys.argv[0].split("/")[-1])
        sys.stdout.flush()
        
    if verbose > 0:
        print "build a multiple alignment from '%s'..." % ( inFileName )
        sys.stdout.flush()
        
    pyRepet.seq.fastaDB.shortenSeqHeaders( inFileName )
    
    bsDB = BioseqDB( inFileName+".shortH" )
    bsDB.upCase()
    bsDB.save( inFileName+".shortHtmp" )
    del bsDB
    os.rename( inFileName+".shortHtmp", inFileName+".shortH" )
    
    pL = pyRepet.launcher.programLauncher.programLauncher( inFileName+".shortH" )
    pL.launchMafft( outFileName=inFileName+".shortH.fa_aln", verbose=verbose )
    
    pyRepet.seq.fastaDB.retrieveInitSeqHeaders( inFileName+".shortH.fa_aln",
                                                inFileName+".shortHlink",
                                                inFileName+".shortH.fa_aln.initH",
                                                verbose-1 )
    
    if outFileName == "":
        outFileName = "%s.fa_aln" % ( inFileName )
    os.system( "mv %s.shortH.fa_aln.initH %s" % ( inFileName, outFileName ) )
    
    for f in [inFileName+".shortH",inFileName+".shortH.fa_aln",inFileName+".shortHlink"]:
        os.remove( f )
        
    if verbose > 0:
        print "%s finished successfully" % (sys.argv[0].split("/")[-1])
        sys.stdout.flush()
        
    return 0

#------------------------------------------------------------------------------

if __name__ == '__main__':
    main()