problems to makeblastdb, the fa file is not being recognised.
2
0
Entering edit mode
7.5 years ago
bio90029 ▴ 10

I have the above code to make a data base from different folder, and I am getting always the same error, 'contigs.fa' no recognized. I post my code, and hopefully someone can help me to find the error.

import glob, sys, os, subprocess
from Bio.Blast import NCBIXML
from Bio import SeqIO

def database_project():

    #folders where my data are store
    #looking for the files within the folder H*
    files = glob.glob('/home/my_name/velvet_results2/H*')
    for file in files:

        #looking for contigs.fa in each folder
        contigs=glob.glob(file + '/*.fa')
        print contigs


        #extract name of folder
        temporary_db = os.path.basename(file) 

        output= '/home/mu_name/velvet_results2/' + temporary_db +'_db'
        if os.path.exists(output):
            print 'This folder already exist'
        else:
            os.makedirs(output)


        cmd=['makeblastdb', '-in', 'contigs.fa', '-dbtype', 'nucl', '-out', 'temporary_db','-title', 'temporary_db']
        my_file=subprocess.Popen(cmd)
        my_file.wait()
        #return database_id
        print 'The database is done'
database_project()
blast • 1.5k views
ADD COMMENT
1
Entering edit mode
7.5 years ago
bio90029 ▴ 10

Thanks guys, I found the problem, glob.glob gives a list, in this case with one element. In the previous script, I was not telling which element to take. So I changed contgs.fa by contigs[0], and it worked perfectly.

cmd=['makeblastdb', '-in', contigs[0], '-dbtype', 'nucl', '-out', file + '/temporary_db','-title', 'temporary_db']
ADD COMMENT
0
Entering edit mode

Glad you figured it out, and learned something. I think your script can be condensed, and improved, but if it works, you're moving yourself forward with your skills.

ADD REPLY
1
Entering edit mode
7.5 years ago
st.ph.n ★ 2.7k
import glob, sys, os, subprocess
from Bio.Blast import NCBIXML
from Bio import SeqIO

def database_project():
    os.chdir('/home/my_name/velvet_results2')
    dirs = os.walk(os.getcwd())
    for d in dirs:
         os.chdir(d)
         for file in glob.glob('*.fa')
             temp_db = d.split('/')[-1] + '_db'

             try: 
                  os.mkdirs(temp_db)
             except OSError:
                  print 'The folder already exists.'

             os.chdir(temp_db)
             subprocess.call('makeblasdb -in contigs.fa -dbtype nucl', shell=True)

database_project()
ADD COMMENT
1
Entering edit mode

looks like you need a closing bracket in the line dirs = os.walk(os.getcwd()

ADD REPLY

Login before adding your answer.

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