Forum: Script to convert jspecies file to mega
gravatar for jaomazava87
5.4 years ago by
European Union
jaomazava870 wrote:

Hi everybody,

I'm trying to convert an output of tetra alignement of jspecies to mega format, I got this script:

#!/usr/bin/env python2.7.6
import argparse

parser = argparse.ArgumentParser(description='Process the JSpecies output file to MEGA.')
parser.add_argument(dest='JSfile', metavar='', help='JSpecies file', type=str)
args = parser.parse_args()


with open(args.JSfile, 'r') as JSinput:
    for line in JSinput:
        line = line.split()

analyseType = str(M[0][0])
title = '!Title '+analyseType+' results from '+args.JSfile+';'

if analyseType == 'ANIm':
    description = '!Description ANIm is the Average Nucleotide Identity using MUMmer algorithm calculated by the JSpecies software;'
elif analyseType == 'ANIb':
    description = '!Description ANIb is the Average Nucleotide Identity using BLAST algorithm calculated by the JSpecies software;'
elif analyseType == 'Tetra':
    description = '!Description Tetra is the Tetranucleotide Signature Frequency Correlation Coefficient calculated by the JSpecies software;'
    description = ''

format = '!Format DataType=Distance DataFormat=LowerLeft NTaxa='+str(len(M[1]))+';'

print('#mega', title, description, format, sep='\n')

for i in M[1]:
    print('#', i, sep='')
for i in M[3:]:
    stop = i.index('---')
    for j in range(len(i[:stop-1])):
        if analyseType != 'Tetra':
            i[j+1] = i[j+1].replace('NaN','50')
            i[j+1] = '{0:f}'.format(100-float(i[j+1]))
            i[j+1] = i[j+1].replace('NaN','50')
            i[j+1] = '{0:f}'.format(1-float(i[j+1]))
    print(' '.join(i[1:stop]))

But when I try too use this I get:

File "./", line 30

    print('mega', title, description, format, sep='\n')


SyntaxError: invalid syntax


It's the first time that I work on script without tutorial in Linux, if anyone can provide an answer why I get this syntax error that would be greatly appreciated.




forum python • 1.3k views
ADD COMMENTlink written 5.4 years ago by jaomazava870
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1115 users visited in the last hour