# Visualizing Proteomics Data

Read in data

```
ms=pd.read_csv("C:\\Users\duan\Desktop\IntroductionToSeaborn\mass_spec_new.csv")
```

```
ms
```

<figure><img src="https://498238201-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWuHhstIreJ3jFvE4gQ3y%2Fuploads%2FjuqYTw50UhUGV9bZ3uhg%2Fimage.png?alt=media&#x26;token=5391e4c0-d873-4c31-ab88-b7ef70e3d017" alt=""><figcaption></figcaption></figure>

```
a = sns.histplot(ms['light Precursor Mz'], bins=20) #simple, right?
```

<figure><img src="https://498238201-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWuHhstIreJ3jFvE4gQ3y%2Fuploads%2Fj1lFscSmS02Y9Yj1Ziot%2Fimage.png?alt=media&#x26;token=990c06d3-4a89-4b2c-bcc8-87fedf48d7df" alt=""><figcaption></figcaption></figure>

```
a = sns.histplot(data=ms,x='light Precursor Mz', bins=20, kde="TRUE",color="lightseagreen",alpha=0.1)#make the plot more elegant
```

<figure><img src="https://498238201-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWuHhstIreJ3jFvE4gQ3y%2Fuploads%2FdfCe9a12bp54UvyYU9Qz%2Fimage.png?alt=media&#x26;token=73593c17-35a5-4e31-b371-8adabd505d78" alt=""><figcaption></figcaption></figure>

```
a = sns.histplot(data=ms,x='light +1 charge mass', bins=20, kde="TRUE",color="red",alpha=0.1)  #O no, what could be wrong?
```

<figure><img src="https://498238201-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWuHhstIreJ3jFvE4gQ3y%2Fuploads%2FgB9dKgA3UC1xH2EQhdYw%2Fimage.png?alt=media&#x26;token=8e5e23c4-a929-4262-902b-25ca965d48bb" alt=""><figcaption></figcaption></figure>

```
v = ms['light +1 charge mass'].values #get all of the values
v.sort() #sort the values
v #print the values - what's wrong?
```

![](https://498238201-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWuHhstIreJ3jFvE4gQ3y%2Fuploads%2FcHPlP9l38Px8Hemc3Qqx%2Fimage.png?alt=media\&token=6e45d8a0-a3c0-4fd4-bc13-6fa974877977) ![](https://498238201-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWuHhstIreJ3jFvE4gQ3y%2Fuploads%2FZ0MTFrXW6xioNtaRuaqm%2Fimage.png?alt=media\&token=7a547f03-3de4-4763-8e62-bf98b43b479a)

```
ms['light +1 charge mass']=ms['light Precursor Mz']*ms['Precursor Charge'] - ((ms['Precursor Charge']-1)*1.0078)
```

```
a = sns.histplot(data=ms,x='light +1 charge mass', bins=20, kde="TRUE",color="red",alpha=0.1)
```

<figure><img src="https://498238201-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWuHhstIreJ3jFvE4gQ3y%2Fuploads%2FkdMvUsyDK9izA1wYwHY7%2Fimage.png?alt=media&#x26;token=fc1b0e82-37a6-4f07-9fea-37dd48d74383" alt=""><figcaption></figcaption></figure>

```
#Let's see if +2 and +3 charged peptides exhibit a different distribution.
a = sns.histplot(data=ms.loc[ms['Precursor Charge'] == 3], x='light +1 charge mass', bins=10, label='+3',kde="TRUE",color="chocolate",alpha=0.2)
sns.histplot(data=ms.loc[ms['Precursor Charge'] == 2], x='light +1 charge mass', bins=10, ax=a, label='+2',kde="TRUE",color="orchid",alpha=0.1)
a.legend()
```

<figure><img src="https://498238201-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWuHhstIreJ3jFvE4gQ3y%2Fuploads%2FE8EYTpHNDxTGlNmYlX6E%2Fimage.png?alt=media&#x26;token=3f2e3fac-64de-429a-a566-7c9e2e64cbd6" alt=""><figcaption></figcaption></figure>

```
#Here, I made a new column that is the ratio of light-to-heavy intensity...the details aren't important. What is important is that we have a new column of values we can plot
ms['Total Area Ratio BT2_HFX_5'] = ms['light BT2_HFX_5 Total Area']/ms['15N BT2_HFX_5 Total Area']
ms['Total Area Ratio BT2_HFX_7'] = ms['light BT2_HFX_7 Total Area']/ms['15N BT2_HFX_7 Total Area']
```

```
sns.set_context('poster') #you don't need to do this - it's just to make the figures easier to see
f = pylab.figure(figsize=(20,10))
swarm = sns.swarmplot(x='Protein Gene', y='Total Area Ratio BT2_HFX_5', data=ms.loc[0:100,:], size=6)
pylab.tight_layout()
pylab.savefig('swarmplot.png')
```

<figure><img src="https://498238201-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWuHhstIreJ3jFvE4gQ3y%2Fuploads%2FlZaNAplsFKR89HUnAKCf%2Fimage.png?alt=media&#x26;token=5f0517f1-aca2-444d-a5b7-6de11d0db90f" alt=""><figcaption></figcaption></figure>

```
sns.set_context('poster') #you don't need to do this - it's just to make the figures easier to see
f = pylab.figure(figsize=(20,10))
box = sns.boxplot(x='Protein Gene', y='Total Area Ratio BT2_HFX_5', data=ms.loc[0:100,:])
pylab.tight_layout()
pylab.savefig('boxplot.pdf') #this will save your figure!
```

<figure><img src="https://498238201-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWuHhstIreJ3jFvE4gQ3y%2Fuploads%2Fr2Kk5nSCd2kOBVvmotUh%2Fimage.png?alt=media&#x26;token=d8b580a0-bc37-425e-8f3b-9a2d241e5e62" alt=""><figcaption></figcaption></figure>

```
sns.set_context('poster') #you don't need to do this - it's just to make the figures easier to see
f = pylab.figure(figsize=(20,10))
box = sns.violinplot(x='Protein Gene', y='Total Area Ratio BT2_HFX_5', data=ms.loc[0:30,:])
#pylab.tight_layout()
pylab.savefig('boxplot.pdf') #this will save your figure!
```

<figure><img src="https://498238201-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWuHhstIreJ3jFvE4gQ3y%2Fuploads%2FrbihBW6ce17ybQ45pXlB%2Fimage.png?alt=media&#x26;token=4f82826c-e5c8-4de9-94d0-8660093d6b0a" alt=""><figcaption></figcaption></figure>
