perlquestion
Anonymous Monk
<p>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. </p>
<code>
usage: cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file target_file
cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file ... target_directory
mv: rename /Users/logancurtis-whitchurch/Dropbox/thesis_folder/consensus_files/files/mask.9_Afr_females_chr.23.output.txt
to
/Users/logancurtis-whitchurch/Dropbox/thesis_folder/consensus_files/files/mask.9_Afr_females.chr.23.txt: No such file or directory
.chr.23.txtmask.NA18505
</code>
<p>
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
</p>
<code>
#! /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_folder/CompleteGenomics/all_individuals_called_sites/$file_name /Users/logancurtis-whitchurch/Dropbox/thesis_folder/consensus_files/files/mask.9_Afr_females_chr.$chr.output.txt");
$indv_count++;
}
else{
system("mv /Users/logancurtis-whitchurch/Dropbox/thesis_folder/consensus_files/files/mask.9_Afr_females_chr.$chr.output.txt /Users/logancurtis-whitchurch/Dropbox/thesis_folder/consensus_files/files/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_folder/consensus_files/files/mask.9_Afr_females.chr.$chr.output.txt");
open(MASK, "/Users/logancurtis-whitchurch/Dropbox/thesis_folder/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 = "";
}
}
</code>
5