Skip to content

Instantly share code, notes, and snippets.

View elowy01's full-sized avatar

Ernesto Lowy elowy01

  • Biofidelity
  • Cambridge, UK
View GitHub Profile
#Multi-Label classification
Typically, a classification task involves predicting a single label. Alternately,
it might involve predicting the likelihood across two or more class labels.
In these cases, the classes are mutually exclusive, meaning the classification
task assumes that the input belongs to one class only.
Some classification tasks require predicting more than one class label.
This means that class labels or class membership are not mutually exclusive.
These tasks are referred to as multiple label classification, or multi-label classification for short.
from Bio.Seq import Seq
from Bio.SeqRecord import SeqRecord
record = SeqRecord(
Seq("MKQHKAMIVALIVICITAVVAALVTRKDLCEVHIRTGQTEVAVF"),
id="YP_025292.1",
name="HokC",
description="toxic membrane protein, small",
)
print(record)
# square of all elements in a vector
sapply(1:10, function(i) i ^ 2)
df <- data.frame(
x=rnorm(25),
y=rnorm(25),
g=rep(factor(LETTERS[1:5]), 5)
)
X <- split(df, df$g)
# Simple plot example for geom_point
data(iris)
# where we specify the type of plot with geom_point()
# the data to plot with aes
IrisPlot <- ggplot(iris, aes(Sepal.Length, Petal.Length, colour=Species))+geom_point()
# if we want to change the colour
IrisPlot <- ggplot(iris, aes(Sepal.Length, Petal.Length))+geom_point(colour="blue")
print(IrisPlot)
# Now, let's modify the axes labels and also add title
print(IrisPlot + labs(y="Petal length (cm)", x = "Sepal length (cm)")) + ggtitle("Petal and sepal length of iris")
# Bins numerical data and returns the different counts for each category
mport numpy as np
a = np.array([22,87,5,43,56,73,55,54,11,20,51,5,79,31,27])
hist,bins = np.histogram(a,bins = [0,20,40,60,80,100])
print(hist) # [3 4 5 2 1]
print(bins) # [ 0 20 40 60 80 100]
# Excellent for plotting small and really large data points
Good article at:
https://towardsdev.com/logarithmic-scale-how-to-plot-and-actually-understand-it-c38f00212206
############### Method 1:
# Python3 code to demonstrate
# to remove a substring from end of the string
# Initialising string
ini_string = 'xbzefdgstb'
# initializing string
sstring = 'stb'
import os
import tempfile
temp = tempfile.NamedTemporaryFile()
try:
print 'temp:', temp
print 'temp.name:', temp.name
finally:
# Automatically cleans up the file
temp.close()
# global alignment between 2 sequences
from Bio import pairwise2
alignments = pairwise2.align.globalxx("ACCGT", "ACG") # returns a list of alignments
# you can format the alignments
from Bio.pairwise2 import format_alignment
print(format_alignment(*alignments[0]))
ACCGT
| ||
A-CG-