예제 #1
0
파일: dssp.py 프로젝트: Kortemme-Lab/klab
    def compute(self):
        tmp_dir = self.tmp_dir
        if not self.read_only:
            pdb_object = self.pdb.clone()
        else:
            pdb_object = self.pdb  # in general, we should not be modifying the structure in this class
        input_filepath = write_temp_file(tmp_dir, pdb_object.get_content(), ftype = 'w', prefix = 'dssp_')
        output_filepath = write_temp_file(tmp_dir, '', ftype = 'w', prefix = 'dssp_')
        try:
            p = _Popen('.', shlex.split('mkdssp -i {input_filepath} -o {output_filepath}'.format(**locals())))
            if p.errorcode:
                if p.stderr.find('empty protein, or no valid complete residues') != -1:
                    raise MissingAtomException(p.stdout)
                else:
                    raise Exception('An error occurred while calling DSSP:\n%s' % p.stderr)

            self.dssp_output = read_file(output_filepath)
            self.dssp = self.parse_output()
        except MissingAtomException as e:
            os.remove(input_filepath)
            os.remove(output_filepath)
            raise
        except Exception as e:
            os.remove(input_filepath)
            os.remove(output_filepath)
            raise colortext.Exception('%s\n%s' % (str(e), traceback.format_exc()))
        os.remove(input_filepath)
        os.remove(output_filepath)
예제 #2
0
파일: dssp.py 프로젝트: Kortemme-Lab/klab
 def compute(self, chain_id):
     tmp_dir = self.tmp_dir
     pdb_object = self.pdb.clone()  # we are immediately modifying the PDB file by stripping chains so we need to make a copy
     pdb_object.strip_to_chains(chain_id)
     input_filepath = write_temp_file(tmp_dir, pdb_object.get_content(), ftype = 'w', prefix = 'dssp_')
     output_filepath = write_temp_file(tmp_dir, '', ftype = 'w', prefix = 'dssp_')
     try:
         p = _Popen('.', shlex.split('mkdssp -i {input_filepath} -o {output_filepath}'.format(**locals())))
         if p.errorcode:
             if p.stderr.find('empty protein, or no valid complete residues') != -1:
                 raise MissingAtomException(p.stdout)
             else:
                 raise Exception('An error occurred while calling DSSP:\n%s' % p.stderr)
         self.dssp_output[chain_id] = read_file(output_filepath)
         self.dssp[chain_id] = self.parse_output(chain_id)
     except MissingAtomException as e:
         os.remove(input_filepath)
         os.remove(output_filepath)
         raise
     except Exception as e:
         os.remove(input_filepath)
         os.remove(output_filepath)
         raise colortext.Exception('%s\n%s' % (str(e), traceback.format_exc()))
     os.remove(input_filepath)
     os.remove(output_filepath)
예제 #3
0
파일: rtools.py 프로젝트: Kortemme-Lab/klab
    def _runRScript(r_script_filename, cwd = '.', remove_output = True):
        # Reset to new current working directory
        tmp_dir = False
        if cwd == None:
            tmp_dir = True
            cwd = tempfile.mkdtemp( prefix = '%s-%s-%s_' % (time.strftime("%y%m%d"), getpass.getuser(), 'plot-working-dir') )

        rscriptname = write_temp_file(cwd, r_script_filename)
        p = subprocess.Popen(["R", "CMD", "BATCH", rscriptname], cwd = cwd)
        while True:
            time.sleep(0.3)
            errcode = p.poll()
            if errcode != None:
                break
        rout = "%s.Rout" % rscriptname
        os.remove(rscriptname)

        rout_contents = None
        if os.path.exists(rout):
            rout_contents = read_file(rout)
            os.remove(rout)

        if errcode != 0:
            print(rout_contents )
            raise Exception("The R script failed with error code %d." % errcode)

        if tmp_dir and remove_output:
            shutil.rmtree(cwd)

        return rout_contents
예제 #4
0
def get_pdb_contents_to_pose_residue_map(pdb_file_contents, rosetta_scripts_path, rosetta_database_path = None, pdb_id = None, extra_flags = ''):
    '''Takes a string containing a PDB file, the RosettaScripts executable, and the Rosetta database and then uses the features database to map PDB residue IDs to pose residue IDs.
       On success, (True, the residue mapping) is returned. On failure, (False, a list of errors) is returned.

       Note: extra_flags should typically include '-ignore_zero_occupancy false' and '-ignore_unrecognized_res'.'''

    filename = write_temp_file("/tmp", pdb_file_contents)
    success, mapping = get_pdb_to_pose_residue_map(filename, rosetta_scripts_path, rosetta_database_path = rosetta_database_path, pdb_id = pdb_id, extra_flags = extra_flags)
    os.remove(filename)
    return success, mapping
예제 #5
0
파일: plot.py 프로젝트: Kortemme-Lab/klab
def create_csv(analysis_table):
    contents = '\n'.join(['DatasetID,Experimental,Predicted'] + ['%s,%s,%s' % (str(l['DatasetID']), str(l['Experimental']), str(l['Predicted'])) for l in analysis_table])
    return write_temp_file('.', contents)
예제 #6
0
     errors.append('No input files were specified.')
 else:
     for batch_file_selector in args:
         if '*' in batch_file_selector or '?' in batch_file_selector:
             batch_files += map(os.path.abspath, glob.glob(batch_file_selector))
         elif os.path.isdir(batch_file_selector):
             for input_file_wildcard in input_file_wildcards:
                 batch_files += map(os.path.abspath, glob.glob(os.path.join(batch_file_selector, input_file_wildcard)))
         elif not os.path.exists(batch_file_selector):
             if len(batch_file_selector) == 4 and batch_file_selector.isalnum():
                 batch_file_selector = batch_file_selector.lower() # the files are named in lowercase on the cluster
                 if not os.path.exists('/netapp/database'):
                     # This script is not being run on the cluster - try to retrieve the file from the RCSB
                     colortext.message('No file %s exists - assuming that this is a PDB ID and trying to retrieve the associated file from the RCSB.' % batch_file_selector)
                     try:
                         fname = write_temp_file('/tmp', retrieve_pdb(batch_file_selector), suffix = '.pdb', prefix = batch_file_selector)
                         batch_files.append(os.path.abspath(fname))
                         temp_files.append(os.path.abspath(fname))
                     except:
                         errors.append('An error occurred retrieving the PDB file "%s".' % batch_file_selector)
                 else:
                     # We are on the cluster so try to retrieve the stored file
                     colortext.message('No file %s exists - assuming that this is a PDB ID and trying to retrieve the associated file from the cluster mirror of the PDB database.' % batch_file_selector)
                     if os.path.exists('/netapp/database/pdb/remediated/uncompressed_files/pdb%s.ent' % batch_file_selector):
                         batch_files.append('/netapp/database/pdb/remediated/uncompressed_files/pdb%s.ent' % batch_file_selector)
                     elif os.path.exists('/netapp/database/pdb/pre-remediated/uncompressed_files/pdb%s.ent' % batch_file_selector):
                         batch_files.append('/netapp/database/pdb/pre-remediated/uncompressed_files/pdb%s.ent' % batch_file_selector)
                     else:
                         errors.append('Could not find a PDB file for argument "%s".' % batch_file_selector)
                         missing_files.append(batch_file_selector)
         else: