Need help with understanding a python error

This is the place for queries that don't fit in any of the other categories.

Need help with understanding a python error

Postby eyeziko » Wed Jun 11, 2014 10:05 pm

Mekire: OP referenced this post (I moved to its own topic).

Dear All,
I know I am starting a new post here but it falls under name error and i really would love some input. i am just using this tool for genome assembly and I am getting this name error.
I am having a problem with the code CISA.py, shown below and I am not sure what to do. It seem that CISA.py is not finding the CISA_S hence it is giving me a name error but there is no file like that been created. Here is the error I am getting:

when I run it with python 2.6
Code: Select all
Traceback (most recent call last):
  File "./CISA.py", line 31, in <module>
    sys.path.append(CISA+'/CISA1')

When I run it with Python 3, I get this error:
Code: Select all
:~/CISA1.3$ python3 ./cisfile.py cisarun.txt
  File "./cisfile.py", line 5
    print 'Please give a file!'
                              ^
SyntaxError: invalid syntax

CISA.py
HERE IS THE CODE
Code: Select all
#! /usr/bin/python
import sys
import os
if len(sys.argv) != 2:
    print 'Please give a file!'                      #This is the line with the problem when running python 3
myfile = sys.argv[1]
f = open(myfile)
nucmer = 'nucmer'
makeblastdb = 'makeblastdb'
blastn = 'blastn'
r2_gap = '0.95'
outfile = 'CISA_Out.fa'
for i in f:
    if 'genome = ' in i:
        g_l = i.split('=')[1].replace('\n', '')
    if 'infile = ' in i:
        infile = i.split('=')[1].replace('\n', '')
    if 'outfile = ' in i:
        outfile = i.split('=')[1].replace('\n', '')
    if 'nucmer = ' in i:
        nucmer = i.split('=')[1].replace('\n', '')
    if 'makeblastdb = ' in i:
        makeblastdb = i.split('=')[1].replace('\n', '')
    if 'blastn = ' in i:
        blastn = i.split('=')[1].replace('\n', '')
    if 'R2_Gap = ' in i:
        r2_gap = i.split('=')[1].replace('\n', '')
    if 'CISA = ' in i:
        CISA_S = i.split('=')[1].replace('\n', '') + '/src'
current_p = os.getcwd()
sys.path.append(CISA_S + '/CISA1')             #This is the line with the problem when running python 2.6
from Controllor_R1 import R1
if not os.path.exists('CISA1'):
    os.makedirs('CISA1')
my_work = R1()
my_work.Start(g_l, infile, nucmer, CISA_S, current_p)
sys.path.append(CISA_S + '/CISA2')
if not os.path.exists('CISA2'):
    os.makedirs('CISA2')
from Controllor_R2 import R2
my_work = R2()
my_work.Start(nucmer, r2_gap, CISA_S, current_p)
sys.path.append(CISA_S + '/CISA3')
if not os.path.exists('CISA3'):
    os.makedirs('CISA3')
from Controllor_R3 import R3
my_work = R3()
my_work.Start(CISA_S, current_p, makeblastdb, blastn)
f = open('info1')
for data in f:
    if 'Round3_result = ' in data:
        R4_start = data.split('=')[1].replace('\n', '')
    if 'Repeat_region = ' in data:
        thr = data.split('=')[1].replace('\n', '')
f.close()
final = R4_start
if int(thr) > 0:
    sys.path.append(CISA_S + '/CISA4')
    if not os.path.exists('CISA4'):
        os.makedirs('CISA4')
from Controllor_R4 import R4
    my_work = R4()
    my_work.Start(thr, R4_start, CISA_S, current_p, makeblastdb, blastn)
    f = open('info2')
    for data in f:
        if 'Round4_result = ' in data:
            R4_end = data.split('=')[1].replace('\n', '')
    f.close()
    if R4_end:
        final = R4_end
os.rename('Contigs_' + final + '.fa', outfile)
final = int(final)
for i in range(1, final):
    if os.path.exists('Contigs_' + str(i) + '.fa'):
        os.remove('Contigs_' + str(i) + '.fa')
Last edited by Mekire on Thu Jun 12, 2014 6:23 am, edited 1 time in total.
Reason: First post lock. Code tags added. Post moved. Etc.
eyeziko
 
Posts: 1
Joined: Wed Jun 11, 2014 9:53 pm

Re: Need help with understanding a python error

Postby stranac » Thu Jun 12, 2014 9:05 am

For python 2.6, that is not the entire traceback.
For python 3, print() is a function, so the syntax is incorrect. The script was obviously written for python 2.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1245
Joined: Thu Feb 07, 2013 3:42 pm


Return to General Coding Help

Who is online

Users browsing this forum: No registered users and 3 guests