Skip to content

Commit

Permalink
Merge branch 'release/1.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
brendaferrari committed Jan 25, 2022
2 parents 63b5637 + 5c88b02 commit 0c3a9c5
Show file tree
Hide file tree
Showing 11 changed files with 280 additions and 56 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Byte-compiled / optimized / DLL files
__pycache__/

# Outputs
smiles_output.txt

# vscode
.vscode
9 changes: 9 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MIT License

Copyright (c) 2021 Brenda Ferrari

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
56 changes: 40 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,60 @@
# PepToCodes - Peptides to Codes
# PepToCodes (1.0.0) - Peptides to Codes

Script developed to transform the amino acid smiles to one letter code or three letter code for latter analysis
Script developed to transform the amino acid smiles to one letter code or three letter code for later analysis.

<img src="resources/images/Peptocodes.png" width="570">

*Illustrative image*

## How to use
## Requirements

* Download the code and unzip it on the desirable directory
* [pandas](https://pandas.pydata.org/) - a Python package that provides fast, flexible, and expressive data structures designed to make working with "relational" or "labeled" data both easy and intuitive.

Libraries were used in a [Miniconda3](https://docs.conda.io/en/latest/miniconda.html) environment using python 3.6.13

## Instalation

To run use the following command:
Miniconda3: [Installation](https://conda.io/projects/conda/en/latest/user-guide/install/index.html)

pandas:
```
python peptocodes.py
conda install -c anaconda pandas
```

* Type your peptide smiles as an input
## How to use

i.e. N[C@@]([H])(CCCNC(=N)N)C(=O)N[C@@]([H])([C@]([H])(O)C)C(=O)N[C@@]([H])(CCCCN)C(=O)N[C@@]([H])(CCCNC(=N)N)C(=O)O
* Download the code and unzip it on the desirable directory

* The answer will pop-up at your terminal screen
* To obtain the one letter code use True as first argument and to obtain the three letter code use True as second argument

i.e. RTKR
* To obtain one letter code:

```
python main.py True False
```
## Observations
* To obtain three letter code:
```
python main.py False True
```
* In this version you may also obtain the 3 letter code for your smiles, just change line 10 to:
```
dictio = pd.read_csv("resources/codes.csv", sep=' ', names=['name', 'smiles', '3lcode', '1lcode'], usecols= ['smiles', '3lcode'], index_col=0, header=None, squeeze=True).to_dict()
```
* For one aminoacid analysis:
* Type your peptide smiles as an input
i.e. N[C@@]([H])(CCCNC(=N)N)C(=O)N[C@@]([H])([C@]([H])(O)C)C(=O)N[C@@]([H])(CCCCN)C(=O)N[C@@]([H])(CCCNC(=N)N)C(=O)O
* The answer will pop-up at your terminal screen
i.e. RTKR
* For more than one aminoacid analysis:
* Use the file [smiles.txt](resources/smiles.txt) as example on how to format input data
* Asteriscs in your code answer means the software could not recognize the input. Please, keep in mind that this software only recognizes [20 aminoacids](resources/codes.csv) for now (canonical and isomeric). We are working on implementing a bigger database.
* **In this version is only possible to tranform ONE smiles at a time**
## Authorship
Expand Down
27 changes: 27 additions & 0 deletions functionalities/dataframe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import pandas as pd

class Dataframe:
"""A class that represents dataframe manipulation
Methods:
create_dataframe(self, columns): Return a formated dataframe"""

def __init__(self, data):
"""Initialize the instance of a class.
Arguments:
data(dict): data used to transform smiles code to peptide code."""
self._data = data

@property
def data(self):
"""Data used to manipulate dataframe."""
return self._data

def create_dataframe(self, columns):
"""Return a formated dataframe.
Arguments:
columns(list): list of strings with column names."""
result = pd.DataFrame.from_dict(self.data, orient='index', columns=columns)
return result
27 changes: 27 additions & 0 deletions functionalities/dictionary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import pandas as pd


class Dictionary:
""" A class that represents the dictionary functionalities.
Method:
Dict(self, one_code=False, three_code=False): Return the full dictionary with all data regards aminoacids on the database.
"""

def Dict(self, one_code=False, three_code=False):
"""Return the full dictionary with all data regards aminoacids on the database.
Arguments:
one_code=False: Default is False. If true returns the one letter code of aminoacids
three_code=False: Default is False. If true returns the three letter code of aminoacids
"""

if one_code is True:
dictio = pd.read_csv("resources/codes.csv", sep=' ', names=['name', 'smiles', '3lcode', '1lcode'],
usecols= ['smiles', '1lcode'], index_col=0, header=None, squeeze=True).to_dict()

elif three_code is True:
dictio = pd.read_csv("resources/codes.csv", sep=' ', names=['name', 'smiles', '3lcode', '1lcode'],
usecols= ['smiles', '3lcode'], index_col=0, header=None, squeeze=True).to_dict()

return dictio
52 changes: 52 additions & 0 deletions functionalities/peptocode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
class PeptoCode:
"""A class that represents peptide to code functionalities.
Arguments:
smiles(str): smiles strings to convert to peptide code.
peptide_data(dict): data used to transform smiles code to peptide code.
Methods:
count_and_change(self): Return a string with the aminoacid code."""

def __init__(self, smiles, peptide_data):
"""Initialize the instance of a class.
Arguments:
smiles(str): smiles strings to convert to peptide code.
peptide_data(dict): data used to transform smiles code to peptide code."""
self.smiles = smiles
self._peptide_data = peptide_data

@property
def peptide_data(self):
"""Data used to transform smiles code to peptide code."""
return self._peptide_data

def count_and_change(self):
"""Return a string with the aminoacid code."""

aacode = []
notaaCode = []
i = 0

while i < len(self.smiles):
keys = list(self.peptide_data.keys())

for j in range(len(keys)):
key = keys[j]

sub = self.smiles[i:i+len(key)]
if sub in self.peptide_data:
i = i + len(key)
aacode.append(self.peptide_data[sub])
break

if j == len(self.peptide_data.keys())-1:
notaaCode.append(sub)
i = i + 1
i = i + len(key)
aacode.append('*')

code = ''.join(aacode)

return code, notaaCode
71 changes: 71 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
from functionalities.peptocode import PeptoCode
from functionalities.dataframe import Dataframe
from functionalities.dictionary import Dictionary

import pandas as pd
import sys

if len(sys.argv) <= 1:
print("One parameter is missing. Please add input file name at following manner: 'python main.py one_code=True/three_code=True'")
sys.exit()

one_code = sys.argv[1].lower() == 'true'
three_code = sys.argv[2].lower() == 'true'

print('Do you wish to transform one aminoacid of a file? Type a to one aminoacid or b for a file.')
answer = input()
if answer.lower() == "a":
print()
smiles = input('Type your peptide smiles: ')

dictio = Dictionary()

peptocode = PeptoCode(smiles, dictio.Dict(one_code, three_code))
aacode, notaaCode = peptocode.count_and_change()

if aacode != "*":
print(f"Your code is: {aacode}")
if notaaCode:
print(f"Some codes were not recognized: {notaaCode}")
else:
print(f"All codes were analyzed and recognized.")
else:
print("Unfortunately your code could not be recognized. Please, verify your code or contact the developers.")

elif answer.lower() == "b":
smiles = input('Type your file name with path: ')

dictio = Dictionary()

df = pd.read_csv(smiles)
aacode = []
notaaCode = []
aasmiles = []
countlen = []
count = 0
for row in df.itertuples():
aasmiles.append(row[1])

peptocode = PeptoCode(row[1], dictio.Dict(one_code, three_code))
code, notCode = peptocode.count_and_change()
aacode.append(code)
notaaCode.append(notCode)

count += 1
countlen.append(count)

variables = zip(aasmiles, aacode, notaaCode)
variablesDataframe = dict(zip(countlen, variables))

dataframe = Dataframe(variablesDataframe)
data = dataframe.create_dataframe(columns=('smiles', 'code', 'not recognized'))
data.to_csv('smiles_output.txt')

if aacode != "*":
print("smiles_output.txt was saved successfully.")
if notaaCode:
print(f"Some codes were not recognized: {notaaCode}")
else:
print(f"All codes were analyzed and recognized.")
else:
print("Unfortunately your code could not be recognized. Please, verify your code or contact the developers.")
39 changes: 0 additions & 39 deletions peptocodes.py

This file was deleted.

2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
python>=3.6.13
pandas>=1.1.5
39 changes: 38 additions & 1 deletion resources/codes.csv
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,41 @@ Serine N[C@@]([H])(CO)C(=O) Ser S
Threonine N[C@@]([H])([C@]([H])(O)C)C(=O) Thr T
Tryptophan N[C@@]([H])(CC(=CN2)C1=C2C=CC=C1)C(=O) Trp W
Tyrosine N[C@@]([H])(Cc1ccc(O)cc1)C(=O) Tyr Y
Valine N[C@@]([H])(C(C)C)C(=O) Val V
Valine N[C@@]([H])(C(C)C)C(=O) Val V
Arginine C(C[C@@H](C(=O)O)N)CN=C(N)N Arg R
Asparagine C([C@@H](C(=O)O)N)C(=O)N Asn N
Aspartate C([C@@H](C(=O)O)N)C(=O)O Asp D
Cysteine C([C@@H](C(=O)O)N)S Cys C
Glutamine C(CC(=O)N)[C@@H](C(=O)O)N Gln Q
Glutamate C(CC(=O)O)[C@@H](C(=O)O)N Glu E
Histidine C1=C(NC=N1)C[C@@H](C(=O)O)N His H
Isoleucine CC[C@H](C)[C@@H](C(=O)O)N Ile I
Leucine CC(C)C[C@@H](C(=O)O)N Leu L
Lysine C(CCN)C[C@@H](C(=O)O)N Lys K
Methionine CSCC[C@@H](C(=O)O)N Met M
Phenylalanine C1=CC=C(C=C1)C[C@@H](C(=O)O)N Phe F
Proline C1C[C@H](NC1)C(=O)O Pro P
Serine C([C@@H](C(=O)O)N)O Ser S
Threonine C[C@H]([C@@H](C(=O)O)N)O Thr T
Tryptophan C1=CC=C2C(=C1)C(=CN2)C[C@@H](C(=O)O)N Trp W
Tyrosine C1=CC(=CC=C1C[C@@H](C(=O)O)N)O Tyr Y
Valine CC(C)[C@@H](C(=O)O)N Val V
Alanine CC(C(=O)O)N Ala A
Arginine C(CC(C(=O)O)N)CN=C(N)N Arg R
Asparagine C(C(C(=O)O)N)C(=O)N Asn N
Aspartate C(C(C(=O)O)N)C(=O)O Asp D
Cysteine C(C(C(=O)O)N)S Cys C
Glutamine C(CC(=O)N)C(C(=O)O)N Gln Q
Glutamate C(CC(=O)O)C(C(=O)O)N Glu E
Histidine C1=C(NC=N1)CC(C(=O)O)N His H
Isoleucine CCC(C)C(C(=O)O)N Ile I
Leucine CC(C)CC(C(=O)O)N Leu L
Lysine C(CCN)CC(C(=O)O)N Lys K
Methionine CSCCC(C(=O)O)N Met M
Phenylalanine C1=CC=C(C=C1)CC(C(=O)O)N Phe F
Proline C1CC(NC1)C(=O)O Pro P
Serine C(C(C(=O)O)N)O Ser S
Threonine CC(C(C(=O)O)N)O Thr T
Tryptophan C1=CC=C2C(=C1)C(=CN2)CC(C(=O)O)N Trp W
Tyrosine C1=CC(=CC=C1CC(C(=O)O)N)O Tyr Y
Valine CC(C)C(C(=O)O)N Val V
6 changes: 6 additions & 0 deletions resources/smiles.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
smiles
N[C@@]([H])(CCCNC(=N)N)C(=O)N[C@@]([H])([C@]([H])(O)C)C(=O)N[C@@]([H])(CCCCN)C(=O)N[C@@]([H])(CCCNC(=N)N)C(=O)O
N[C@@]([H])(CCCNC(=N)N)C(=O)N[C@@]([H])([C@]([H])(O)C)C(=O)N[C@@]([H])(CCCCN)C(=O)N[C@@]([H])(CCCNC(=N)N)C(=O)O
N[C@@]([H])(CCCNC(=N)N)C(=O)N[C@@]([H])([C@]([H])(O)C)C(=O)N[C@@]([H])(CCCCN)C(=O)N[C@@]([H])(CCCNC(=N)N)C(=O)O
N[C@@]([H])(CCCNC(=N)N)C(=O)N[C@@]([H])([C@]([H])(O)C)C(=O)N[C@@]([H])(CCCCN)C(=O)N[C@@]([H])(CCCNC(=N)N)C(=O)O
N[C@@]([H])(CCCNC(=N)N)C(=O)N[C@@]([H])([C@]([H])(O)C)C(=O)N[C@@]([H])(CCCCN)C(=O)N[C@@]([H])(CCCNC(=N)N)C(=O)O

0 comments on commit 0c3a9c5

Please sign in to comment.