At 10:46 AM 3/25/2005 -0600, Shiping Wang wrote:
Hi, I have problem to match array defined in Getopt::Long and transfer to
new file:
If I do:
try.pl --InputData sample.txt --Trait=_BMI --covars=age, _DBP, _SBP
--Race=Others
with this file:
GFAMID GDADID GMOMID ID SEX
HYT3 _SBP _DBP _BMI RACE AGE _HTMED antiht
How can I get it to new file like this:
A HYT3
C _SBP
C _DBP
T _BMI
S RACE
C AGE
S _HTMED
S antiht
Thanks!!!
SW
###############################################################################
#!/usr/local/bin/perl
# try.pl
use warnings;
use strict;
use Getopt::Long;
my $inputData =' ';
my $trait= ' ';
my $race;
my @covars;
my $result = GetOptions("InputData=s" => \$inputData,
"Trait=s"
=> \$trait,
"Race=s"
=> \$race,
"Covars=s" => [EMAIL PROTECTED]
);
my @covarlist = split(/,/,
@covars);
if(!$inputData){
exit();
}
#die "you must specify all parameters\n\t--Trait --Race
--Covars\n" unless(define $trait || define $race || define @covars);
my $oriname = (split/\./, $inputData)[0];
my $outname;
if ($race){
$outname = "$oriname\_$race";
} else{
$outname = "$oriname";
}
open (outDat, ">$outname.dat") or die $!;
open (inPed, "$inputData") or die $!;
my $header = <inPed>;
chomp $header;
my @headline = split/\t/, $header;
my @ped_n_trait = @headline[0, 3, 1, 2, 4..12];
my %vartype;
### not working
foreach my $i (@ped_n_trait[5..12]){
if ($i eq 'HYT3'){
$vartype{$i} = 'A';
}elsif ($i eq "$trait"){
$vartype{$i} = 'T';
}else{
$vartype{$i} = 'S';
for(@covarlist){
if($_ eq "$i"){
$vartype{$_} = 'C';
}
}
}
}
### working, maybe better way to it ###
foreach my $i (@ped_n_trait[5..12]){
if ($i eq 'HYT3'){
$vartype{$i} = 'A';
}elsif ($i eq "$trait"){
$vartype{$i} = 'T';
}else{
for(@covarlist){
if($_ eq "$i"){
$vartype{$i} = 'C';
}
$vartype{$i} = 'S' if (!$vartype{$i});
}
}
}
for (@ped_n_trait[5..12]){
print outDat "$vartype{$_}\t$_\n";
}
close outDat;
close inPed;
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>