GSEAPY is a python wrapper for GSEA and Enrichr.
GSEAPY has five subcommands: gsea, prerank, ssgsea, replot enrichr.
Solve Problems by Coding Solutions - A Complete solution for python programming
PyTorch - From Research To Production
An open source deep learning platform that provides a seamless path from research prototyping to production deployment. PyTorch enables fast, flexible experimentation and efficient production
through a hybrid front-end, distributed training, and ecosystem of tools
and libraries.
Website
Top 5 Python Web Frameworks
1)
Django
Django is a high-level Python Web framework that
encourages rapid development and clean, pragmatic design.
Ridiculously fast + Reassuringly secure +
Exceedingly scalable
2)
TurboGears
TurboGears 2 is a reinvention of the TurboGears
project to take advantage of new components, and to provide a fully
customizable WSGI (Web Server Gateway Interface) stack.
3)Web2Py
Free open source full-stack framework for rapid
development of fast, scalable, secure and portable database-driven web-based
applications. Written and programmable in Python
4)
Flask
Flask is a Python framework available under the BSD
license. It was inspired by the Sinatra Ruby framework. Flask depends on the
Werkzeug WSGI toolkit and Jinja2template.
5)Bottle
Bottle is a microframework. Originally meant for
building APIs, Bottle implements everything in a single source file. It has no
dependencies apart from the Python Standard Library. Coding with Bottle gets
you closer to the metal than coding with any full-stack framework.
Snake game using python program
#To install pygame package "pip install
pygame" in python Terminal
import pygame, random, sys
from pygame.locals import *
def collide(x1, x2, y1, y2, w1, w2, h1, h2):
if x1+w1>x2 and x1<x2+w2 and y1+h1>y2 and y1<y2+h2:return True
else:return False
def die(screen, score):
f=pygame.font.SysFont('Arial', 30);t=f.render('Your score was: '+str(score), True, (0, 0, 0));screen.blit(t, (10, 270));pygame.display.update();pygame.time.wait(2000);sys.exit(0)
xs = [290, 290, 290, 290, 290];ys = [290, 270, 250, 230, 210];dirs = 0;score = 0;applepos = (random.randint(0, 590), random.randint(0, 590));pygame.init();s=pygame.display.set_mode((600, 600));pygame.display.set_caption('Snake');appleimage = pygame.Surface((20, 20));appleimage.fill((0, 0, 255));img = pygame.Surface((20, 20));img.fill((255, 0, 0));f = pygame.font.SysFont('Arial', 20);clock = pygame.time.Clock()
while True:
clock.tick(10)
for e in pygame.event.get():
if e.type == QUIT:
sys.exit(0)
elif e.type == KEYDOWN:
if e.key == K_UP and dirs != 0:dirs = 2
elif e.key == K_DOWN and dirs != 2:dirs = 0
elif e.key == K_LEFT and dirs != 1:dirs = 3
elif e.key == K_RIGHT and dirs != 3:dirs = 1
i = len(xs)-1
while i >= 2:
if collide(xs[0], xs[i], ys[0], ys[i], 20, 20, 20, 20):die(s, score)
i-= 1
if collide(xs[0], applepos[0], ys[0], applepos[1], 20, 10, 20, 10):score+=1;xs.append(700);ys.append(700);applepos=(random.randint(0,590),random.randint(0,590))
if xs[0] < 0 or xs[0] > 580 or ys[0] < 0 or ys[0] > 580: die(s, score)
i = len(xs)-1
while i >= 1:
xs[i] = xs[i-1];ys[i] = ys[i-1];i -= 1
if dirs==0:ys[0] += 20
elif dirs==1:xs[0] += 20
elif dirs==2:ys[0] -= 20
elif dirs==3:xs[0] -= 20
s.fill((255, 255, 255))
for i in range(0, len(xs)):
s.blit(img, (xs[i], ys[i]))
s.blit(appleimage, applepos);t=f.render(str(score), True, (0, 0, 0));s.blit(t, (10, 10));pygame.display.update()
import pygame, random, sys
from pygame.locals import *
def collide(x1, x2, y1, y2, w1, w2, h1, h2):
if x1+w1>x2 and x1<x2+w2 and y1+h1>y2 and y1<y2+h2:return True
else:return False
def die(screen, score):
f=pygame.font.SysFont('Arial', 30);t=f.render('Your score was: '+str(score), True, (0, 0, 0));screen.blit(t, (10, 270));pygame.display.update();pygame.time.wait(2000);sys.exit(0)
xs = [290, 290, 290, 290, 290];ys = [290, 270, 250, 230, 210];dirs = 0;score = 0;applepos = (random.randint(0, 590), random.randint(0, 590));pygame.init();s=pygame.display.set_mode((600, 600));pygame.display.set_caption('Snake');appleimage = pygame.Surface((20, 20));appleimage.fill((0, 0, 255));img = pygame.Surface((20, 20));img.fill((255, 0, 0));f = pygame.font.SysFont('Arial', 20);clock = pygame.time.Clock()
while True:
clock.tick(10)
for e in pygame.event.get():
if e.type == QUIT:
sys.exit(0)
elif e.type == KEYDOWN:
if e.key == K_UP and dirs != 0:dirs = 2
elif e.key == K_DOWN and dirs != 2:dirs = 0
elif e.key == K_LEFT and dirs != 1:dirs = 3
elif e.key == K_RIGHT and dirs != 3:dirs = 1
i = len(xs)-1
while i >= 2:
if collide(xs[0], xs[i], ys[0], ys[i], 20, 20, 20, 20):die(s, score)
i-= 1
if collide(xs[0], applepos[0], ys[0], applepos[1], 20, 10, 20, 10):score+=1;xs.append(700);ys.append(700);applepos=(random.randint(0,590),random.randint(0,590))
if xs[0] < 0 or xs[0] > 580 or ys[0] < 0 or ys[0] > 580: die(s, score)
i = len(xs)-1
while i >= 1:
xs[i] = xs[i-1];ys[i] = ys[i-1];i -= 1
if dirs==0:ys[0] += 20
elif dirs==1:xs[0] += 20
elif dirs==2:ys[0] -= 20
elif dirs==3:xs[0] -= 20
s.fill((255, 255, 255))
for i in range(0, len(xs)):
s.blit(img, (xs[i], ys[i]))
s.blit(appleimage, applepos);t=f.render(str(score), True, (0, 0, 0));s.blit(t, (10, 10));pygame.display.update()
Top 6 NLP Python Library
NLTK
- It is a leading platform for building Python programs to work with human
language data. It provides easy-to-use interfaces to over 50 corpora and
lexical resources such as WordNet, along with a suite of text processing
libraries for classification, tokenization, stemming, tagging, parsing, and
semantic reasoning, wrappers for industrial-strength NLP libraries, and an
active discussion forum.
TextBlob
- It is a Python (2 and 3) library for processing textual data. It provides a
simple API for diving into common natural language processing (NLP) tasks such
as part-of-speech tagging, noun phrase extraction, sentiment analysis,
classification, translation, and more.
Stanford
CoreNLP - It provides a set of human
language technology tools. It can give the base forms of words, their parts of
speech, whether they are names of companies, people, etc., normalize dates,
times, and numeric quantities, mark up the structure of sentences in terms of
phrases and syntactic dependencies, indicate which noun phrases refer to the
same entities, indicate sentiment, extract particular or open-class relations
between entity mentions
spaCy – The spaCy excels at
large-scale information extraction tasks. It's written from the ground up in
carefully memory-managed Cython. spaCy is the best way to prepare text for deep
learning. It interoperates seamlessly with TensorFlow, PyTorch, scikit-learn,
Gensim and the rest of Python's awesome AI ecosystem.
Gensim started off as a collection of Scalable statistical semantics and can
analyze plain-text documents for semantic structure, retrieve semantically similar
documents
Polyglot
is a natural language pipeline that supports massive multilingual applications.
Python program to find day of birth
import datetime
y = input("Enter year of Birth: ");
m = input("Enter month of Birth: ");
d = input("Enter date of Birth: ");
mydate = datetime.date(int(y),int(m),int(d))
print(mydate.strftime("%A"))
y = input("Enter year of Birth: ");
m = input("Enter month of Birth: ");
d = input("Enter date of Birth: ");
mydate = datetime.date(int(y),int(m),int(d))
print(mydate.strftime("%A"))
Python program to shutdown and restart computer
import os;
check = input("Want to shutdown your computer ? (y/n): ");
if check == 'n':
check = input("Want to restart your computer ? (y/n): ");
if check == 'y':
os.system("shutdown /r /t 1");
else:
exit();
else:
os.system("shutdown /s /t 1");
check = input("Want to shutdown your computer ? (y/n): ");
if check == 'n':
check = input("Want to restart your computer ? (y/n): ");
if check == 'y':
os.system("shutdown /r /t 1");
else:
exit();
else:
os.system("shutdown /s /t 1");
Python program for reading an excel file
import xlrd
loc=("your own excel path with double slash at drive name like C:\\")
wb = xlrd.open_workbook(loc)
sheet = wb.sheet_by_index(0)
print ("The value of Row 0 and Column 0 is", sheet.cell_value(0, 0))
print("No of Rows in the current sheet is",sheet.nrows)
print("No of Columns in the current sheet is",sheet.ncols)
print("Extracting all columns name in the current sheet")
for i in range(sheet.ncols):
print(sheet.cell_value(0, i))
print("Extracting first column in the current sheet")
for i in range(sheet.nrows):
print(sheet.cell_value(i, 0))
print("Extracting rowwise content in the current sheet")
for i in range(sheet.nrows):
print(sheet.row_values(i))
loc=("your own excel path with double slash at drive name like C:\\")
wb = xlrd.open_workbook(loc)
sheet = wb.sheet_by_index(0)
print ("The value of Row 0 and Column 0 is", sheet.cell_value(0, 0))
print("No of Rows in the current sheet is",sheet.nrows)
print("No of Columns in the current sheet is",sheet.ncols)
print("Extracting all columns name in the current sheet")
for i in range(sheet.ncols):
print(sheet.cell_value(0, i))
print("Extracting first column in the current sheet")
for i in range(sheet.nrows):
print(sheet.cell_value(i, 0))
print("Extracting rowwise content in the current sheet")
for i in range(sheet.nrows):
print(sheet.row_values(i))
Python programt for finding ports opened in the website domain
import socket;
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result = sock.connect_ex(('www.example.com', port number))
if result == 0:
print ("Port is open")
else:
print ("Port is not open")
Python program to print date and time
import datetime;
print("Today Date & Time:\n");
print(datetime.datetime.today());
print("Today Date & Time:\n");
print(datetime.datetime.today());
Python program to print Hostname, IP, MAC address
import uuid
import socket
hostname = socket.gethostname()
IPAddr = socket.gethostbyname(hostname)
print("The Name of this device is: " + hostname)
print("The IP Address of this device is: " + IPAddr)
print ("The MAC address of this device is:",hex(uuid.getnode()))
import socket
hostname = socket.gethostname()
IPAddr = socket.gethostbyname(hostname)
print("The Name of this device is: " + hostname)
print("The IP Address of this device is: " + IPAddr)
print ("The MAC address of this device is:",hex(uuid.getnode()))
Python programto find Sine and Cosine Values plot using Matplotlib
import numpy as np
import matplotlib.pyplot as plt
x=np.linspace(0,1)
data1 = np.sin(x)
data2 = np.cos(x)
fig, ax1 = plt.subplots()
color = 'tab:red'
ax1.set_xlabel('x')
ax1.set_ylabel('sine', color=color)
ax1.plot(x, data1, color=color)
ax1.tick_params(axis='y', labelcolor=color)
ax2 = ax1.twinx()
color = 'tab:green'
ax2.set_ylabel('cosine', color=color)
ax2.plot(x, data2, color=color)
ax2.tick_params(axis='y', labelcolor=color)
plt.show()
#Simple Implementation
#---------------------------------------------------------------------
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-np.pi, np.pi, 256, endpoint=True)
c= np.cos(x)
s= np.sin(x)
plt.plot(x,c)
plt.plot(x,s)
plt.show()
import matplotlib.pyplot as plt
x=np.linspace(0,1)
data1 = np.sin(x)
data2 = np.cos(x)
fig, ax1 = plt.subplots()
color = 'tab:red'
ax1.set_xlabel('x')
ax1.set_ylabel('sine', color=color)
ax1.plot(x, data1, color=color)
ax1.tick_params(axis='y', labelcolor=color)
ax2 = ax1.twinx()
color = 'tab:green'
ax2.set_ylabel('cosine', color=color)
ax2.plot(x, data2, color=color)
ax2.tick_params(axis='y', labelcolor=color)
plt.show()
#Simple Implementation
#---------------------------------------------------------------------
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(-np.pi, np.pi, 256, endpoint=True)
c= np.cos(x)
s= np.sin(x)
plt.plot(x,c)
plt.plot(x,s)
plt.show()
Solving linear mathematical equations with two variable
import numpy as np
A=np.array([[1.5,1],[3.75,4]])
B=np.array([1800,900])
x=np.linalg.solve(A,B)
print("Values of A and B variables:",x)
h=np.allclose(np.dot(A, x), B)
print("Substitution of two variables in equation to validate:",h)
A=np.array([[1.5,1],[3.75,4]])
B=np.array([1800,900])
x=np.linalg.solve(A,B)
print("Values of A and B variables:",x)
h=np.allclose(np.dot(A, x), B)
print("Substitution of two variables in equation to validate:",h)
Operations on Matrices using Python program
import numpy as np
A = np.array([[4,1,7],[2,1,8],[3 ,7,1]])
B = np.array([[6,1,1],[2,1,5],[2,3,1]])
C=A.dot(B)
print("Values of First 2D Matrix\n",A)
print("Values of Second 2D Matrix\n",B)
print("---------------------------------------------")
print("Multiplication of Matrices\n",C)
print("\n")
Ainv=np.linalg.inv(A)
Binv=np.linalg.inv(B)
print("Inverse of First Matrix\n",Ainv)
print("Inverse of Second Matrix\n",Binv)
print("\n")
AI=Ainv.dot(A)
BI=Binv.dot(B)
print("Multiplication of First Matrix and their Inverse\n",AI)
print("Multiplication of Second Matrix and their Inverse\n",BI)
AD=np.linalg.det(A)
BD=np.linalg.det(B)
print("\n")
print("Determinant of First Matricx:",AD)
print("Determinant of Second Matricx:",BD)
print("\n")
ADi=np.diag(A)
BDi=np.diag(B)
print("Diagonal Elements of First Matrix:",ADi)
print("Diagonal Elements of Second Matrix:",BDi)
SADi=np.trace(A)
SBDi=np.trace(B)
print("\n")
print("Sum of Diagonal Elements of First Matrix:",SADi)
print("Sum of Diagonal Elements of Second Matrix:",SBDi)
print("\n")
CA=np.cov(A)
CB=np.cov(B)
print("Covariance matrix of First Matrix\n",CA)
print("Covariance matrix of Second Matrix\n",CB)
print("\n")
ECA=np.linalg.eigh(CA)
ECB=np.linalg.eigh(CB)
print("First array represents eigenvalues and second array represents eigenvectors")
print("\n")
print("covariance matrix eigenvalues eigenvectors of First Matrix\n",ECA)
print("\n")
print("covariance matrix eigenvalues eigenvectors of Second Matrix\n",ECB)
A = np.array([[4,1,7],[2,1,8],[3 ,7,1]])
B = np.array([[6,1,1],[2,1,5],[2,3,1]])
C=A.dot(B)
print("Values of First 2D Matrix\n",A)
print("Values of Second 2D Matrix\n",B)
print("---------------------------------------------")
print("Multiplication of Matrices\n",C)
print("\n")
Ainv=np.linalg.inv(A)
Binv=np.linalg.inv(B)
print("Inverse of First Matrix\n",Ainv)
print("Inverse of Second Matrix\n",Binv)
print("\n")
AI=Ainv.dot(A)
BI=Binv.dot(B)
print("Multiplication of First Matrix and their Inverse\n",AI)
print("Multiplication of Second Matrix and their Inverse\n",BI)
AD=np.linalg.det(A)
BD=np.linalg.det(B)
print("\n")
print("Determinant of First Matricx:",AD)
print("Determinant of Second Matricx:",BD)
print("\n")
ADi=np.diag(A)
BDi=np.diag(B)
print("Diagonal Elements of First Matrix:",ADi)
print("Diagonal Elements of Second Matrix:",BDi)
SADi=np.trace(A)
SBDi=np.trace(B)
print("\n")
print("Sum of Diagonal Elements of First Matrix:",SADi)
print("Sum of Diagonal Elements of Second Matrix:",SBDi)
print("\n")
CA=np.cov(A)
CB=np.cov(B)
print("Covariance matrix of First Matrix\n",CA)
print("Covariance matrix of Second Matrix\n",CB)
print("\n")
ECA=np.linalg.eigh(CA)
ECB=np.linalg.eigh(CB)
print("First array represents eigenvalues and second array represents eigenvectors")
print("\n")
print("covariance matrix eigenvalues eigenvectors of First Matrix\n",ECA)
print("\n")
print("covariance matrix eigenvalues eigenvectors of Second Matrix\n",ECB)
Subscribe to:
Posts (Atom)