コード例 #1
0
    def _build(self):
        SBIglobals.alert(
            'deepdebug', self,
            'Analyzing AA Contact {0.type}:{0.number} - {1.type}:{1.number}'.
            format(self.aminoacid1, self.aminoacid2))

        for dist_type in self.available_distance_types:
            self._distance.setdefault(dist_type, None)

        self._distance[self._threshold_type] = self.aminoacid1.distance(
            self.aminoacid2, dist_type=self._threshold_type)
        SBIglobals.alert(
            'deepdebug', self, '\tEvaluating distance {0:.3f} of {1}'.format(
                self._distance[self._threshold_type][2], self._threshold_type))
        if float(self._distance[self._threshold_type][2]) <= self._threshold_distance and \
           float(self._distance[self._threshold_type][2]) >= 0:
            SBIglobals.alert('deepdebug', self, '\tDistance under threshold.')
            self._underthreshold = True
            for dist_type in self._distance:
                if dist_type != self._threshold_type:
                    SBIglobals.alert(
                        'deepdebug', self,
                        '\tGathering {0} distance'.format(dist_type))
                    self._distance[dist_type] = self.aminoacid1.distance(
                        self.aminoacid2, dist_type=dist_type)
                    SBIglobals.alert(
                        'deepdebug', self,
                        '\t\tDistance {0:.3f} of {1}'.format(
                            self._distance[dist_type][2], dist_type))
コード例 #2
0
    def __init__(self, database, search_type = 'prot'):

        #Search Type Check
        if search_type not in set(['prot','nucl']):
            raise BE(-10)
        self._search_type = search_type

        #Blast executable configuration
        self._configurator = ConfigParser.RawConfigParser(allow_no_value=True)
        self._configurator.read(os.getenv('SBI_CONFIG_FILE',default_configuration_file))
        self._exe    = Executable(executable    = self._configurator.get('blast','executable'),
                                  path          = self._configurator.get('blast','path'),
                                  variable_path = self._configurator.get('blast','variable_path'))

        #Database Configuration
        self._database = self._check_database(os.path.abspath(database))
        if os.path.isfile(self._database.file.full + ".idx"):
            self._idx = File(file_name = self._database.file.full + ".idx", action = 'r')
        else:
            self._idx = None

        #Adding fixed blast parameters
        self._exe.add_attribute(self._database.file.full, '-db')
        self._exe.add_attribute('5', '-outfmt')
        self._exe.add_parameter('-lcase_masking')

        SBIglobals.alert('debug', self, 'New Blast Executable created.\nBlast executable at {0}\n'.format(self._exe.full_executable))

        self._selfHit     = False
        self._hitIDformat = 'single'
        self._overwritte  = False
        self._clean_files = True
コード例 #3
0
    def remove(self, other, new_fasta_file, force=None):
        '''
        Two {Fasta} objects can be subtracted. In that case, sequences from the
        first {Fasta} who appear in the second {Fasta} are removed. Sequences are
        identified only by sequence identifier.

        @param:    other
        @pdef:     {Fasta} containing the sequences to remove from the {Fasta}
        @ptype:    {Fasta}

        @param:    new_fasta_file
        @pdef:     name of the new fasta file
        @ptype:    {String}

        @param:    force
        @pdef:     overwrite previous files with the same name
        @pdefault: _SBIglobals.overwrite_
        @ptype:    {Boolean}

        @return: {Fasta}
        '''
        remove_seq = set(other.sequence_identifiers)
        sequences = []

        for seq in self.live_show():
            if seq.id not in remove_seq:
                SBIg.alert('verbose', self,
                           'ACCEPT sequence {0}'.format(seq.id))
                sequences.append(seq)
            else:
                SBIg.alert('verbose', self,
                           'REJECT sequence {0}'.format(seq.id))
        return Fasta.build_multifasta(new_fasta_file, sequences, force)
コード例 #4
0
    def _check_database(self, database):
        #Database file does not exist
        if not os.path.isfile(database):
            raise BE(code = -5, value = database)

        #Database is not formated (if dbformatexe is added in the configuration path it will be autoformated)
        formatdb_files = []
        if self._search_type == 'nucl':     formatdb_sufix = ['.nhr','.nin','.nsq']
        elif self._search_type == 'prot':   formatdb_sufix = ['.phr','.pin','.psq']
        for sufix in formatdb_sufix:
            if not os.path.isfile(database + sufix):
                formatdb_files.append(database + sufix)

        if len(formatdb_files) > 0:
            try:
                dbexe  = Executable(executable    = self._configurator.get('blast','dbformatexe'),
                                    path          = self._configurator.get('blast','path'),
                                    variable_path = self._configurator.get('blast','variable_path'))

                SBIglobals.alert('debug', self, 'Trying to format de DB {0} to perform a blast search.\n'.format(database))

                dbexe.add_attribute(database, '-in')
                dbexe.add_attribute(self._search_type, '-dbtype')

                SBIglobals.alert('debug', self, 'Executing command {0}\n'.format(dbexe))

                dbexe.execute()

            except ConfigParser.NoOptionError, e:
                raise BE(code = -6, value = formatdb_files)
            except SystemError, e:
                raise BE(code = -11, value = e)
コード例 #5
0
def builtArchDB(pdblist, pdbdir, outdir):
    pdb_connect = PDBlink(local=pdbdir)
    for pdbinfo in pdblist:
        pdb, chain = pdbinfo
        subdir = pdb[1:3].lower()
        pdbfile = pdb_connect.get_PDB(pdb)
        SBIglobals.alert('verbose', None,
                         'Processing file: {0}'.format(pdbfile))
        archs = archer.build_archs(sourcepdb=pdbfile,
                                   chain=chain,
                                   limit_distance=25)
        for archkey in archs:
            if len(archs[archkey]) > 0:
                Path.mkdir(os.path.join(outdir[archkey], subdir))
                Path.mkdir(os.path.join(outdir['STRUC'], subdir))
            for arch in archs[archkey]:
                pyobjName = "_".join([
                    str(arch.aminoacid_distance), arch.type, arch.identifier
                ]) + '.archObj'
                arch.dump(
                    os.path.join(os.path.join(outdir[archkey], subdir),
                                 pyobjName))
                arch.format2file(filename=os.path.join(
                    os.path.join(outdir['STRUC'], subdir), arch.identifier),
                                 extension='pdb',
                                 center=True)
                arch.format2file(filename=os.path.join(
                    os.path.join(outdir['STRUC'], subdir), arch.identifier),
                                 extension='js',
                                 center=True)
コード例 #6
0
 def _distance_cb_backbone(self, nucleotide):
     if self.has_cb:
         cb_coord = np.array(np.zeros(3))
         cb_coord = np.vstack((cb_coord, self.cb.coordinates))
         cb_coord = np.delete(cb_coord, 0, 0)
         atom = self.cb
     elif self.has_ca:
         cb_coord = np.array(np.zeros(3))
         cb_coord = np.vstack((cb_coord, self.ca.coordinates))
         cb_coord = np.delete(cb_coord, 0, 0)
         atom = self.ca
     else:
         return (None, None, -1)
     if nucleotide._backbone_coordinates is not None:
         n_coord = nucleotide._backbone_coordinates
         n_atoms = nucleotide._backbone_atoms
     else:
         n_coord = nucleotide._sidechain_coordinates
         n_atoms = nucleotide._sidechain_atoms
     SBIglobals.alert('deepdebug', self,
                      '\tAminoAcid coordenate {0}'.format(cb_coord))
     SBIglobals.alert('deepdebug', self,
                      '\tNucleotide coordenates {0}'.format(n_coord))
     distances = sp.distance.cdist(cb_coord, n_coord)
     index = np.unravel_index(distances.argmin(), distances.shape)
     return (atom, n_atoms[index[1]], distances.min())
コード例 #7
0
    def execute(self, stdout=False, silent=False):
        """
        Executes the commands
        @type  stdout: Boolean
        @param stdout: determines if the output is through stdout
        """
        if self.command is None:
            return False

        if not stdout:
            stdoutPIPE = open('/dev/null', 'w')
        else:
            stdoutPIPE = subprocess.PIPE

        if silent:
            stderrPIPE = open('/dev/null', 'w')
        else:
            stderrPIPE = subprocess.PIPE

        SBIglobals.alert(
            'debug', self,
            '\tExecuting command:\n\t{0}\n'.format(" ".join(self.command)))

        p = subprocess.Popen(self.command,
                             stdout=stdoutPIPE,
                             stderr=stderrPIPE)

        out, err = p.communicate()

        if stdout:
            self._stdout = out

        if not silent and err.strip() != '':
            raise SystemError(err)
コード例 #8
0
def parse_subhit(subhit):
    """
    Returns the required data from the given subhit 
    """
    data = {}
    """
        Totally random, Sometimes, with 0 gaps, 0 identities or 0 positives no tag is specified...
    """
    if len(subhit.getElementsByTagName("Hsp_gaps")) != 0:
        data['hg'] = int(
            subhit.getElementsByTagName("Hsp_gaps")[0].childNodes[0].nodeValue)
    else:
        data['hg'] = 0
    if len(subhit.getElementsByTagName("Hsp_identity")) != 0:
        data['hi'] = int(
            subhit.getElementsByTagName("Hsp_identity")
            [0].childNodes[0].nodeValue)
    else:
        data['hi'] = 0
    if len(subhit.getElementsByTagName("Hsp_positive")) != 0:
        data['hp'] = int(
            subhit.getElementsByTagName("Hsp_positive")
            [0].childNodes[0].nodeValue)
    else:
        data['hp'] = 0

    SBIglobals.alert(
        'debug', 'blast_parser',
        "\t\tGaps: %d\n\t\tIdentities: %d\n\t\tSimilarities: %d\n" %
        (data['hg'], data['hi'], data['hp']))
    """
        The rest of the data is easier
    """
    data['ev'] = float(
        subhit.getElementsByTagName("Hsp_evalue")[0].childNodes[0].nodeValue)
    data['al'] = int(
        subhit.getElementsByTagName("Hsp_align-len")
        [0].childNodes[0].nodeValue)
    data['qs'] = str(
        subhit.getElementsByTagName("Hsp_qseq")
        [0].childNodes[0].nodeValue).strip()
    data['hs'] = str(
        subhit.getElementsByTagName("Hsp_hseq")
        [0].childNodes[0].nodeValue).strip()
    data['qpi'] = int(
        subhit.getElementsByTagName("Hsp_query-from")
        [0].childNodes[0].nodeValue)
    data['qpe'] = int(
        subhit.getElementsByTagName("Hsp_query-to")[0].childNodes[0].nodeValue)
    data['hpi'] = int(
        subhit.getElementsByTagName("Hsp_hit-from")[0].childNodes[0].nodeValue)
    data['hpe'] = int(
        subhit.getElementsByTagName("Hsp_hit-to")[0].childNodes[0].nodeValue)
    data['scs'] = str(
        subhit.getElementsByTagName("Hsp_midline")
        [0].childNodes[0].nodeValue).strip()

    return data
コード例 #9
0
    def sync_directories(sourcedir,
                         destinationdir,
                         by_dir=True,
                         by_file=False,
                         listdif=False):
        """
            > sync_directories(): Syncronizes two directory trees.
                                    - sourcedir      (string): Name of the original directory
                                                               @Mandatory
                                    - destinationdir (string): Name of the syncronized directory
                                                               @Mandatory
                                    - by_dir         (bool)  : Sync is performed at directory level
                                                               @Default: True
                                    - by_file        (bool)  : Sync is performed at file level
                                                               @Default: False
                                    - listdif        (bool)  : When True, sync is not performed, only listed
                                                               @Default: False
                                    @Yields file/dir names when listdif is True
                                    @Raises AttributeError if by_dir and by_file are both True
        """
        if by_file is True and by_dir is True:
            raise AttributeError(
                'Both sync methods can not be active simultaneously')

        source_dirs = set()
        if by_dir:
            for onedir in Path.list_directories(root=sourcedir, rootless=True):
                source_dirs.add(onedir)
            for onedir in Path.list_directories(root=destinationdir,
                                                rootless=True):
                if onedir in source_dirs:
                    source_dirs.remove(onedir)
        if by_file:
            for onedir in Path.list_files(root=sourcedir, rootless=True):
                source_dirs.add(onedir)
            for onedir in Path.list_files(root=destinationdir, rootless=True):
                if onedir in source_dirs:
                    source_dirs.remove(onedir)

        previous_dir = '#not_a_dir_at_all'
        sourcedir = os.path.abspath(sourcedir)
        destinationdir = os.path.abspath(destinationdir)
        for onedir in sorted(source_dirs):
            onedir = onedir.lstrip('/')
            if not os.path.commonprefix([previous_dir, onedir
                                         ]) == previous_dir:
                SBIglobals.alert(
                    'verbose', Path(),
                    '{0} is different from {1} to {2}'.format(
                        onedir, sourcedir, destinationdir))
                if not listdif:
                    fullori = os.path.join(sourcedir, onedir)
                    shutil.copytree(os.path.join(sourcedir, onedir),
                                    os.path.join(destinationdir, onedir))
                else:
                    yield os.path.join(sourcedir, onedir)
                previous_dir = onedir
コード例 #10
0
    def _add_HTc(self, chain):
        if self._HTdo and chain.chaintype == 'P':
            phi_id = PHInnerContact.test_identifier(chain)
            SBIglobals.alert('debug', self, 'Analyzing Protein-Heteroatom Inner Contacts {0} for {1.chain}'.format(phi_id, chain))

            phi = PHInnerContact(chain, self._HT_type, self._HT_distance)

            SBIglobals.alert('debug', self, '\tAdding new Inner Contacts')
            self._HTcontacts[phi_id] = phi
コード例 #11
0
    def _check_action(self, action):
        if not action in self.available_action:  # Raise 'Wrong action' Error
            raise File(1, action, self.available_action)
        if self.is_gziped and not action.endswith('b'):
            action += 'b'  # Better if working with compressed files

        self._action = action

        SBIglobals.alert('debug', self,
                         '\tAction {0} is OK...'.format(self._action))
コード例 #12
0
    def _add_AAc(self, chain):
        if self._AAdo and chain.chaintype == 'P':
            raise NotImplementedError
            ppi_id = PPInnerContact.test_identifier(chain)
            SBIglobals.alert('debug', self, 'Analyzing Protein Inner Contacts {0} for {1.chain}'.format(ppi_id, chain))

            ppi = PPInnerContact(chain, self._AA_type, self._AA_distance)

            SBIglobals.alert('debug', self, '\tAdding new Inner Contacts')
            self._AAcontacts[ppi_id] = ppi
コード例 #13
0
 def get_residue_by_identifier(self, identifier):
     if len(self._chaindict) == 0:
         for r in self.full_chain:
             self._chaindict[r.identifier.strip()] = r
     try:
         r = self._chaindict[str(identifier.strip())]
     except KeyError as e:
         SBIglobals.alert('error', self, '{0} is not a valid identifier for chain {1}'.format(identifier, self.globalID), e)
     else:
         return r
コード例 #14
0
    def _build(self):
        count  = 1

        SBIglobals.alert('debug', self, 'Analyzing Inner Contacts of {0:03} chains'.format(len(self.pdb)))

        for chain in self.pdb.chains:
            SBIglobals.alert('debug', self, 'Analyzing Chain {0:03} out of {1:03}'.format(count, len(self.pdb)))
            self._add_AAc(chain)
            self._add_NCc(chain)
            self._add_HTc(chain)
            count += 1
コード例 #15
0
 def dump(self, object_file, overwrite = None):
     """
         - dump(): Stores the object into a file
                     - object_file (string): Name for the output file
                                             @Mandatory
                     - overwrite (bool):     Overwrite previous file of the same name
                   @Raises FileError
     """
     SBIglobals.alert('verbose', self, 'Writting object to file {0}'.format(object_file))
     dumpFile = File(file_name = object_file, action = 'wb', overwrite = overwrite)
     pickle.dump(self, dumpFile.descriptor)
     dumpFile.close()
コード例 #16
0
    def _check_file(self):
        if self._action.startswith('r'):
            if not os.path.isfile(self.full):
                raise FileError(3, self.full, 'noexists')
            if not os.access(self.full, os.R_OK):
                raise FileError(4, self.full, 'read')
        if self._action.startswith('w') or self._action.startswith('a'):
            if os.path.isfile(self.full):
                if not self._overwrite: raise FileError(3, self.full, 'exists')
            if not os.path.isdir(self.dir):
                raise FileError(4, self.dir, 'nodir')
            if not os.access(self.dir, os.W_OK):
                raise FileError(4, self.dir, 'write')

        SBIglobals.alert('debug', self, '\tFile is OK...')
コード例 #17
0
 def load(object_file):
     """
         > load(): Retrieves the object from a python object file
                     - object_file (string): Name of the file containing the object
                                             @Mandatory
                   @Returns the loaded object.
                   @staticmethod: can be called without any instance declared
                   @Raises FileError
     """
     SBIglobals.alert('verbose', StorableObject, 'Preparing to load object from file {0}'.format(object_file))
     Object   = None
     loadFile = File(file_name = object_file, action='rb')
     Object   = pickle.load(loadFile.descriptor) 
     loadFile.close()
     return Object
コード例 #18
0
    def __init__(self, file_name=None, action='r', overwrite=None):
        if file_name is None:
            raise FileError(0)  # Raise 'No file specified' Error
        self._file = file_name

        SBIglobals.alert('debug', self,
                         'Preparing File: {0}'.format(self.full))

        self._action = None
        self._check_action(action.lower())  #action must be valid

        self._fd = None
        # Local overwrite takes precedence over Global overwrite
        self._overwrite = SBIglobals.decide_overwrite(overwrite)

        self._check_file()
コード例 #19
0
    def retrieve(self, sequence_ids, all_but=False, prefix_size=None):
        '''
        Get specific sequences from the FASTA file.

        @param:    sequence_ids
        @pdef:     sequence identifier(s)
        @ptype:    {String}, {List} or {Set}

        @param:    all_but
        @pdef:     Flag. Instead of retrieving the given ids, we retrieve all
                   except the given ids.
        @pdefault: _False_
        @ptype:    {Boolean}

        @param:    prefix_size
        @pdef:     maximum characters for the prefix. If _None_, all the
                   characters are included.
        @pdefault: _None_
        @ptype:    {Integer}

        @raises: {AttributeError} if sequence_ids is not a valid type.
        @return: {List} of {Sequence}
        '''
        info = 'Skipping sequence {0}' if all_but else 'Getting sequence {0}'

        if not isinstance(sequence_ids, (list, set)):
            SBIg.alert('debug', self, info.format(sequence_ids))
        else:
            SBIg.alert('debug', self, [info.format(x) for x in sequence_ids])

        if isinstance(sequence_ids, basestring):
            sequence_ids = set([sequence_ids])
        if isinstance(sequence_ids, list):
            sequence_ids = set(sequence_ids)
        if isinstance(sequence_ids, set):
            sequences = []
            for s in self.live_show():
                seq_id = s.id if prefix_size is None else s.id[:prefix_size]
                if seq_id in sequence_ids and not all_but:
                    sequences.append(s)
                if seq_id not in sequence_ids and all_but:
                    sequences.append(s)
            return sequences
        else:
            raise AttributeError('sequence_ids must be a string, list or set.')
コード例 #20
0
    def _format_database(self, database):
        '''
        Executes the blast script to format the database.

        @param:    database
        @pdef:     database to blast upon.
        @ptype:    {String}
        '''
        SBIg.warn(self, 'Formating {0} for blast.'.format(database))
        dbexe  = Executable(executable = BlastExe._DBFORMATER,
                            path       = self._EXE.path)

        dbexe.add_attribute(database,               '-in')
        dbexe.add_attribute(self._search_type[0:4], '-dbtype')

        SBIg.alert('debug', self, 'Executing command {0}\n'.format(dbexe))

        dbexe.execute()
コード例 #21
0
 def list_directories(root=os.curdir, rootless=False):
     """
         > list_directories(): Returns all dirs in a directory tree
                                 - root              (string): Root of the directory tree to search
                                                               @Default: current working directory
                                 - rootless          (bool)  : When False, the name of the dirs are returned with
                                                               absolute path. Otherwise the root is removed.
                                                               @Default: False
                               @Yields directory names
     """
     for path, dirs, files in os.walk(os.path.abspath(root)):
         for onedir in dirs:
             SBIglobals.alert(
                 'debug', Path(),
                 'Found directory {0}'.format(os.path.join(path, onedir)))
             if not rootless:
                 yield os.path.join(path, onedir)
             else:
                 yield os.path.join(path, onedir).replace(root, '')
コード例 #22
0
    def _build(self):
        if len(self.protein.aminoacids) == 0 or len(
                self.nucleotide.nucleotides) == 0:
            return
        super(PNInterface, self)._build()

        for i in range(len(self._filtered[0])):
            SBIglobals.alert(
                'deepdebug', self,
                'Analyze AN Contact for {0.type}:{0.number} - {1.type}:{1.number}'
                .format(self.protein.aminoacids[self._filtered[0][i]],
                        self.nucleotide.nucleotides[self._filtered[1][i]]))
            new_contact = ContactAN(
                aminoacid=self.protein.aminoacids[self._filtered[0][i]],
                nucleotide=self.nucleotide.nucleotides[self._filtered[1][i]],
                threshold_type=self.threshold_type,
                threshold_distance=self.threshold_distance)
            if new_contact.is_underthreshold:
                self.contacts = new_contact
コード例 #23
0
    def _simple_execute(self, threshold):
        self._EXE.add_attribute(self._input, '-i')
        self._EXE.add_attribute(self._output, '-o')
        SBIg.alert('debug', self, 'Setting threshold to {0}'.format(threshold))
        self._EXE.add_attribute(threshold, '-c')
        self._EXE.add_attribute('1', '-g')
        SBIg.alert('debug', self, 'Setting word to {0}'.format(self._word))
        self._EXE.add_attribute(self._word, '-n')
        if self._memory is not None:
            self._EXE.add_attribute(self._memory, '-M')

        try:
            self._EXE.execute()
            self._EXE.clean_command()
        except SystemError, e:
            SBIg.throw(
                self,
                'Some error occurred while executing cd-hit\n{0}\n'.format(e),
                SystemError)
コード例 #24
0
    def _process(self, update=False):
        '''
        Transform the source files into the final local db files.

        @param:    update
        @pdef:     toggles between create and update processing
        @pdefault: _False_
        @ptype:    {Boolean
        '''
        if update:
            old = self._RELEASE['total_items'].copy()
        j = 0
        for i in range(len(self._SOURCES)):
            dfilen = os.path.join(self.local, self._SOURCES[i])
            ofilen = os.path.join(self.local, self._MANDATORY_FILES[j])
            ffilen = os.path.join(self.local, self._MANDATORY_FILES[j + 1])
            if not os.path.isfile(dfilen):
                continue
            SBIg.alert('verbose', self, 'Parsing:       {0}'.format(dfilen))
            SBIg.alert('verbose', self, 'DB file to:    {0}'.format(ofilen))
            SBIg.alert('verbose', self, 'Fasta file to: {0}'.format(ffilen))
            dfile = File(dfilen)
            ofile = File(ofilen, 'w', update)
            ffile = File(ffilen, 'w', update)
            protein = None
            for protein in Connect._parse_uniprot(dfile):
                pname = protein.entry_name
                pvers = protein.version
                SBIg.alert('verbose', self, 'Protein: {0}'.format(pname))
                if not update:
                    self._RELEASE['total_items'][pname] = pvers
                else:
                    if pname not in self._RELEASE['total_items']:
                        self._RELEASE['new_items'][pname] = pvers
                    else:
                        del (old[pname])
                        if self._RELEASE['total_items'][pname] != pvers:
                            self._RELEASE['update_items'][pname] = pvers

                ffile.write(protein.sequence.format('FASTA') + '\n')
                ofile.write(protein.json() + '\n')
            j += 2
            dfile.close()
            ofile.close()
            ffile.close()

        if update:
            self._RELEASE['total_items'].update(self._RELEASE['new_items'])
            self._RELEASE['total_items'].update(self._RELEASE['update_items'])
            self._RELEASE['deleted_items'] = old
            for k in self._RELEASE['deleted_items']:
                del (self._RELEASE['total_items'][k])
コード例 #25
0
    def _format_database(self, database):
        '''
        Executes the hmmer script to format the database.

        @param:    database
        @pdef:     database to blast upon.
        @ptype:    {String}
        '''
        SBIg.warn(self, 'Formating {0} for hmmer.'.format(database))

        dbexe = Executable(executable=HmmExe._DBFORMATER, path=self._EXE.path)

        if self.overwrite:
            dbexe.add_parameter('-f')

        dbexe.add_parameter(database)

        SBIg.alert('debug', self, 'Executing command {0}\n'.format(dbexe))

        dbexe.execute()
コード例 #26
0
ファイル: Residue.py プロジェクト: venkatesh-sivaraman/MODPIN
    def reposition(self, matrix=None, vector=None):
        """
        Rotates and translates the {Residue} according to a matrix and translational vector

        @type matrix: numpy.matrix

        @type vector: numpy.array
        """
        if matrix is None: matrix = np.identity(3, float)
        if vector is None: vector = np.zeros(3, float)
        SBIglobals.alert('deepdebug', self,
                         'Reposition residue {0.type}:{0.number}'.format(self))

        self._backbone_coordinates = None
        self._sidechain_coordinates = None
        for atom in self.atoms:
            SBIglobals.alert('deepdebug', self,
                             'Atom {0.name} {0.is_backbone}'.format(atom))
            atom.rotate(matrix=matrix)
            atom.translate(vector=vector)
            self._add_to_matrix(atom)
コード例 #27
0
    def _download_sources(self):
        '''
        Download the source files to local directory.
        '''
        for dfile in self._SOURCES:
            download = False
            source = os.path.join(self._FTP, dfile)
            source_size = DBlink._file_size(source)
            # source_date = DBlink._file_date(source)
            DBlink._SOURCES_SIZES.append(source_size)
            destination = os.path.join(self.local, dfile)
            if not os.path.isfile(destination):
                if DBlink._RELEASE['date'] != DBlink._TODAY:
                    # if source_date < DBlink._RELEASE:
                    #     SBIg.alert('verbose', self, 'No new updates in the source side' +
                    #                                 ' for {0}'.format(source) +
                    #                                 ' since the last local update.')
                    # else:
                    download = True
                else:
                    download = True
            else:
                SBIg.alert(
                    'verbose', self,
                    'Looks like {0} has already been downloaded.'.format(
                        source))

            if download:
                SBIg.alert(
                    'verbose', self,
                    'Downloading {0} to {1}'.format(source, destination))
                SBIg.alert(
                    'verbose', self,
                    'Source file size is {0:.3f} MB.'.format(source_size))
                urllib.urlretrieve(source, destination)
コード例 #28
0
ファイル: archer.py プロジェクト: jaumebonet/archer
def sortarchs(inputdir, outputdir):
    
    archsdir              = outputdir
    Path.mkdir(archsdir)
    sorted_archs          = {}
    loop_file_name        = os.path.join(archsdir, 'ArchDB.{0}.db')
    loop_split_file_name  = os.path.join(archsdir, 'ArchDB.{0}.{1:02d}-{2:02d}.db')
    sections_ini          = [ 0, 4, 7,14,21]
    sections_end          = [ 4, 6,13,20, 0]
    for archfile in Path.list_files(root = inputdir, pattern = '*.archObj'):
        filename = os.path.basename(archfile)
        data     = filename.split('_')
        length   = int(data[0])
        archtype = data[1] 
        sorted_archs.setdefault(archtype,{}).setdefault(length,[])
        sorted_archs[archtype][length].append(archfile)
    
    for archtype in sorted_archs:
        SBIglobals.alert('verbose', None, "ARCHS: " + archtype + "\n")
        fd  = File(loop_file_name.format(archtype), 'w')
        fdp = []
        for x in range(len(sections_ini)):
            fdp.append(File(loop_split_file_name.format(archtype, sections_ini[x], sections_end[x]), 'w'))
        for length in sorted(sorted_archs[archtype]):
            SBIglobals.alert('verbose', None, '\t{0}'.format(length))
            for archfile in sorted_archs[archtype][length]:
                SBIglobals.alert('verbose', None, '\t\t{0}\n'.format(archfile))
                nsp = Arch.load(archfile)
                fd.descriptor.write(nsp.archtype_format() + "\n")
                for x in range(len(fdp)):
                    if length >= sections_ini[x] and (sections_end[x] == 0 or length <= sections_end[x]):
                        fdp[x].descriptor.write(nsp.archtype_format() + "\n")
        fd.close()
        for x in range(len(fdp)):
            fdp[x].close()
コード例 #29
0
    def __init__(self, pdb_file=None):
        SBIglobals.alert('debug', self,
                         'Loading PDB file {0}'.format(pdb_file))

        super(PDB, self).__init__(pdb_file=pdb_file,
                                  dehydrate=True,
                                  header=True)

        SBIglobals.alert(
            'debug', self,
            'Calculating Inner Contacts for Protein - Heteroatom')
        self.innercontacts = InnerContacts(pdb=self,
                                           AA=False,
                                           NC=False,
                                           HT=True,
                                           HT_type="min",
                                           HT_distance=6)

        SBIglobals.alert(
            'debug', self,
            'Calculating PP and PN interfaces of the biomolecules in the PDB')
        self.interfaces = Complex(pdb=self,
                                  biomolecule=True,
                                  PPI=True,
                                  PPI_type="cb",
                                  PPI_distance=12,
                                  PNI=True,
                                  PNI_type="min",
                                  PNI_distance=8,
                                  PHI=True,
                                  PHI_type="min",
                                  PHI_distance=6)
コード例 #30
0
    def list_files(root=os.curdir,
                   pattern='*',
                   avoid_empty_files=True,
                   rootless=False):
        """
            > list_files()      : Returns any file in a directory tree matching a specific pattern
                                    - root              (string): Root of the directory tree to search
                                                                  @Default: current working directory
                                    - pattern           (string): Expression to match (ls-like format)
                                                                  (Accepts list of strings)
                                                                  @Default: *
                                    - avoid_empty_files (bool)  : Ignore files with size 0
                                                                  @Default: True
                                    - rootless          (bool)  : When False, the name of the files are returned with
                                                                  absolute path. Otherwise the root is removed.
                                                                  @Default: False
                                  @Yields file names
        """
        if os.path.isfile(root): yield root

        search_patterns = []
        if not isinstance(pattern, list):
            search_patterns.append(pattern)
        else:
            search_patterns = pattern
        for pat in search_patterns:
            for path, dirs, files in os.walk(os.path.abspath(root)):
                for filename in fnmatch.filter(files, pat):
                    if not avoid_empty_files or os.path.getsize(
                            os.path.join(path, filename)) > 0:
                        SBIglobals.alert(
                            'debug', Path(), 'Found file {0}'.format(
                                os.path.join(path, filename)))
                        if not rootless:
                            yield os.path.join(path, filename)
                        else:
                            root = os.path.abspath(root) + "/"
                            yield os.path.join(path,
                                               filename).replace(root, '')
コード例 #31
0
    def _build(self):
        for dist_type in self.available_distance_types:
            self._distance.setdefault(dist_type, None)

        self._distance[self._threshold_type] = self.aminoacid.distance(self.nucleotide, dist_type = self._threshold_type)
        SBIglobals.alert('deepdebug', self, '\tEvaluating distance {0:.3f} of {1}'.format(self._distance[self._threshold_type][2], self._threshold_type))
        if float(self._distance[self._threshold_type][2]) <= self._threshold_distance and \
           float(self._distance[self._threshold_type][2]) >= 0:
            SBIglobals.alert('deepdebug', self, '\tDistance under threshold.')
            self._underthreshold = True
            for dist_type in self._distance:
                if dist_type != self._threshold_type:
                    SBIglobals.alert('deepdebug', self, '\tGathering {0} distance'.format(dist_type))
                    self._distance[dist_type] = self.aminoacid.distance(self.nucleotide, dist_type = dist_type)
                    SBIglobals.alert('deepdebug', self, '\t\tDistance {0:.3f} of {1}'.format(self._distance[dist_type][2], dist_type))