import os header = ["[REF]", "[QRY]", "[Sequences]", "TotalSeqs", "AlignedSeqs", "UnalignedSeqs", "[Bases]", "TotalBases","AlignedBases", "UnalignedBases", "[Alignments]", "1-to-1", "TotalLength", "AvgLength", "AvgIdentity","M-to-M", "TotalLength", "AvgLength", "AvgIdentity", "[Feature Estimates]", "Breakpoints", "Relocations", "Translocations", "Inversions", "Insertions", "InsertionSum", "InsertionAvg", "TandemIns", "TandemInsSum","TandemInsAvg", "[SNPs]", "TotalSNPs"] data = {} for file_name in os.listdir("/public/work/Personal/wuxu/qiantao_17"): if file_name.endswith(".report"): with open(os.path.join("/public/work/Personal/wuxu/qiantao_17", file_name), "r") as f: for line in f: split_line = line.strip().split() if len(split_line) < 2: continue key, value = split_line[:2] if key not in data: data[key] = header if key == "[REF]" else [value] else: data[key].append(value) # 输出表头 print("file_name", *header, sep="\t") # 输出数据 for file_name in os.listdir("/public/work/Personal/wuxu/qiantao_17"): if file_name.endswith(".report"): for i in range(len(data.get("[REF]", []))): row = [file_name] + [data.get(key, [""] * len(data.get("[REF]", [])))[i] for key in header] print(*row, sep="\t")对file_name遍历,每行的第一列为每个文件名,其余每列为对应的数据
时间: 2023-08-29 22:09:29 浏览: 32
这段代码的功能是读取指定文件夹下以“.report”结尾的文件,将这些文件中的数据提取出来,并按照表头输出每个文件中的数据。具体实现是先定义一个表头列表,再定义一个字典来存储每个关键字对应的数据,然后遍历文件夹中的每个“.report”文件,逐行读取文件的内容,将读取到的数据存储到字典中相应的关键字对应的值中。最后,按照表头输出每个文件中的数据。
相关问题
import os header = ["[REF]", "[QRY]", "[Sequences]", "TotalSeqs", "AlignedSeqs", "UnalignedSeqs", "[Bases]", "TotalBases","AlignedBases", "UnalignedBases", "[Alignments]", "1-to-1", "TotalLength", "AvgLength", "AvgIdentity","M-to-M", "TotalLength", "AvgLength", "AvgIdentity", "[Feature Estimates]", "Breakpoints", "Relocations", "Translocations", "Inversions", "Insertions", "InsertionSum", "InsertionAvg", "TandemIns", "TandemInsSum","TandemInsAvg", "[SNPs]", "TotalSNPs"] data = {} for file_name in os.listdir("/public/work/Personal/wuxu/qiantao_17"): if file_name.endswith(".report"): with open(os.path.join("/public/work/Personal/wuxu/qiantao_17", file_name), "r") as f: for line in f: split_line = line.strip().split() if len(split_line) < 2: continue key, value = split_line[:2] if key not in data: data[key] = header if key == "[REF]" else [value] else: data[key].append(value) # 输出表头 print("file_name", *header, sep="\t") # 输出数据 for file_name in os.listdir("/public/work/Personal/wuxu/qiantao_17"): if file_name.endswith(".report"): for i in range(len(data.get("[REF]", []))): row = [file_name] + [data.get(key, [""] * len(data.get("[REF]", [])))[i] for key in header] print(*row, sep="\t"),修改代码,实现输出结果的第一列每一行为每个.report的文件名,其余列为对应的数据
import os
header = ["[REF]", "[QRY]", "[Sequences]", "TotalSeqs", "AlignedSeqs", "UnalignedSeqs", "[Bases]", "TotalBases","AlignedBases", "UnalignedBases", "[Alignments]", "1-to-1", "TotalLength", "AvgLength", "AvgIdentity","M-to-M", "TotalLength", "AvgLength", "AvgIdentity", "[Feature Estimates]", "Breakpoints", "Relocations", "Translocations", "Inversions", "Insertions", "InsertionSum", "InsertionAvg", "TandemIns", "TandemInsSum","TandemInsAvg", "[SNPs]", "TotalSNPs"]
data = {}
for file_name in os.listdir("/public/work/Personal/wuxu/qiantao_17"):
if file_name.endswith(".report"):
with open(os.path.join("/public/work/Personal/wuxu/qiantao_17", file_name), "r") as f:
for line in f:
split_line = line.strip().split()
if len(split_line) < 2:
continue
key, value = split_line[:2]
if key not in data:
data[key] = header if key == "[REF]" else [value]
else:
data[key].append(value)
# 输出表头
print("file_name", *header, sep="\t")
# 输出数据
for file_name in os.listdir("/public/work/Personal/wuxu/qiantao_17"):
if file_name.endswith(".report"):
for i in range(len(data.get("[REF]", []))):
row = [file_name.split(".")[0]] + [data.get(key, [""] * len(data.get("[REF]", [])))[i] for key in header]
print(*row, sep="\t")
修改后的代码中,将文件名进行了处理,只输出了文件名的前缀部分,即去掉了后缀".report",并在输出数据时,第一列输出了对应的文件名。其余部分的代码和原来的代码基本相同。
以qry用户进入SQL SERVERCREATE LOGIN qry WITH PASSWORD ='qry', Default_database=[STUDENT632107100233]; CREATE USER qry FOR LOGIN qry with default_schema=dbo
好的,您的问题是 "以qry用户进入SQL SERVERCREATE LOGIN qry WITH PASSWORD ='qry', Default_database=[STUDENT632107100233]; CREATE USER qry FOR LOGIN qry with default_schema=dbo",这是一个 SQL Server 的命令,它的作用是创建一个名为 "qry" 的登录账户,并设置密码为 "qry",并将默认数据库设置为 "STUDENT632107100233",然后为这个登录账户创建一个用户,并将默认模式设置为 "dbo"。请问您还有其他的问题吗?
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![exe](https://img-home.csdnimg.cn/images/20210720083343.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)