【发布时间】:2020-06-22 21:28:22
【问题描述】:
我正在尝试从我的 perl 脚本中重新创建 python 脚本,以查找所有具有通用名称 model1_r.pdb 的文件,然后他们将其移动到一个新文件夹,其新文件夹的名称与之前的现有文件夹相同。 这是我写的python代码;
import os, shutil, glob
# This program will list all pdb file named (model1_r.pdb) in a given directory.
# inpout: directory name
# output: pdb files
source = input("enter filepath: ")
# build the command to look for model1_r.pdb
for file_path in glob.glob(os.path.join(source, '*model1_r.pdb')):
new_dir = file_path.rsplit('/', 1)[1]
find = os.system("find -type f -name \"model1_r.pdb\" ")
print(filepath)
destination = "/gs/gsfs0/users/kdhusia/dir_all_pdb/"
#Move the files to new folder based with filepath folder name
shutil.move(find, ios.path.join(destination, os.path.basename(filepath)))
这是我的 perl 脚本,它运行良好,但速度很慢
use strict;
use warnings;
use Data::Dumper;
use File::Basename;
# This program will list all pdb file named (model1_r.pdb) in a given directory.
# inpout: directory name
# output: pdb files
my $dir = $ARGV[0] || undef;
die "a directory is required\n" unless $dir;
chomp $dir;
# build the command to look for model1_r.pdb
my $cmd = "find $dir -type f -name \"model1_r.pdb\" ";
#my $cmd = "find $dir -type f -name \"*.pdb\" ";
print $cmd, "\n";
my @output = `$cmd`;
my $DEST = "/gs/gsfs0/users/kdhusia/dcomplex_all";
for my $line (@output) {
# remove CR from $line
chomp $line;
#print $line;
# get pair-name from line
my @pairs = split("\/", $line);
#print Dumper(\@pairs);
my $new_name = $pairs[2].".pdb";
#print "new_name = $new_name\n";
# copy model1_r.pdb to dinal destination
# change the name of pdb to "pair-name.pdb"
my $cmd = "cp $line $DEST/$new_name";
# my $cmd = "./dcomplex $pdbfile A B "
print "$cmd\n";
# do the copy
system($cmd);
}
我使用堆栈上的先前讨论进行了转换(Python: Moving files to folder based on filenames)
我在存储文件路径的过程中遗漏了一些东西。任何 cmets 将不胜感激。
【问题讨论】:
-
基于你的假设,python 版本会比 perl 运行得更快?