• PAM 2500 荧光数据导出数据整合脚本


    PAM 2500导出的数据是以分号为分隔符的纯文本,且一次测量单独保存在文件里,默认以日期加括号里的序号为文件名,我们只需要其中的Fo、Fm和最后一次的数据。

    原始数据如下:

     1 "t";"Date";"Time";"No.";"ML";"Temp.";"PAR";"F";"Fm'";"~Fo'";"Y(II)";"Y(NPQ)";"Y(NO)";"NPQ";"qN";"qP";"qL";"ETR";"";
     2        7;28.12.18;17:46:40;Type: IC 
     3        9;28.12.18;17:46:41;default_90.par*
     4        7;28.12.18;17:46:40;1;2; 0.0;0;Fo: 0.548;Fm: 3.018
     5        7;28.12.18;17:46:40;1;2; 0.0;0;0.548;3.018;0.548;0.818;0.000;0.182;0.000;0.000;1.000;1.000;  0.0;;
     6       27;28.12.18;17:47:00;2;2; 0.0;319;2.926;2.979;0.547;0.018;0.013;0.970;0.013;0.071;0.023;0.005;  2.4;;
     7       47;28.12.18;17:47:20;3;2; 0.0;319;2.733;2.891;0.544;0.055;0.040;0.906;0.044;0.182;0.078;0.025;  7.3;;
     8       67;28.12.18;17:47:40;4;2; 0.0;319;2.724;2.797;0.540;0.026;0.071;0.903;0.079;0.279;0.041;0.015;  3.5;;
     9       87;28.12.18;17:48:00;5;2; 0.0;319;2.563;2.661;0.535;0.037;0.114;0.849;0.134;0.274;0.055;0.019;  4.9;;
    10      107;28.12.18;17:48:20;6;2; 0.0;319;2.370;2.529;0.529;0.063;0.152;0.785;0.193;0.273;0.089;0.027;  8.4;;
    11      127;28.12.18;17:48:40;7;2; 0.0;319;2.168;2.396;0.523;0.095;0.186;0.718;0.260;0.299;0.132;0.040; 12.7;;
    12      147;28.12.18;17:49:00;8;2; 0.0;319;1.992;2.293;0.518;0.131;0.209;0.660;0.316;0.325;0.181;0.057; 17.6;;
    13      167;28.12.18;17:49:20;9;2; 0.0;319;1.848;2.213;0.514;0.165;0.223;0.612;0.364;0.357;0.230;0.078; 22.1;;
    14      187;28.12.18;17:49:40;10;2; 0.0;319;1.729;2.157;0.511;0.198;0.229;0.573;0.399;0.377;0.278;0.099; 26.6;;
    15      207;28.12.18;17:50:00;11;2; 0.0;319;1.642;2.124;0.509;0.227;0.229;0.544;0.421;0.394;0.322;0.123; 30.4;;
    16      221;28.12.18;17:50:14;File: I_181228_174633.PWS

    我们需要以提取第3行和第15行的数据整合成一个新的文件,我们把所有需要整合的文件放在同一文件夹下,运行脚本如下:

    use strict;
    use warnings;
    
    
    my @dir;
    my @myfiles;
    open OUT, ">result.csv";
    opendir (DIR, "./") or die "cannot open this directory";
    @dir = readdir DIR;
    foreach my $file (@dir){
        if ($file =~ /.*\.CSV/){
            push @myfiles, $file;
        }
    }
    close(DIR);
    
    foreach my $file (@myfiles){
        open IN, "<".$file or die "cannot open $file";
        my @lines = <IN>;
        chomp @lines;
        my @F_start = split(/;/, $lines[4]);
        my @F_end = split(/;/, $lines[15]);
        print OUT $file.",".substr($F_start[7],4,).",".substr($F_start[8],4,).",".join(",",@F_end)."\n";
        close(IN);
    }
    
    close(OUT);

    手动加入表头行即可,新结果如下:

    1 FileName,No,Fo,Fv,Fv/Fm,t,Date,Time,No.,ML,Temp.,PAR,F,Fm',~Fo',Y(II),Y(NPQ),Y(NO),NPQ,qN,qP,qL,ETR
    2 20181227_2(7).CSV,NX08,0.493,2.65,0.813962264,207,27.12.18,20:07:20,11,2,0,444,1.466,2.036,0.467,0.28,0.167,0.553,0.302,0.325,0.391,0.155,52.2
    3 20181227_2(8).CSV,NX08,0.512,2.751,0.81388586,207,27.12.18,20:11:29,11,2,0,444,1.652,2.169,0.488,0.238,0.161,0.601,0.268,0.297,0.329,0.119,44.4
    4 20181227_2(9).CSV,NX08,0.502,2.596,0.806625578,207,27.12.18,20:15:46,11,2,0,444,1.502,1.982,0.474,0.242,0.179,0.579,0.31,0.327,0.341,0.13,45.2
    5 20181228(13).CSV,NX09,0.499,2.817,0.8228612,207,28.12.18,17:26:43,11,2,0,319,1.296,2.091,0.47,0.38,0.16,0.46,0.347,0.34,0.519,0.224,50.9
    6 20181228(14).CSV,NX09,0.512,2.713,0.811279027,207,28.12.18,17:30:48,11,2,0,319,1.523,2.111,0.486,0.279,0.16,0.561,0.285,0.314,0.389,0.154,37.3
    7 20181228(15).CSV,NX09,0.505,2.823,0.821112292,207,28.12.18,17:35:16,11,2,0,319,1.371,2.21,0.481,0.38,0.135,0.486,0.277,0.299,0.516,0.22,50.9

    随后可以导入到R中进行统计学分析,比如求各组的平均值,如下

    mean <- tapply(data$Fv.Fm,data$No,mean)
    

     

    版本更新(自动加入表头)

    use strict;
    use warnings;
    
    
    my @dir;
    my @myfiles;
    open OUT, ">result.csv";
    opendir (DIR, "./") or die "cannot open this directory";
    @dir = readdir DIR;
    foreach my $file (@dir){
        if ($file =~ /.*\.CSV/){
            push @myfiles, $file;
        }
    }
    close(DIR);
    
    my $head = "FileName,Fo,Fm,t,Date,Time,No.,ML,Temp.,PAR,F,Fo',Fm',~Fo',Y(II),Y(NPQ),Y(NO),NPQ,qN,qP,qL,ETR";
    print OUT $head."\n";
    
    foreach my $file (@myfiles){
        open IN, "<".$file or die "cannot open $file";
        my @lines = <IN>;
        chomp @lines;
        my @F_start = split(/;/, $lines[2]);
        my @F_end = split(/;/, $lines[12]);
        print OUT $file.",".substr($F_start[7],4,).",".substr($F_start[8],4,).",".join(",",@F_end)."\n";
        close(IN);
    }
    
    
    close(OUT);
    
  • 相关阅读:
    hdu4280 Island Transport(最大流Dinic数组模拟邻接连边)
    hihoCoder1378 (最大流最小割)
    单聊语音
    Mybatis批量更新数据
    mysql 之 MRR
    Intellij IDEA 快捷键整理
    SpringBoot 整合 Swagger2 使用教程
    jdk/dubbo spi
    redis问题(待解决)
    JVM调优心得
  • 原文地址:https://www.cnblogs.com/liulele/p/10200468.html
Copyright © 2020-2023  润新知