예제 #1
0
    def annotations(self, pdb, remove=True):
        """Call matlab and parse the annotations to create a list of unit id to
        loop mappings.

        :param str pdb: The pdb id to use.
        :param Bool remove: Flag to indicate if the produced file should be
        removed.
        :returns: The annotations produced by matlab.
        """

        mlab = matlab.Matlab(self.config['locations']['fr3d_root'])
        path = str(os.path.join(self.precomputed, pdb))
        try:
            if not os.path.exists(path):
                os.mkdir(path)
        except:
            raise core.InvalidState("Could not create %s for matlab" % path)

        [output_file, err_msg] = mlab.loadLoopPositions(path, nout=2)
        if err_msg != '':
            raise matlab.MatlabFailed(err_msg)

        data = self.parse(output_file)
        if remove:
            os.remove(output_file)
        return data
예제 #2
0
    def __call__(self, loop_type, loops, release_id):
        """Launch the main matlab motif clustering pipeline. This will cluster
        motifs of the given type for the given pdb files. This will get all
        valid loops from the best chains and models and then run a series of
        parallel matlab jobs to cluster them.

        :loop_type: The type of loops to cluster.
        :pdbs: The pdb files to get loops from.
        :returns: Nothing.
        """

        if not loops:
            raise ValueError("Must give loops to cluster")

        self._clean_up()

        output_dir = self.make_release_directory(loop_type, release_id)
        self.make_input_file_for_matlab(loops, output_dir)
        self.parallel_exec_commands(self.prepare_aAa_commands(loops))

        self.logger.info('Starting Matlab to run MotifAtlasPipeline.m')

        mlab = matlab.Matlab(self.config['locations']['fr3d_root'])
        [status, err_msg] = \
            mlab.MotifAtlasPipeline(output_dir, nout=2)

        if err_msg:
            raise matlab.MatlabFailed(err_msg)

        self._clean_up()
        self.logger.info('Successful clustering of %s' % loop_type)

        return output_dir
예제 #3
0
    def data(self, pdb, **kwargs):
        # 'A,B,C', '1,2', ''
        mlab = matlab.Matlab(self.config['locations']['fr3d_root'])
        chains, models, err = mlab.loadBestChainsAndModels(pdb, nout=3)

        if err != '':
            raise matlab.MatlabFailed(err)

        return {'pdb_id': pdb, 'best_chains': chains, 'best_models': models}
예제 #4
0
    def data(self, pdb, **kwargs):
        mlab = matlab.Matlab(self.config['locations']['fr3d_root'])
        ifn, err_msg = mlab.loadRedundantNucleotides(pdb, nout=2)
        if err_msg != '':
            raise matlab.MatlabFailed(err_msg)

        with open(ifn, 'rb') as raw:
            data = self._parse(raw, pdb)
        os.remove(ifn)
        return data
예제 #5
0
    def data(self, pdb, **kwargs):
        """Compute the interaction annotations for a pdb file.

        :pdb: The pdb id to process.
        :kwargs: Keyword arguments.
        :returns: The interaction annotations.
        """
        mlab = matlab.Matlab(str(self.config['locations']['fr3d_root']))

        self.logger.info('Running matlab on %s', pdb)
        ifn, status, err_msg = mlab.loadInteractions(pdb, nout=3)
        status = status[0][0]
        if status == 0:
            data = self.parse(ifn, pdb)
            os.remove(ifn)
            return data
        elif status == 2:
            raise core.Skip('Pdb file %s has no nucleotides' % pdb)
        raise core.InvalidState(
            'Matlab error code %i when analyzing %s' % status, pdb)
예제 #6
0
    def __save__(self, loops, location):
        """Save the loops to a file.

        :loops: The loops matlab proxy object to save.
        :param str location: The location to saave to.
        """

        if not os.path.isdir(location):
            os.makedirs(location)

        try:
            mlab = matlab.Matlab(self.config['locations']['fr3d_root'])
            [status, err_msg] = mlab.aSaveLoops(loops, location, nout=2)
        except Exception as err:
            self.logger.exception(err)
            raise err

        if status != 0:
            self.logger.error(mlab.last_stdout)
            raise matlab.MatlabFailed("Could not save all loop mat files")

        self.logger.debug("Saved loop mat files")
    def data(self, pdb, **kwargs):
        """Compute the anti/syn annotations for a pdb file.

        :pdb: The pdb id to process.
        :kwargs: Keyword arguments.
        :returns: The interaction annotations.
        """
        mlab = matlab.Matlab(str(self.config['locations']['fr3d_root']))

        self.logger.info('Running matlab on %s', pdb)
        # Need to change the matlab script name
        ifn, status, err_msg = mlab.loadFlankings(pdb, nout=3)
        status = status[0][0]
        if status == 0:
            data = self.parse(ifn, pdb)
            os.remove(ifn)
            return data
        # I'm not sure whether we need to change any of these
        elif status == 2:
            raise core.Skip('PDB file %s has no nucleotides' % pdb)
        elif status == 3:
            raise core.Skip('PDB file %s has no flanking interactions' % pdb)
        raise core.InvalidState(
            'Matlab error code %i when analyzing %s' % status, pdb)
예제 #8
0
    def _extract_loops(self, pdb, loop_type, mapping, normalize):
        """Uses matlab to extract the loops for a given structure of a specific
        type. This will also save the loop files into the correct place.

        :param str pdb: PDB file to process
        :param str loop_type: The type of loop (IL, HL, J3, ...) to extract
        loops for.
        :param dict mapping: A mapping of unit ids to known loop names.
        :returns: The extracted loops.
        """
        try:
            mlab = matlab.Matlab(self.config['locations']['fr3d_root'])
            [loops, count, err_msg] = mlab.extractLoops(pdb, loop_type, nout=3)
        except Exception as err:
            self.logger.exception(err)
            raise err

        if err_msg != '':
            raise core.MatlabFailed(err_msg)

        if loops == 0:
            self.logger.warning('No %s in %s', loop_type, pdb)
            loop_id = self._get_fake_loop_id(pdb, loop_type)
            return [
                mod.LoopInfo(loop_id=loop_id,
                             type='NA',
                             pdb_id=pdb,
                             sequential_id='000',
                             length=0,
                             seq='',
                             r_seq='',
                             nwc_seq='',
                             r_nwc_seq='',
                             unit_ids='',
                             loop_name='')
            ]

        self.logger.info('Found %i %s loops', count, loop_type)

        data = []
        for index in xrange(count):
            loop = loops[index].AllLoops_table
            full_id = normalize(loop.full_id)
            loop_id = self._get_loop_id(full_id, pdb, loop_type, mapping)
            loops[index].Filename = loop_id

            data.append(
                mod.LoopInfo(loop_id=loop_id,
                             type=loop_type,
                             pdb_id=pdb,
                             sequential_id=loop_id.split("_")[-1],
                             length=int(loops[index].NumNT[0][0]),
                             seq=loop.seq,
                             r_seq=loop.r_seq,
                             nwc_seq=loop.nwc,
                             r_nwc_seq=loop.r_nwc,
                             unit_ids=','.join(full_id),
                             loop_name=loop.loop_name))

        if self.save_loops:
            self.__save__(loops, self.config['locations']['loops_mat_files'])

        return data
예제 #9
0
 def data(self, pdb, **kwargs):
     mlab = matlab.Matlab(self.config['locations']['fr3d_root'])
     mlab.zAddNTData(pdb)
     return None