def make_backbone_blast_db(project_dir, blast_db_seq, dbtype): 'It formats a blastdb when need it' logger = logging.getLogger(LOGGER_NAME) #the name should be the basename of the blast_db_seq db_dir = join(project_dir, BACKBONE_DIRECTORIES['blast_databases']) if not exists(db_dir): makedirs(db_dir) db_seq_fpath = join(db_dir, _get_basename(blast_db_seq)) if not exists(db_seq_fpath): #which is the name of the new databae? blast_db_seq_format = guess_seq_file_format(open(blast_db_seq)) if blast_db_seq_format == 'fasta': rel_symlink(blast_db_seq, db_seq_fpath) else: seqio(in_seq_fhand=open(blast_db_seq), out_seq_fhand=open(db_seq_fpath, 'w'), out_format='fasta') logger.info('Formatting the database %s' % db_seq_fpath) try: makeblastdb_plus(db_seq_fpath, dbtype=dbtype) except RuntimeError: msg = 'Error making blastdb. db:%s\n dbtype:%s\n' % \ (db_seq_fpath, dbtype) remove(db_seq_fpath) raise RuntimeError(msg) return db_seq_fpath
def _select_last_analysis(self): '''It select the last analysis from a directory with timestamped results''' self._log({'analysis_started':True}) dirs = self._get_timestamped_output_dirs() latest_dir = dirs[-1] output_dir = self._get_output_dirs()['result'] if os.path.exists(output_dir): os.remove(output_dir) rel_symlink(latest_dir, output_dir)
def run(self): '''It runs the analysis.''' contigs_path = self._get_input_fpaths()['contigs'] contigs_ext = contigs_path.extension reference_dir = self._create_output_dirs()['result'] reference_fpath = os.path.join(reference_dir, BACKBONE_BASENAMES['mapping_reference'] + '.' + \ contigs_ext) if os.path.exists(reference_fpath): os.remove(reference_fpath) rel_symlink(contigs_path.last_version, reference_fpath)
def run(self): '''It runs the analysis. It checks if the analysis is already done per input file''' self._log({'analysis_started':True}) proj_name = self._get_project_name() #we need an assembly dir for this run #in this case every assembly is done in a new directory #the directory for this assembly output_dirs = self._create_output_dirs(timestamped=True) assembly_dir = output_dirs['analysis'] mira_dir = os.path.join(assembly_dir, '%s_assembly' % proj_name) original_dir = os.getcwd() #with technologies have we used? #each input file should have a link in the assembly dir techs = set() for path in self._get_input_fpaths()['reads']: fpath = path.last_version fname = os.path.split(fpath)[-1] mira_input_fname = os.path.join(assembly_dir, fname) rel_symlink(fpath, mira_input_fname) if '454' in fname: techs.add('454') elif 'sanger' in fname: techs.add('sanger') settings = self._project_settings['Mira'] #job part of the command job = settings['job_options'] job.extend(techs) job = ','.join(job) job = '-job=' + job cmd = ['mira', '-project=%s' % proj_name, '-fasta', job] if 'general_settings' in settings: general_settings = settings['general_settings'] cmd.extend(general_settings) cmd.append('-OUT:rld=yes') for tech in techs: tech_str = '%s_settings' % tech if tech_str in settings: cmd.append(tech_str.upper()) cmd.extend(settings[tech_str]) logger = logging.getLogger("franklin") logger.info('The input files for Mira has been created') logger.info('To run Mira go to the directory: %s' % assembly_dir) logger.info('and run the command: %s' % ' '.join(cmd)) self._log({'analysis_finished':True})
def _prepare_mapper_index(self, mapping_index_dir, reference_path, platform, mapper): 'It creates reference_fpath depending on the mapper and the platform' kind = 'color' if platform == 'solid' else 'sequence' color_space = True if kind == 'color' else False mapping_index_dir = mapping_index_dir[0].original_path index_dir = mapping_index_dir % (mapper, kind) if not os.path.exists(index_dir): os.mkdir(index_dir) reference_fpath = reference_path.last_version reference_fname = os.path.basename(reference_fpath) index_fpath = os.path.join(index_dir, reference_fname) if not os.path.exists(index_fpath): rel_symlink(reference_fpath, index_fpath) return index_fpath, color_space
def test_rel_symlink(self): 'It tests various cases of rel symlinks' tempdir = NamedTemporaryDir() hola = os.path.join(tempdir.name, 'hola') os.mkdir (hola) caracola = os.path.join(tempdir.name, 'caracola') rel_symlink(hola ,caracola) assert os.path.exists(caracola) fname = os.path.join(hola, 'fname') open(fname, 'w') caracola2 = os.path.join(tempdir.name, 'caracola2') rel_symlink(fname ,caracola2) assert os.path.exists(caracola2) path2 = os.path.join(tempdir.name, 'dir1', 'dir2') os.makedirs(path2) caracola3 = os.path.join(path2, 'caracola3') rel_symlink(hola, caracola3) assert os.path.exists(caracola3)