Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

cp Program Error

by Anonymous Monk
on Aug 01, 2013 at 10:18 UTC ( #1047413=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks, I have some programs that check wether corresponding sites in different single line text files match or differ with respect to a 0 or N character. The program ultimately creates a single file of the same length where at any position in the text file a 0 denotes all searched files contain a 0 in that spot and an N denotes at least one file contained an N. The initial step involves the cp command and for two of my 6 programs I receive this message from my terminal screen.

usage: cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file target_fi +le cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file ... targe +t_directory mv: rename /Users/logancurtis-whitchurch/Dropbox/thesis_folder/consens +us_files/files/mask.9_Afr_females_chr.23.output.txt to /Users/logancurtis-whitchurch/Dropbox/thesis_folder/consensus_files/fi +les/mask.9_Afr_females.chr.23.txt: No such file or directory .chr.23.txtmask.NA18505

I am at a loss because these directories do exist and when executing the cp command in an isolated manner with just terminal it works

#! /usr/bin/perl -w use strict; use warnings; use Term::ANSIColor; #--------------------------------------------------------------------- +---------- # What: This program will output the number of reference sites assayed + in all # individuals in a given file, for chromosome 23. # # This is for the subpopulation of 9 Afr females. #--------------------------------------------------------------------- +---------- my $usage = "get_ref_sites_9_Afr_females.pl [individual_name_list]\n"; die $usage unless @ARGV == 1; #--------------------------------------------------------------------- +---------- open (INDV, "<$ARGV[0]") or die "Cannot open $ARGV[0]:$!\n"; my @individuals = <INDV>; # Define array close(INDV); my $chr = 23; my $indv_count = 0; my ($indv, $individuals, $covered, $buf, $data, $n, $count); while ($indv_count < 9){ #This needs to be the count of the number of + individuals if ($indv_count == 0) { chomp($individuals[$indv_count]); $indv = $individuals[$indv_count]; $count = 0; my $file_name = "mask".".$indv".".chr.23.txt"; system("cp /Users/logancurtis-whitchurch/Dropbox/thesis_fo +lder/CompleteGenomics/all_individuals_called_sites/$file_name /Users/ +logancurtis-whitchurch/Dropbox/thesis_folder/consensus_files/files/ma +sk.9_Afr_females_chr.$chr.output.txt"); $indv_count++; } else{ system("mv /Users/logancurtis-whitchurch/Dropbox/thesis_fo +lder/consensus_files/files/mask.9_Afr_females_chr.$chr.output.txt /Us +ers/logancurtis-whitchurch/Dropbox/thesis_folder/consensus_files/file +s/mask.9_Afr_females.chr.$chr.txt"); chomp($individuals[$indv_count]); $indv = $individuals[$indv_count]; $count = 0; my $file_name = "mask".".$indv".".chr.23.txt"; open(INPUT, "/Users/logancurtis-whitchurch/Dropbox/thesis_ +folder/CompleteGenomics/all_individuals_called_sites/$file_name") or +die "can't open $file_name\n"; open(OUT, ">/Users/logancurtis-whitchurch/Dropbox/thesis_f +older/consensus_files/files/mask.9_Afr_females.chr.$chr.output.txt"); open(MASK, "/Users/logancurtis-whitchurch/Dropbox/thesis_f +older/consensus_files/files/mask.9_Afr_females.chr.$chr.txt") or die +"can't open masked file for chr $chr:$!\n"; my $mask=<MASK>; chomp($mask); close(MASK); while (($n = read INPUT, $data, 100000) != 0) { my @info = split(//, $data); foreach my $info (@info){ if($info =~ "N"){ substr($mask,($count),1,'N'); } $count++; } $buf .= $data; print "$count for $indv for chr $chr are read\n"; } print OUT "$mask\n"; close(INPUT); close(OUT); $count = 0; $indv_count++; $mask = ""; $data = ""; $n = ""; $buf = ""; } }

Comment on cp Program Error
Select or Download Code
Re: cp Program Error
by choroba (Abbot) on Aug 01, 2013 at 10:32 UTC
    Are you sure your system arguments do not contain any newline? From the error mv emits it seems there is a newline after the file name.
    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      I checked the text file that I used for my  @individuals array for new lines as well as the source code entry and didn't find any, thank you though

Re: cp Program Error
by RichardK (Priest) on Aug 01, 2013 at 10:54 UTC

      I went ahead and changed the source code so that rename is used and now the only message the terminal puts out before terminating the program is .chr.23.txtmask.NA12004 this baffles me because I have no files with this syntax in the directories being used or anywhere on my computer. All the files I'm using have names like mask.NA12004.chr.23.txt the source of the error escapes me. Thank you for the tip though.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1047413]
Approved by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (11)
As of 2014-09-23 15:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (224 votes), past polls