Bioinfocoder has asked for the wisdom of the Perl Monks concerning the following question:
whose fields will get populated by user input on command line eg[module1] ;;path to speedseq package binary directory $;SPEEDSEQ_BIN_DIR$; = /usr/local/packages/ ;;Sequence file 1 $;Seq1File$; = ;;Sequence file 2 $;Seq2File$; = ;;Read Group $;Read_Group$;='@RG\tID:NA12878\tSM:NA12878\tPL:ILLUMINA\tLB:NA12878\t +PU:NA12878' ;;Reference $;Reference$; = [module2] ;;Output Chromosome $;Chromosome$; = ;;use --v for verbose summary $;OTHER_ARGS$; = --v
perl script.pl template.config --seq1 USER_INPUT.txt --Seq2 USER_INPT2.txt --Ref USER_INPUT_REF.txt --chr_list USER_INPUT_CHR.txt
and it will output a populated a new config file like -
[module1] ;;path to speedseq package binary directory $;SPEEDSEQ_BIN_DIR$; = /usr/local/packages/ ;;Sequence file 1 $;Seq1File$; = "USER_INPUT.txt" ;;Sequence file 2 $;Seq2File$; = "USER_INPT2.txt" ;;Read Group $;Read_Group$;='@RG\tID:NA12878\tSM:NA12878\tPL:ILLUMINA\tLB:NA12878\t +PU:NA12878' ;;Reference $;Reference$; = "USER_INPUT_REF.txt" [module2] ;;Output Chromosome $;Chromosome$; = "USER_INPUT_CHR.txt" ;;use --v for verbose summary $;OTHER_ARGS$; = --v
I tried with hash also, but that is not keeping the output order same as in the input file. I would really appreciate if anyone can provide suggestions on how to approach this.
Here is my Code -
Thanks!my ($template_name, $Prefix, $Seq1File,$Seq2File,$Align_Reference,$Chr +omosome_list,$Reference,$KnownSites ) = @ARGV; GetOptions ('template_config=s' => \$template_name, 'Project=s' => \$P +refix, 'Fasta_seq1=s' => \$Seq1File, 'Fasta_seq2=s' => \$Seq2File, 'R +ef_align=s' => \$Align_Reference, 'Chr_list=s' => \$Chromosome_list, +'Ref=s' => \$Reference, 'Sites=s' => \$KnownSites); open my $in_fh, '<', $template_name; my %field = map { s/^\s+|\s*\n$//g; $_; } grep { !/^\s*#|^\s*$/ } <$i +n_fh>; close $in_fh; foreach my $spec (sort keys %field) { if($spec =~ m/Output\s+Prefix/) { $field{$spec} = $field{$spec} .= $Prefix; } elsif ($spec =~ m/Sequence\s+file\s+1/) { $field{$spec} = $field{$spec} .= $Seq1File; } elsif ($spec =~ m/Sequence\s+file\s+2/) { $field{$spec} = $field{$spec} .= $Seq2File; } elsif ($spec =~ m/Align_Reference/) { $field{$spec} = $field{$spec} .= $Align_Reference; } elsif ($spec =~ m/Chromsome\s+List\s+file/) { $field{$spec} = $field{$spec} .= $Chromosome_list; } elsif ($spec =~ m/Reference/) { $field{$spec} = $field{$spec} .= $Reference; } elsif ($spec =~ m/Known\s+sites/) { $field{$spec} = $field{$spec} .= $KnownSites; } } # Print it to an output file { #open my $output_file = './test_processing.txt'; open my $out_fh, '>', './complete_nicu.txt'; foreach my $key (keys %field) { print $out_fh "$key\n"; print $out_fh "$field{$key}\n"; print "$field{$key}\n"; } close $out_fh; }
|
|---|