Assembly copy from subdirectory
0
0
Entering edit mode
2.9 years ago
Jecy J • 0

Hi everyone,

i have done spades assembly of multiple samples and would like to copy all the contig file from subdirectory.

I tried like this

cat file_list.txt | xargs -I {} cp {} /destination/dir/path

# file_list.txt : all the contig file name

But somehow its showing the contig file not present in subdirectory, but I crossed check and found files are present.

Can anybody please let me the solution. I am using macOS.

Thanks JC

Assembly • 1.1k views
ADD COMMENT
0
Entering edit mode

I think this should work:

cat file_list.txt | xargs -i cp {} /destination/dir/path
ADD REPLY
0
Entering edit mode

Sorry it did not work

1st try

$ cat abc.txt | xargs -i cp {} /Users/jecy/project
xargs: illegal option -- i
usage: xargs [-0opt] [-E eofstr] [-I replstr [-R replacements] [-S replsize]]
             [-J replstr] [-L number] [-n number [-x]] [-P maxprocs]
             [-s size] [utility [argument ...]]

2nd try.

$cat abc.txt | xargs -I cp {} /Users/jecy/project
xargs: {}: No such file or directory
ADD REPLY
0
Entering edit mode

can you post one or two lines from abc.txt? I think xargs is not getting any input. Btw, are you using windows or gnu-linux?

ADD REPLY
0
Entering edit mode
cat abc.txt
1.fa
2.fa
3.fa
4.fa
5.fa

The subdirectory like this :

% cd test1
 % ls
1.fa        123.txt     2.fa        3.fa        new_test
ADD REPLY
0
Entering edit mode

Then your command should be like this:

$ cat abc.txt | xargs -I {} cp test1/{} /Users/jecy/project

Assuming that all files in abc.txt are in test1 directory.

ADD REPLY
0
Entering edit mode

Thanks for reply. Sorry, directory structure are like this.

% cd test

#inside this directory there are few subdirectories and abc.txt 

%ls
test1 test2 test3 abc.txt 

and i would like to copy files present inside the subdirectories to test directory

ADD REPLY
0
Entering edit mode

xargs must be supplied exact location to copy the files. Since it is not happening, xargs is failing. Either abc.txt should have file name with path or you supply file path to xargs. You can take a different approach as follows:

$ cd test
$ find . -type f -name "*.fa" | xargs -I {} echo {}  
# This should print the files with .fa extension within directory and subdirectories. If output lists all the files you want to copy, then try following
$ find . -type f -name "*.fa" | xargs -I {} cp {} <destination>

It would have been better if you furnished tree at the start. If you use find, you don't even need xargs.

ADD REPLY
0
Entering edit mode
But somehow its showing the contig file not present in subdirectory,

Always post the error please . The function you posted worked on my system. Check for the typos, incorrect destination name and check if directory names have special characters such as space etc.

You can do this in several ways.

cat test.txt| while read line; do echo cp $line /destination/dir/path; done (Remove echo after checking the dry-run)

cat test.txt| parallel --plus --dry-run cp {} $line /destination/dir/path (Remove --dry-run after checking the dry-run)

Parallel comes from GNU-Parallel and is present in system repos for most of the gnu-linux distros.

ADD REPLY

Login before adding your answer.

Traffic: 1765 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6