Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SSN
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
bioc
SSN
Commits
98a05c21
Commit
98a05c21
authored
3 months ago
by
Totaro Massimo G
Browse files
Options
Downloads
Patches
Plain Diff
fix: output file names
parent
4b4161b5
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
ssn.ipynb
+29
-29
29 additions, 29 deletions
ssn.ipynb
with
29 additions
and
29 deletions
ssn.ipynb
+
29
−
29
View file @
98a05c21
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "AkmFcUlSqjvW"
},
"source": [
"# SSN analysis\n",
"\n",
...
...
@@ -27,13 +16,16 @@
"\n",
"Alternatively, a BLAST-preanalysed database can be provided.\n",
"Just hit cancel on the first FASTA upload prompt and then provide the TSV file."
],
"metadata": {
"id": "AkmFcUlSqjvW"
}
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"cellView": "form",
"id": "ad3vrSFIVZNl"
},
"outputs": [],
"source": [
"#@title Click below to run\n",
"\n",
...
...
@@ -69,8 +61,8 @@
" print('No file provided')\n",
"\n",
"if isfile(fileTsv):\n",
" fileBOut = '
ev
s.csv'\n",
" fileEOut = '
b
ts.csv'\n",
" fileBOut = '
bt
s.csv'\n",
" fileEOut = '
e
ts.csv'\n",
" fileZip = NamedTemporaryFile(suffix='.zip').name\n",
"\n",
" try:\n",
...
...
@@ -119,13 +111,21 @@
" files.download(fileZip)\n",
" except:\n",
" print('Invalid file format')"
]
}
],
"metadata": {
"
id": "ad3vrSFIVZNl",
"cellView": "form"
"
colab": {
"provenance": []
},
"execution_count": null,
"outputs": []
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
},
"language_info": {
"name": "python"
}
]
},
"nbformat": 4,
"nbformat_minor": 0
}
%% Cell type:markdown id: tags:
# SSN analysis
This is an automated script to generate a Sequence Similarity Network starting from a curated sequence alignment.
To run the analysis, click on the button in the cell below.
You will be prompted to upload a FASTA file containing the curated sequence alignment.
Alternatively, a BLAST-preanalysed database can be provided.
Just hit cancel on the first FASTA upload prompt and then provide the TSV file.
%% Cell type:code id: tags:
```
#@title Click below to run
import numpy
from google.colab import files
from pandas import read_csv
from zipfile import ZipFile
from os.path import isfile
from tempfile import NamedTemporaryFile
fileFasta = NamedTemporaryFile(suffix='.fasta').name
fileTsv = NamedTemporaryFile(suffix='.tsv').name
try:
print('Upload FASTA file to be analysed')
files.upload_file(fileFasta)
print('Analysing FASTA file...')
!apt-get install ncbi-blast+ > /dev/null && \
makeblastdb -in {fileFasta} -dbtype prot -parse_seqids -out 'DB' > /dev/null && \
blastp -db 'DB' -query {fileFasta} -out {fileTsv} -outfmt "6 qseqid sseqid evalue bitscore"
if not isfile(fileTsv):
print('The provided FASTA file could not be processed')
raise ValueError
except ValueError:
try:
print('Upload TSV file to be analysed')
files.upload_file(fileTsv)
except ValueError:
print('No file provided')
if isfile(fileTsv):
fileBOut = '
ev
s.csv'
fileEOut = '
b
ts.csv'
fileBOut = '
bt
s.csv'
fileEOut = '
e
ts.csv'
fileZip = NamedTemporaryFile(suffix='.zip').name
try:
df = read_csv(fileTsv,
sep='\t',
header=None,
index_col=[0, 1],
names=['T', 'S', 'e', 'b'],
dtype={'e':numpy.float64,
'b':numpy.float64})
e = df.pivot_table(index='T',
columns='S',
values='e',
aggfunc='min')
((numpy.minimum(e, e.T) + numpy.tril(numpy.full(e.shape, numpy.nan)))
.unstack()
.to_frame()
.sort_index(level=1)
.dropna()
.reset_index()
.to_csv(fileEOut,
sep=';',
index=False,
header=['Source','Target','evalue']))
b = df.pivot_table(index='T',
columns='S',
values='b',
aggfunc='max')
((numpy.maximum(b, b.T) + numpy.tril(numpy.full(b.shape, numpy.nan)))
.unstack()
.to_frame()
.sort_index(level=1)
.dropna()
.reset_index()
.to_csv(fileBOut,
sep=';',
index=False,
header=['Source','Target','bitscore']))
with ZipFile(fileZip, 'w') as f:
f.write(fileBOut)
f.write(fileEOut)
files.download(fileZip)
except:
print('Invalid file format')
```
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment