Mercurial > repos > venice-juanillas > convert_format
view file_conversion/matrix2powermarker.pl @ 0:f3222062f9ca draft
Uploaded
author | venice-juanillas |
---|---|
date | Mon, 05 Nov 2012 23:01:18 -0500 |
parents | |
children |
line wrap: on
line source
#!C:\Perl\bin\perl use warnings; ##################################################### ## Author: Venice Margarette B. Juanillas ## Date: May 13,2011 ## Program Description: This script will transform a matrix into a Powerformat dataset ## this will utilize a matrix and transpose this matrix ## The column names will become the rows, the SNP ids will be the new ## columns ############################################################################################# ## declarations my $line; my $line_count = 1; my $temp; my $next_line = 0; my @row = (); my @array = (); my @string = (); my @SNP_ids = (); my @Sample_names = (); ## check for file parameters if(!@ARGV or scalar(@ARGV) != 2){ print "No Parameters specified...Specify 1.) input data 2.) output file\n"; }else{ main($ARGV[0],$ARGV[1]); ## call to subroutine main } sub main{ my ($infile, $outfile) = @_; #open input and output files open(IN, "$infile")|| die "Cannot open input file specified."; open(OUT, ">$outfile")|| die "Cannot open input file specified."; #read line by line while($line = <IN>){ next if $line =~ /^\s*$/; # skip blank lines if($line_count == 1){ @Sample_names = split(/\t|\n/,$line); ## split the header, which contains the sample names and store them to an array $next_line =1; ## flag to got to the next line $line_count++; next; } if($next_line == 1){ ## reading the next line @row = split(/\t|\n/,$line); ## slits all elements delimited by the tabs and newlines push(@SNP_ids,$row[0]); ## store all ids for($i = 0; $i < $#Sample_names; $i++){ $Sample_names[$i] = $Sample_names[$i]."\t".$row[$i]; ## append all data markers to their respective sample names } } } #this is segment is mainly for outputting the transposed matrix into the file #for($i = 0;$i <= $#SNP_ids;$i++){ # print OUT "$SNP_ids[$i]\t"; #} #print OUT "\n"; for($i = 0;$i < $#Sample_names;$i++){ ## output to file all contents of the array print OUT $Sample_names[$i]."\n"; ## basically all that's in the matrix } ## close files to save modifications close(IN); close(OUT); } ## end of script