Forum:Script to convert jspecies file to mega
0
0
Entering edit mode
8.8 years ago

Hi everybody,

I'm trying to convert an output of tetra alignment 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()

M=[]

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

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;'
else:
    description = ''

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

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

for I in M[1]:
    print('#', i, sep='')
print()
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]))
        else:
            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 "./jspecies2mega.py", 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.

Best,
Fety

python • 1.7k views
ADD COMMENT

Login before adding your answer.

Traffic: 2976 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