Seqfil stat.pl - calculate frequency of pulse sequence use
From NMR Wiki
(Difference between revisions)
Line 55: | Line 55: | ||
} | } | ||
</source> | </source> | ||
- | [[Category:Perl]] [[Category: | + | [[Category:Perl]] |
+ | [[Category:Scripts]] |
Current revision
This simple script will calculate number of times each pulse sequence is used. After scanning directories (which may take some time), it will print a two column table: number - pulse sequence name.
#!/usr/bin/perl use strict; #data directory that contains user dirs, no slash at the end my $dataroot = '/export/home'; #location to look into for the user directories my @dirs = qw();#add user names here inside the parentheses, no quotes, separated by empty space my %stats; foreach my $user (@dirs){ my $udir = $dataroot . '/' . $user; open FIND, "find $udir -name procpar |" or die $!; my @procpars = <FIND>; close FIND; foreach my $p (@procpars){ chomp $p; my $seqfil = getpar('seqfil',$p); if (!exists $stats{$seqfil}){ $stats{$seqfil} = 0; } $stats{$seqfil}++; } } my @explist = sort { $stats{$b} <=> $stats{$a} } keys %stats; foreach my $e (@explist) { printf "%-6d%s\n", $stats{$e}, $e; } sub getpar{ my ($par,$file) = @_; open PROCPAR, "<$file" or die $!; my $val = undef; while (my $line = <PROCPAR>) { if ($line =~ /^$par\s/){ $val = <PROCPAR>; close PROCPAR; last; } } my @bits = split /\s+/, $val; $val = $bits[1]; if ($val =~ /^"/){ $val =~ s/"//g; } return $val; }