Forum: Script to convert jspecies file to mega
0
gravatar for jaomazava87
4.7 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()

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

 

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

Help
Access

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