I am working in design some script to copy files from a specific directory and put them into a new one directory, the structure could be..
file(s) to be copied (it could a file with the files name to be copied, and if the format is a column, it will be ok)
address in(where are these files)
address out (destiny of the copied files)
I check some script in perl, and I found a script in http://hayne.net/MacDev/Perl/copy_without_xattr
the script is #!/usr/bin/perl
# copy_without_xattr # Files on OS X can have resource forks and other extended attributes and # as of Tiger (10.4) the 'cp' command copies these extended attributes. # This script copies the file(s) given as command-line args # to the destination given as the last command-line arg # but suppresses the copying of extended attributes. # I.e. it does the same thing as /bin/cp except for the extended attributes # This is useful when the destination is on a non-HFS volume # in order to avoid the "._" files that would otherwise be produced. # (These "._" files hold the extended attributes and resource fork info) # # Cameron Hayne (macdev@hayne.net) Sept 2005
use strict; use warnings; use File::Basename;
my $scriptName = basename($0); if (scalar(@ARGV) < 2) { print("usage: $scriptName file1 [file2 file3 ...] destDir"); exit 1; }
my $destDir = pop(@ARGV); my @files = @ARGV; die "$scriptName: $destDir is not a directory\n" unless -d $destDir; die "$scriptName: $destDir is not writable\n" unless -w $destDir; foreach my $file (@files) { die "$scriptName: $file is not a file\n" unless -f $file; die "$scriptName: File $file does not exist or is not readable\n" unless -r $file; }
# We set an environment variable to disable the copying of extended attributes # Unfortunately, /bin/cp does not look at COPY_EXTENDED_ATTRIBUTES_DISABLE # or this script would be as simple as: /bin/cp @ARGV # We use '/usr/bin/tar' (which does look at COPY_EXTENDED_ATTRIBUTES_DISABLE) # to simulate the effect of /bin/cp # Note: to test future versions of 'tar' to see if they are using this variable, # you could use the command: # 'strings /usr/bin/tar | grep COPY_EXTENDED_ATTRIBUTES_DISABLE'
my $tmpFile = "/tmp/$scriptName$$"; my $tarCreateCmd = "/usr/bin/tar -cf $tmpFile"; foreach my $file (@files) { my $fname = basename($file); my $dname = dirname($file); # we use the "-C" option so that the archive will have the basenames $tarCreateCmd .= " -C $dname $fname"; } system($tarCreateCmd) == 0 or die "$scriptName: failed to create tar file: $!\n";;
chdir($destDir) or die "$scriptName: failed to chDir to $destDir: $!\n";
my $tarExtractCmd = "/usr/bin/tar -xf $tmpFile"; system($tarExtractCmd) == 0 or die "$scriptName: failed to extract tar file: $!\n";;
unlink($tmpFile) or die "Failed to unlink $tmpFile: $!\n";
It seems almost ok for my purpose, but I write some changes.
Other script that could be useful, is in http://www.xav.com/perl/lib/File/Copy.html
Also I check this script, but it remark that file::Copy does'n work from http://forums.hostmysite.com/post-6651.html
use strict; use File::Copy;
open( IN, "/Users/paul/Desktop/missinglist" );
my $line; my @line_array; while ( $line = IN ) { push(@line_array , split(/\r/, $line )); } my $num = @line_array; my $count = 0; my $patha; my $pathb; my @array;
while ($count < $num) { my @array = split(/\t/, @line_array[$count] ); my $patha = @array[0]; #this is the first path ex. "/Music/iTunes/iTunes Music/Silbermond/Verschwende deine Zeit/17 Symphonie (On Stage).m4a" $count++;
my @array = split(/\t/, @line_array[$count] ); my $pathb = @array[0]; #this is the second path ex. "/Users/paul/Desktop/itunescopy/17 Symphonie (On Stage).m4a" $count++;
print "-$patha-\t-$pathb-\n"; copy($patha, $pathb); #this should copy, but doesn't - when the paths are directly typed in here w/ quotes, it works }
program copy_file.pl from http://hayne.net/MacDev/Perl/
#!/usr/bin/perl
# copy_file.pl # programa obrtenido de la red y modificado en cuanto a la localizacion del tar # referencia http://hayne.net/MacDev/Perl/copy_without_xattr # Cameron Hayne (macdev@hayne.net) Sept 2005
use strict; use warnings; use File::Basename;
my $scriptName = basename($0); if (scalar(@ARGV) < 2) { print("usage: $scriptName file1 [file2 file3 ...] destDir"); exit 1; }
my $destDir = pop(@ARGV); my @files = @ARGV; die "$scriptName: $destDir is not a directory\n" unless -d $destDir; die "$scriptName: $destDir is not writable\n" unless -w $destDir; foreach my $file (@files) { die "$scriptName: $file is not a file\n" unless -f $file; die "$scriptName: File $file does not exist or is not readable\n" unless -r $file; }
my $tmpFile = "/tmp/$scriptName$$"; my $tarCreateCmd = "tar -cf $tmpFile"; foreach my $file (@files) { my $fname = basename($file); my $dname = dirname($file); $tarCreateCmd .= " -C $dname $fname"; } system($tarCreateCmd) == 0 or die "$scriptName: failed to create tar file: $!\n";;
chdir($destDir) or die "$scriptName: failed to chDir to $destDir: $!\n";
my $tarExtractCmd = "tar -xf $tmpFile"; system($tarExtractCmd) == 0 or die "$scriptName: failed to extract tar file: $!\n";;
unlink($tmpFile) or die "Failed to unlink $tmpFile: $!\n";
Programa splitSeq.pl por Juan Caballero, se utiliza para separar en archivos fasta un archivo multifasta. muy util Gracias Juan!! (los < y &lgt representan realmente <, y >. )
#!/usr/bin/perl -w use strict;
$/ = ">"; $ARGV[0] or die "usage: perl splitSeq.pl FASTA\n"; open S, "$ARGV[0]" or die "Error reading $ARGV[0]\n";
while (<S>) { s/>//g; if (/^[\w|\d]+/) { my $id = $&; die "Uniq identifier exists\n" if (-f "$id.fasta"); open O, ">$id.fasta" or die "Error writing output\n"; print O ">$_"; close O; } } close S;
the next lines could be useful when you are working in a cluster, the example are about a blast analysis, please, check the lines careful, because I guess the address must be updated.
7 comments:
I am working in design some script to copy files from a specific directory and put them into a new one directory, the structure could be..
file(s) to be copied (it could a file with the files name to be copied, and if the format is a column, it will be ok)
address in(where are these files)
address out (destiny of the copied files)
I check some script in perl, and I found a script in http://hayne.net/MacDev/Perl/copy_without_xattr
the script is #!/usr/bin/perl
# copy_without_xattr
# Files on OS X can have resource forks and other extended attributes and
# as of Tiger (10.4) the 'cp' command copies these extended attributes.
# This script copies the file(s) given as command-line args
# to the destination given as the last command-line arg
# but suppresses the copying of extended attributes.
# I.e. it does the same thing as /bin/cp except for the extended attributes
# This is useful when the destination is on a non-HFS volume
# in order to avoid the "._" files that would otherwise be produced.
# (These "._" files hold the extended attributes and resource fork info)
#
# Cameron Hayne (macdev@hayne.net) Sept 2005
use strict;
use warnings;
use File::Basename;
my $scriptName = basename($0);
if (scalar(@ARGV) < 2)
{
print("usage: $scriptName file1 [file2 file3 ...] destDir");
exit 1;
}
my $destDir = pop(@ARGV);
my @files = @ARGV;
die "$scriptName: $destDir is not a directory\n" unless -d $destDir;
die "$scriptName: $destDir is not writable\n" unless -w $destDir;
foreach my $file (@files)
{
die "$scriptName: $file is not a file\n"
unless -f $file;
die "$scriptName: File $file does not exist or is not readable\n"
unless -r $file;
}
# We set an environment variable to disable the copying of extended attributes
# Unfortunately, /bin/cp does not look at COPY_EXTENDED_ATTRIBUTES_DISABLE
# or this script would be as simple as: /bin/cp @ARGV
# We use '/usr/bin/tar' (which does look at COPY_EXTENDED_ATTRIBUTES_DISABLE)
# to simulate the effect of /bin/cp
# Note: to test future versions of 'tar' to see if they are using this variable,
# you could use the command:
# 'strings /usr/bin/tar | grep COPY_EXTENDED_ATTRIBUTES_DISABLE'
$ENV{'COPY_EXTENDED_ATTRIBUTES_DISABLE'} = "true";
my $tmpFile = "/tmp/$scriptName$$";
my $tarCreateCmd = "/usr/bin/tar -cf $tmpFile";
foreach my $file (@files)
{
my $fname = basename($file);
my $dname = dirname($file);
# we use the "-C" option so that the archive will have the basenames
$tarCreateCmd .= " -C $dname $fname";
}
system($tarCreateCmd) == 0
or die "$scriptName: failed to create tar file: $!\n";;
chdir($destDir) or die "$scriptName: failed to chDir to $destDir: $!\n";
my $tarExtractCmd = "/usr/bin/tar -xf $tmpFile";
system($tarExtractCmd) == 0
or die "$scriptName: failed to extract tar file: $!\n";;
unlink($tmpFile) or die "Failed to unlink $tmpFile: $!\n";
It seems almost ok for my purpose, but I write some changes.
Other script that could be useful, is in http://www.xav.com/perl/lib/File/Copy.html
use File::Copy;
copy("file1","file2");
copy("Copy.pm",\*STDOUT);'
move("/dev1/fileA","/dev2/fileB");
use POSIX;
use File::Copy cp;
$n = FileHandle->new("/a/file","r");
cp($n,"x");'
but I saw that it requires a module, isn't it?
Also I check this script, but it remark that file::Copy does'n work
from http://forums.hostmysite.com/post-6651.html
use strict;
use File::Copy;
open( IN, "/Users/paul/Desktop/missinglist" );
my $line;
my @line_array;
while ( $line = IN )
{
push(@line_array , split(/\r/, $line ));
}
my $num = @line_array;
my $count = 0;
my $patha;
my $pathb;
my @array;
while ($count < $num) {
my @array = split(/\t/, @line_array[$count] );
my $patha = @array[0]; #this is the first path ex. "/Music/iTunes/iTunes Music/Silbermond/Verschwende deine Zeit/17 Symphonie (On Stage).m4a"
$count++;
my @array = split(/\t/, @line_array[$count] );
my $pathb = @array[0]; #this is the second path ex. "/Users/paul/Desktop/itunescopy/17 Symphonie (On Stage).m4a"
$count++;
print "-$patha-\t-$pathb-\n";
copy($patha, $pathb); #this should copy, but doesn't - when the paths are directly typed in here w/ quotes, it works
}
Juan Caballero a dit:
Juan: cp *.fasta directorio/
Juan: entonces: cp 1.fasta 2.fasta 3.fasta 4.fasta directorio/
o si tienes un archivo con la lista que te interesa:
cp `cat list` directorio/
Juan: pues la lista puede ser por espacios o tabulares, si es con cambios de linea cambialo a una funcion recursiva:
for I in `cat list`; do cp $I directorio/; done
program copy_file.pl from http://hayne.net/MacDev/Perl/
#!/usr/bin/perl
# copy_file.pl
# programa obrtenido de la red y modificado en cuanto a la localizacion del tar
# referencia http://hayne.net/MacDev/Perl/copy_without_xattr
# Cameron Hayne (macdev@hayne.net) Sept 2005
use strict;
use warnings;
use File::Basename;
my $scriptName = basename($0);
if (scalar(@ARGV) < 2)
{
print("usage: $scriptName file1 [file2 file3 ...] destDir");
exit 1;
}
my $destDir = pop(@ARGV);
my @files = @ARGV;
die "$scriptName: $destDir is not a directory\n" unless -d $destDir;
die "$scriptName: $destDir is not writable\n" unless -w $destDir;
foreach my $file (@files)
{
die "$scriptName: $file is not a file\n"
unless -f $file;
die "$scriptName: File $file does not exist or is not readable\n"
unless -r $file;
}
$ENV{'COPY_EXTENDED_ATTRIBUTES_DISABLE'} = "true";
my $tmpFile = "/tmp/$scriptName$$";
my $tarCreateCmd = "tar -cf $tmpFile";
foreach my $file (@files)
{
my $fname = basename($file);
my $dname = dirname($file);
$tarCreateCmd .= " -C $dname $fname";
}
system($tarCreateCmd) == 0
or die "$scriptName: failed to create tar file: $!\n";;
chdir($destDir) or die "$scriptName: failed to chDir to $destDir: $!\n";
my $tarExtractCmd = "tar -xf $tmpFile";
system($tarExtractCmd) == 0
or die "$scriptName: failed to extract tar file: $!\n";;
unlink($tmpFile) or die "Failed to unlink $tmpFile: $!\n";
Programa splitSeq.pl por Juan Caballero, se utiliza para separar en archivos fasta un archivo multifasta. muy util Gracias Juan!!
(los < y &lgt representan realmente <, y >. )
#!/usr/bin/perl -w
use strict;
$/ = ">";
$ARGV[0] or die "usage: perl splitSeq.pl FASTA\n";
open S, "$ARGV[0]" or die "Error reading $ARGV[0]\n";
while (<S>) {
s/>//g;
if (/^[\w|\d]+/) {
my $id = $&;
die "Uniq identifier exists\n" if (-f "$id.fasta");
open O, ">$id.fasta" or die "Error writing output\n";
print O ">$_";
close O;
}
}
close S;
the next lines could be useful when you are working in a cluster, the example are about a blast analysis, please, check the lines careful, because I guess the address must be updated.
#!/usr/bin/bash
#$ -cwd
#$ -j y
#$ -S /bin/bash
export BLASTDB=/share/bio/ncbi/db/
export BLASTDIR=/opt/Bio/ncbi/bin/
export BLASTMAT=/opt/Bio/ncbi/dat
$BLASTDIR/blastall -p blastn -i file.seq -d $BLASTDB/NR/nr -o file.blast -e 0.0001 -m 8 -a 2
Cesar
REMOVING \n in FASTA files from with perl
from @linxe
removing "\n" in fasta files: perl -ane 's/\n// unless(/>/); print $_' < fasta > new_file
Post a Comment