ic23oluk has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks
I am thinking of how to store the table below into a complex data structure, and which data structure to use. The input is a tab-separated .txt file, derived from excel. Note that some cells are empty (in this case "RQ Max"). Here's the table:
and here is my codeWell Sample Name Target Name RQ Max Ct Mean 1 Sample 1 actin 20,514 2 Sample 1 claudin 30,544 3 Sample 1 occludin 31,183 25 Sample 1 actin 20,514 26 Sample 1 claudin 30,544 27 Sample 1 occludin 31,183 49 Sample 2 actin 20,416 50 Sample 2 claudin 25,611 51 Sample 2 occludin 27,831 73 Sample 2 actin 20,416 74 Sample 2 claudin 25,611 75 Sample 2 occludin 27,831 97 Sample 3 actin 24,213 98 Sample 3 claudin 32,065 99 Sample 3 occludin 34,556 121 Sample 3 actin 24,213 122 Sample 3 claudin 32,065 123 Sample 3 occludin 34,556 145 Sample 4 actin 20,498 146 Sample 4 claudin 25,365 147 Sample 4 occludin 27,869 169 Sample 4 actin 20,498 170 Sample 4 claudin 25,365 171 Sample 4 occludin 27,869 193 H2O actin 194 H2O claudin 195 H2O occludin 217 H2O actin 218 H2O claudin 219 H2O occludin
#! usr/bin/perl use strict; use warnings; # CHECK FOR CORRECT USAGE unless (@ARGV == 1){ die "Usage: perl $0 \"file.txt\"\n"; } my $input = "$ARGV[0]"; #chomp ($input); open (READ, $input) || die "Cannot open $input: $!\n"; my $line = ''; my %data; while ($line = <READ>){ chomp $line; if ($line =~ m/^[0-9]/i); $i++; $data{"$i"} = [ split /\t{1}/, $line ]; } }
as you can see, i am at the very beginning of my program, because I am not sure which structure to use. Actually I only need three columns of the entire table, which is "Sample Name", "Target Name" and "Ct Mean". As I later want to calculate sth for each Sample, it might be helpful to have these as the keys. In a hash of hashes structure, I'd like to have the Target Names as the "second keys". Could somebody push me into the right direction? Im currently struggling with the storing of the data, as I haven't used perl for a longer period...
Thanks in advance!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: table into complex data structure
by choroba (Cardinal) on Oct 31, 2017 at 13:32 UTC | |
by ic23oluk (Sexton) on Oct 31, 2017 at 13:54 UTC | |
by holli (Abbot) on Oct 31, 2017 at 16:01 UTC | |
|
Re: table into complex data structure
by thanos1983 (Parson) on Oct 31, 2017 at 14:50 UTC | |
|
Re: table into complex data structure
by 1nickt (Canon) on Oct 31, 2017 at 14:11 UTC |