comparison file_conversion/matrix2powermarker.pl @ 0:f3222062f9ca draft

Uploaded
author venice-juanillas
date Mon, 05 Nov 2012 23:01:18 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f3222062f9ca
1 #!C:\Perl\bin\perl
2 use warnings;
3
4 #####################################################
5 ## Author: Venice Margarette B. Juanillas
6 ## Date: May 13,2011
7 ## Program Description: This script will transform a matrix into a Powerformat dataset
8 ## this will utilize a matrix and transpose this matrix
9 ## The column names will become the rows, the SNP ids will be the new
10 ## columns
11 #############################################################################################
12
13 ## declarations
14 my $line;
15 my $line_count = 1;
16 my $temp;
17 my $next_line = 0;
18 my @row = ();
19 my @array = ();
20 my @string = ();
21 my @SNP_ids = ();
22 my @Sample_names = ();
23
24 ## check for file parameters
25 if(!@ARGV or scalar(@ARGV) != 2){
26 print "No Parameters specified...Specify 1.) input data 2.) output file\n";
27 }else{
28 main($ARGV[0],$ARGV[1]); ## call to subroutine main
29 }
30
31 sub main{
32 my ($infile, $outfile) = @_;
33
34 #open input and output files
35 open(IN, "$infile")|| die "Cannot open input file specified.";
36 open(OUT, ">$outfile")|| die "Cannot open input file specified.";
37
38 #read line by line
39 while($line = <IN>){
40 next if $line =~ /^\s*$/; # skip blank lines
41 if($line_count == 1){
42 @Sample_names = split(/\t|\n/,$line); ## split the header, which contains the sample names and store them to an array
43 $next_line =1; ## flag to got to the next line
44 $line_count++;
45 next;
46 }
47 if($next_line == 1){ ## reading the next line
48 @row = split(/\t|\n/,$line); ## slits all elements delimited by the tabs and newlines
49 push(@SNP_ids,$row[0]); ## store all ids
50 for($i = 0; $i < $#Sample_names; $i++){
51 $Sample_names[$i] = $Sample_names[$i]."\t".$row[$i]; ## append all data markers to their respective sample names
52 }
53 }
54 }
55
56 #this is segment is mainly for outputting the transposed matrix into the file
57 #for($i = 0;$i <= $#SNP_ids;$i++){
58 # print OUT "$SNP_ids[$i]\t";
59 #}
60 #print OUT "\n";
61 for($i = 0;$i < $#Sample_names;$i++){ ## output to file all contents of the array
62 print OUT $Sample_names[$i]."\n"; ## basically all that's in the matrix
63 }
64
65 ## close files to save modifications
66 close(IN);
67 close(OUT);
68
69 }
70
71 ## end of script