Example #1
0
def pbassign_cli():
    """
    PBassign command line.
    """
    options, pdb_name_lst = user_inputs()

    if options.p:
        if pdb_name_lst:
            print("{} PDB file(s) to process".format(len(pdb_name_lst)))
        else:
            print("Nothing to do. Good bye.")
            return
        # PB assignement of PDB structures
        chains = pbx.chains_from_files(pdb_name_lst)
    else:
        # PB assignement of a Gromacs trajectory
        chains = pbx.chains_from_trajectory(options.x, options.g)

    all_comments = []
    all_sequences = []
    for comment, chain in chains:
        dihedrals = chain.get_phi_psi_angles()
        sequence = pbx.assign(dihedrals)
        all_comments.append(comment)
        all_sequences.append(sequence)

    fasta_name = options.o + ".PB.fasta"
    with open(fasta_name, "w") as outfile:
        pbx.io.write_fasta(outfile, all_sequences, all_comments)

    print("wrote {0}".format(fasta_name))
    def test_loader_PDB(self):
        """
        Test for API loader function on PDBs
        """
        filename = os.path.join(here, "test_data/2LFU.pdb")
        comment, chain = list(pbx.chains_from_files([filename]))[0]

        ref_comment = "{0} | model 1 | chain A".format(filename)
        ref_chain = "Chain A / model 1: 2372 atoms"
        assert ref_comment == comment
        assert ref_chain == format(chain)
Example #3
0
    def test_loader_PDB(self):
        """
        Test for API loader function on PDBs
        """
        filename = os.path.join(here, "test_data/2LFU.pdb")
        comment, chain = list(pbx.chains_from_files([filename]))[0]

        ref_comment = "{0} | model 1 | chain A".format(filename)
        ref_chain = "Chain A / model 1: 2372 atoms"
        self.assertEqual(ref_comment, comment)
        self.assertEqual(ref_chain, format(chain))
Example #4
0
def pbassign_cli():
    """
    PBassign command line.
    """
    options, pdb_name_lst = user_inputs()

    if options.p:
        if pdb_name_lst:
            print("{} PDB file(s) to process".format(len(pdb_name_lst)))
        else:
            print('Nothing to do. Good bye.')
            return
        # PB assignement of PDB structures
        chains = pbx.chains_from_files(pdb_name_lst)
    else:
        # PB assignement of a Gromacs trajectory
        chains = pbx.chains_from_trajectory(options.x, options.g)

    all_comments = []
    all_sequences = []
    for comment, chain in chains:
        try:
            dihedrals = chain.get_phi_psi_angles()
            sequence = pbx.assign(dihedrals)
            all_comments.append(comment)
            all_sequences.append(sequence)
        except FloatingPointError:
            print(
                "The computation of angles produced NaN. This typically means there are issues"
                " with some residues coordinates. Check your input file ({0})".
                format(comment),
                file=sys.stderr)

    if all_comments:
        fasta_name = options.o + ".PB.fasta"
        with open(fasta_name, 'w') as outfile:
            pbx.io.write_fasta(outfile, all_sequences, all_comments)

        print("wrote {0}".format(fasta_name))
    else:
        print("No output file was written")
Example #5
0
def liste_sequence(path_sequences):
    '''
    Parse le dossier contenant les fichiers pdb a analyses.
    Assigne a chaque PDB une sequence de blocs proteique.
    Retourne une liste de sequences de blocs proteique (sequences) ainsi
    que la liste des PDB (liste_PDB) presents dans le repertoire
    (path_sequences).
    '''
    sequences = []
    liste_PDB = []
    liste_chain = []
    for element in os.listdir(path_sequences):
        if element.endswith('.pdb'):
            liste_PDB.append(element)
            for chain_name, chain in pbx.chains_from_files(
                [path_sequences + "/" + element]):
                liste_chain.append(chain_name)
                # Calcule angle phi et psi
                dihedrials = chain.get_phi_psi_angles()
                # assignation des blocks proteique
                pb_seq = pbx.assign(dihedrials)
                sequences.append(pb_seq)
    return sequences, liste_PDB, liste_chain
Example #6
0
def cli(args=None):
    """Entry point for seq_to_first_iso's CLI.

    Parameters
    ----------
    args : list of str, optional
        CLI arguments, args are used for testing (default is None for CLI).

    Returns
    -------
    None
        Writes a csv file and possibly a gml file.

    Raises
    ------
    SystemExit
        If no sequences were found on the file.

    Notes
    -----
    Main function of the script, for use with CLI.

    """
    if not args:
        args = sys.argv[1:]

    options, pdb_name_lst = user_inputs()
    if options.pdb:
        if pdb_name_lst:
            print("{} PDB file(s) to process".format(len(pdb_name_lst)))
        else:
            print('Nothing to do. Good bye.')
            return
        # PB assignement of PDB structures
        chains = pbx.chains_from_files(pdb_name_lst)
    else:
        # PB assignement of a Gromacs trajectory
        chains = pbx.chains_from_trajectory(options.x, options.g)

    all_comments = []
    all_sequences = []

    for comment, chain in chains:
        try:
            dihedrals = chain.get_phi_psi_angles()
            sequence = pbx.assign(dihedrals)
            all_comments.append(comment)
            all_sequences.append(sequence)
        except FloatingPointError:
            log.error("The computation of angles produced NaN. "
                      "This typically means there are issues with "
                      "some residues coordinates. "
                      f"Check your input file ({comment})")

    log.info(f"There are {len(all_sequences)} sequences of length "
             f"{len(all_sequences[0])}")
    log.info("Calculating the Mutual Information matrix ...")
    MI_matrix = mutual_information_matrix(all_sequences)
    # Write to a file
    log.info(f"Writing the matrix as {options.output} ...")
    df = pd.DataFrame(MI_matrix)
    df.to_csv(options.output)

    # Add option in CLI, centrality
    # Creating a network.
    if options.network:
        log.info("Creating a network ...")
        PB_graph = interaction_graph(MI_matrix)
        log.info(f"Writing the network as {options.network} ...")
        # Write the graph to GML format.
        nx.write_gml(PB_graph, path=options.network)