工作笔记

工作笔记

(一) Linux

1 查看sudoer用户

首先需要有sudoer用户权限,然后执行命令
sudo cat /etc/sudoer

2 查看目录文件大小

  • 查看当前一级目录文件大小
    du -h --max-depth=1
  • 查看当前目录所有文件大小
    du -sh
    du -k --max-depth=1 (以kb为单位显示)

3 设置vim行号

set_vimrc

(二) python用法

1. list合并去重

  • list1.append(list2) list2 all elements as a element in new list
  • list1.extent(list2) every element of list2 as a element in new list, include duplication elements
  • list1 += list2 every element of list2 as a element in new list, include duplication elements
  • new_list = list(set(list1) delete duplication elements in list1

(三) matplotlib.pyplot学习

  • plt.axvline(0.0, color='k') 在坐标轴上加一条竖直的线,0.0为竖直线在坐标轴上的位置
  • plt.axhline(y=0.5, ls='dotted', color='k') 加水线通过坐标轴

1. 拟合曲线

1.1 多项式拟合
import matplotlib.pyplot as plt
import numpy as np

x = np.arange(1, 17, 1)
y = np.array([4.00, 6.40, 8.00, 8.80, 9.22, 9.50, 9.70, 9.86, 10.00, 10.20, 10.32, 10.42, 10.50, 10.55, 10.58, 10.60])
z1 = np.polyfit(x, y, 3) # 用3次多项式拟合
p1 = np.poly1d(z1)
print(p1) # 在屏幕上打印拟合多项式
yvals=p1(x) # 也可以使用yvals=np.polyval(z1,x)
plot1=plt.plot(x, y, '*',label='original values')
plot2=plt.plot(x, yvals, 'r',label='polyfit values')
plt.xlabel('x axis')
plt.ylabel('y axis')
plt.legend(loc=4) # 指定legend的位置,读者可以自己help它的用法
plt.title('polyfitting')
plt.show()
plt.savefig('p1.png')
1.2 指定函数拟合
# 使用非线性最小二乘法拟合
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
import numpy as np
# 用指数形式来拟合
x = np.arange(1, 17, 1)
y = np.array([4.00, 6.40, 8.00, 8.80, 9.22, 9.50, 9.70, 9.86, 10.00, 10.20, 10.32, 10.42, 10.50, 10.55, 10.58, 10.60])
def func(x,a,b):
    return a*np.exp(b/x)
popt, pcov = curve_fit(func, x, y)
a=popt[0] # popt里面是拟合系数,读者可以自己help其用法
b=popt[1]
yvals=func(x,a,b)
plot1=plt.plot(x, y, '*',label='original values')
plot2=plt.plot(x, yvals, 'r',label='curve_fit values')
plt.xlabel('x axis')
plt.ylabel('y axis')
plt.legend(loc=4) # 指定legend的位置,读者可以自己help它的用法
plt.title('curve_fit')
plt.show()
plt.savefig('p2.png')
1.3 画柱状图(特异性模型)
def plot_specificity(input1, sele_path):
    df1 = pd.read_csv(input1)
    df2 = pd.read_csv(sele_path)

    sele_list = df2.iloc[:, 0].tolist()
    sele_list_new = df2.iloc[:, -2].tolist()
    sele_list_modify = df2.iloc[:, -1].tolist()
    for i, j, jj in zip(sele_list, sele_list_new, sele_list_modify):
        # print(i, j)
        each_id = df1[df1['compound_ID'] == i]
        print(each_id.head())

        each_id.sort_values(by='SE', ascending=False, inplace=True)
        each_id.to_csv('./tmp/' + str(jj) + '_spe_pred.csv', index=False)
        print(each_id.head(), len(each_id))

        label = np.array(each_id.iloc[:50, 1])
        se = np.array(each_id.iloc[:50, -1])
        index = np.arange(len(se))
        # print(label, se)

        plt.figure(figsize=(18, 10))
        plt.subplots_adjust(left=0.05, bottom=0.25, right=0.98, top=0.93, hspace=0.2, wspace=0.3)
        # plt.xlabel("...", labelpad=20)

        plt.bar(index, se, alpha=0.9, width=0.4, label='specificity', lw=1)
        # plt.bar(index, se, alpha=0.9, width=0.4, facecolor='yellowgreen', label='specificity', lw=1)
        plt.title(j, fontproperties='Times New Roman', fontsize=20)
        plt.xticks(index, label, rotation=90, fontproperties='Times New Roman', fontsize=14)
        plt.yticks(fontproperties='Times New Roman', fontsize=15)
        plt.ylim(0, 0.45)
        plt.grid(ls=':', linewidth=0.3)
        # plt.show()
        plt.savefig('./tmp/' + str(jj) + '_spe.png', dpi=100)
        plt.clf()

简单实例

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值