![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Python
lengedd
这个作者很懒,什么都没留下…
展开
-
python读取excle内容是否在另一个excle中,并读取对应值
图1的pdbname包含在图二的description中,并输出表二对应的值另存为一个表格#coding=gbk# import pandas as pd## df = pd.read_excel('F:/1对接/chapter4/8w_双突变/total_B_8w.xlsx')# print(df[df['description']=='01_pos_remove_00B_01_00B_positioned_00884']['interface_delta_B'])# print(df[d..原创 2021-07-23 15:17:34 · 753 阅读 · 0 评论 -
python通过txt文件将指定文件复制到另一个文件夹
import shutilimport numpy as npdata = []for line in open("test5.txt", "r"): # 设置文件对象并读取每一行文件 data.append(line)# print(data)for a in data: srcfile_path = 'pdbname_list/{}'.format(a[:-1]) print(srcfile_path) tarfile_path = 'targt1'原创 2021-07-22 20:41:34 · 2024 阅读 · 0 评论 -
python读取文件名
#coding=gbkimport osdef readname(): filePath = 'F:\\1对接\\chapter4\\100pdb\\' name = os.listdir(filePath) return nameif __name__ == "__main__": name = readname() print(name) for i in name: print(i)转自:https://www.jb51转载 2021-07-22 16:08:42 · 2020 阅读 · 0 评论 -
python实现pdb转fasta
import sysif len(sys.argv) <= 1: print('python pdb2fasta.py desgin_3.txt > desgin_3.fasta') exit()input_file = open(sys.argv[1])letters = {'ALA': 'A', 'ARG': 'R', 'ASN': 'N', 'ASP': 'D', 'CYS': 'C', 'GLU': 'E', 'GLN': 'Q', 'GLY': 'G', '原创 2021-07-16 15:06:46 · 1794 阅读 · 0 评论 -
社区版pycharm如何创建django
指定自己需要存放的文件夹,创建项目名打开pycharm就可以看到自己创建的目录了原创 2021-07-10 10:59:53 · 244 阅读 · 0 评论 -
python爬虫报错requests.exceptions.MissingSchema: Invalid URL
把开头的#encoding=gbk改为utf-8原创 2021-07-09 13:40:37 · 6900 阅读 · 0 评论 -
python将fasta格式转为.csv
from Bio import SeqIOimport pandas as pdmeta = []sequence = []label = []i = 0seq = ('fasts.txt') # 转换的文件for seq_record in SeqIO.parse(seq, "fasta"): meta.append(str(seq_record.id)) sequence.append(str(seq_record.seq)) i = 1 + i lab原创 2021-07-06 10:33:33 · 572 阅读 · 0 评论 -
python绘制散点聚类图及标记序号
# coding=gbkimport pandas as pdimport matplotlib.pyplot as pltfrom sklearn.cluster import KMeans# data = pd.read_excel('lactose-lactuse-scatter.xlsx', engine='openpyxl')# #遍历所有数据# x = data.iloc[:]## #5个簇,1个自由点# mod = KMeans(n_clusters=5, random_s原创 2021-07-01 14:50:12 · 2001 阅读 · 0 评论 -
python绘制热图
# coding=gbkimport matplotlib.pyplot as pltimport pandas as pdimport seaborn as snsimport numpy as np#结果图编码从0开始,编号依次加一对应蛋白的编号,其中50为m7file_name = pd.read_excel('lactose-lactuse.xlsx',engine='openpyxl')data = file_name.pivot("lactose","lactulose","l原创 2021-07-01 14:49:34 · 11048 阅读 · 0 评论 -
python绘制直方图
用两列数据绘制直方图#coding=gbkimport xlwings as xwimport pandas as pdimport matplotlib.pyplot as plt#pd.set_option('display.max_columns', None) #解决表格多列时中间省略显示问题#pd.set_option('display.max_rows', None) #解决表格多行时中间省略显示问题#读取excel文件中的数据app = xw.App(visi原创 2021-07-01 14:48:52 · 17282 阅读 · 0 评论 -
python读取excle数据
file_name = pd.read_excel('lactose-lactuse.xlsx',engine='openpyxl')原创 2021-06-21 13:30:05 · 94 阅读 · 0 评论 -
Python实现 提取fasta中Homosapiens所在行标题和序列
file_r = open('SwissProt.fasta', 'r')file_w = open('SwissProtHomo.fasta', 'w')seq = ''for line in file_r: if line[0] == '>' and seq == '': header = line elif line[0] != '>': seq = seq+line elif line[0] == '>' and se原创 2021-04-24 10:49:36 · 595 阅读 · 0 评论 -
python实现 提取gbk文件的登记码和ORIGIN序列
file_r = open("sequence.gbk")file_w = open("sequence.fasta", "w")flag = 0for line in file_r: if line[0:9] == 'ACCESSION': #得到第一个空格和第二个空格之间的内容,[2]:得到第二个空格和第三个空格之间的内容 AC = line.split()[1].strip() # AC = line.split( )[1] file_w.writ原创 2021-04-23 16:49:00 · 417 阅读 · 0 评论 -
用python 实现从fasta文件中获取登记码
fasta_file = open('SwissProt.fasta', 'r')ac_list = []for line in fasta_file: if line[0] == '>': fields = line.split('|') ac_list.append(fields[1])print(ac_list)结果['Q664P8', 'Q66K14', 'Q8K9I1', 'Q664P8', 'Q66K14', 'Q8E4B4', 'B3原创 2021-04-21 16:45:58 · 183 阅读 · 2 评论 -
用Python实现 获取fasta的头文件
fasta_file = open('SwissProt.fasta', 'r')out_file = open('SwissProt.header', 'w')for line in fasta_file: if line[0:1] == '>': out_file.write(line)out_file.close()fasta:sp|Q664P8|TAUB_YERPS Taurine import ATP-binding protein TauB OS=Y原创 2021-04-21 16:12:04 · 469 阅读 · 0 评论 -
python生物信息学数据管理第三章自测题
3.1 读取和写入文件将文件读取并存为副本file_r = open('ml.txt', 'r')file_w = open('ml副本.txt', 'w')txt = file_r.read()file_w.write(txt)file_r.close()file_w.close()3.2 计算文件中平均值和标准差并保存到另一个文件import mathfile_r = open('jisuan.txt', 'r')file_w = open('结果.txt', 'w')原创 2021-04-16 15:57:48 · 795 阅读 · 1 评论 -
python中read、readline和readlines的区别
read() : 一次性读取整个文件内容。推荐使用read(size)方法,size越大运行时间越长readline() :每次读取一行内容。内存不够时使用,一般不太用readlines() :一次性读取整个文件内容,并按行返回到list,方便我们遍历一般小文件我们都采用read(),不确定大小你就定个size,大文件就用readlines()1)我们先用read来完整读取一个小文件,代码如下:f = open('test.py', 'r')print(f.read())f.close转载 2021-04-16 14:06:18 · 3125 阅读 · 0 评论 -
计算标准差和中位数
计算标准差计算标准差:要先算出平均值,—>(value-aver)**2,相加后除以长度,再开平方跟import mathdata = [3.2, 4.5, 2.4, 9.2, 8.3]aver = sum(data) / len(data)total = 0.0for value in data: total +=(value - aver) ** 2pfc = math.sqrt(total/len(data))print(pfc)计算中位数data =原创 2021-04-16 10:11:17 · 2795 阅读 · 0 评论 -
Python字符串格式化%s%d%f
%s字符串string="hello" #%s打印时结果是hello print "string=%s" % string # output: string=hello #%2s意思是字符串长度为2,当原字符串的长度超过2时,按原长度打印,所以%2s的打印结果还是hello print "string=%2s" % string # output: string=hello #%7s意思是字符串长度为7,当原字符串的长度小于7时,在原字符串左侧补空格, #原创 2021-04-15 10:45:49 · 292 阅读 · 0 评论 -
Python生物信息学数据管理---第二章自测
insulin = '''MPRAPRCRAVRSLLRSHYREVLPLATFVRRLGPQGWRLVQRGDPAAFRALVAQCLVCVPWDARPPPAAPSFRQVSCLKELVARVLQRLCERGAKNVLAFGFALLDGARGGPPEAFTTSVRSYLPNTVTDALRGSGAWGLLLRRVGDDVLVHLLARCALFVLVAPSCAYQVCGPPLYQLGAATQARPPPHASGPRRRLGCERAWNHSVREAGVPLGLPAPGARRRGGSASRSLPLPKRPR原创 2021-04-09 11:01:15 · 677 阅读 · 0 评论 -
matplotlib作图
import numpy as npimport matplotlib.pyplot as mpmp.figure('Figure A', facecolor='gray')mp.title('FigureB', fontsize=16)mp.xlabel('X', fontsize=14)mp.ylabel('Y', fontsize=14)#设置刻度参数 labelsize设置刻度字体大小mp.tick_params(labelsize=10)#设置图表网格线# - or原创 2021-02-18 17:29:34 · 99 阅读 · 1 评论 -
用seaborn作聚类热图
import matplotlib.pyplot as pltimport seaborn as snsimport pandas as pdsns.set()data = pd.read_csv("fs.csv")#print(data.head())flights = data.pivot("month","year","passengers")## 绘制x-y-z的热力图,比如 年-月-销量 的聚类热图g = sns.clustermap(flights, fmt='d', c原创 2021-02-04 21:20:27 · 2396 阅读 · 1 评论 -
用seaborn作热图报错:urllib.error.URLError: <urlopen error [Errno 11004] getaddrinfo failed>
seaborn-data数据下载网址https://codechina.csdn.net/mirrors/mwaskom/seaborn-data?utm_source=csdn_github_acceleratorimport matplotlib.pyplot as pltimport seaborn as snssns.set()#用行和列标签绘制flights_long = sns.load_dataset("flights")flights = flights_long.pivot(原创 2021-02-04 21:15:29 · 3224 阅读 · 2 评论 -
matplotlib显示中文代码
from matplotlib.font_manager import FontProperties#matplotlib图片中不支持中文,需导入字体的路径,字体默认在此路径font_set = FontProperties(fname=r"c:\windows\fonts\simsun.ttc", size=12) #matplotlib找不到字体,需要自行设置一下plt.rcParams['font.sans-serif']=['SimHei'] ...原创 2020-09-18 09:51:01 · 210 阅读 · 0 评论 -
使用matplotlib时报错:RuntimeWarning: Glyph 20998 missing from current font.
添加以下代码即可plt.rcParams['font.sans-serif']=['SimHei']原创 2020-09-17 15:08:00 · 602 阅读 · 3 评论 -
python安装matplotlib模块以及解决timed out
pip install --index-url https://pypi.douban.com/simple matplotlib //添加--index-url https://pypi.douban.com/simple可以解决timed out问题原创 2020-09-16 16:07:59 · 211 阅读 · 0 评论 -
numpy模块安装不成功简单解决方法总结
转自:https://www.jb51.net/article/131358.htm方法一:1、首先选择了easy_installnumpy,安装报错:Unabletofindvcvarsall.bat2、去https://sourceforge.net/projects/numpy/files/NumPy/手动下载安装包,windows系统选择zip,unix系统则选择tar.gz。下载完后解压,在系统命令行下进入该文件夹,执行pythonsetup.pyinstall,然而安装还是报错:大致转载 2020-06-17 19:06:41 · 9890 阅读 · 1 评论