SixTheCat has asked for the wisdom of the Perl Monks concerning the following question:
rs6413438,CYP2C19_10
rs4986910,CYP2C19_20
The output looks something like this--------- Converting Star Allele references to rs numbers ---------
Current input line is
Index 0 is rs6413438
Index 0 is rs6413438 is stored as rs6413438 <-- Correct display
Index 1 is CYP2C19_10
Index 1 is CYP2C19_10
is stored as CYP2C19_10 <--- WTF, where is the first variable?
Comparing CYP2C19_10
and CYP2C19_10
Comparing CYP2C19_10
and CYP2C19_12
Current input line is
Index 0 is rs4986910
Index 0 is rs4986910 is stored as rs4986910 <-- Correct display
Index 1 is CYP2C19_20
Index 1 is CYP2C19_20
is stored as CYP2C19_20 <--- WTF
Comparing CYP2C19_20
and CYP2C19_10
Comparing CYP2C19_20
and CYP2C19_12
-------------- Done converting Star Allele references -------------
#!perl use strict; use 5.010; my $STARFile; + # File handle to reference file my @Stars; $Stars[0] = "CYP2C19_10"; + # Mock array of values to cross reference $Stars[1] = "CYP2C19_12"; + # if(@Stars==0){return;} + # If no Star Alleles were specified then no n +eed to do this so return to the main body if(! open $STARFile,"<","test.csv"){die "Reference file could not be f +ound or could not be opened.";} # Open the Star reference file to +prepare to convert information and store the file handle to $STARFile +. print "Converting specified Star Designations to SNPs..."; # The conversion table is opened so convert the Star name to rs number +s and then store the rs numbers to the @SNPs array and the correspond +ing Star name to the @Stars array at the same index. my @SNPs; my @StarsCon; my $RefIndex; + # Holds the line in the reference table file my $StarIndex; + # Holds the index of the @Stars Array that is + being checked my $tmpSNPIndex; + # Holds the index in the @SNPs array that we ar +e comparing my $tmpStar; + # Holds the Star Allele name my $tmpRS; + # Holds the SNP's rs number my @tmpConv; + # Holds the split Star and rs numbers say "\n--------- Converting Star Allele references to rs numbers ----- +----"; while (<$STARFile>){ + # Input a line from the database and as long a +s we haven't reached the end of the file chomp; + # Remove the trailing newline say "Current input line is @_"; @tmpConv = split ",",$_; + # Split the CSV line from the reference table s +uch that @tmpConv[0] = Star name and @tmpConv[1] = rs number $tmpStar = $tmpConv [1]; $tmpRS = $tmpConv[0]; say "Index 0 is $tmpConv[0]"; + # Displays correctly say "Index 0 is $tmpConv[0] is stored as $tmpRS"; + # Displays correctly say "Index 1 is $tmpConv[1]"; + # Displays correctly say "Index 1 is $tmpConv[1] is stored as $tmpStar"; + # Displays INcorrectly for($StarIndex=0;$StarIndex<@Stars;$StarIndex++){ say "Comparing $tmpStar and $Stars[$StarIndex]"; if($tmpStar eq $Stars[$StarIndex]){ + # If the current line of the database file c +ontains the Star Allele rs number then $tmpSNPIndex = @SNPs; + # Get the number of entries in the @SNPs array +. say "1. $tmpRS was converted from $tmpStar"; say "2. $tmpStar was converted to $tmpRS"; say "3. $tmpStar was converted to $tmpRS"; say "4. $tmpRS was converted from $tmpStar"; push @StarsCon, $tmpStar; + # Add the Star allele name to the @StarsCon ar +ray push @SNPs, $tmpRS; + # Add the new rs number to the @SNPs array if(@Stars>0){ + # If we have more than one SNP then splice @Stars,$StarIndex,1; + # and @Stars array }else{ + # Otherwise Pop off the last one pop @Stars; + # } last; + # Exit the for loop } } if(! @Stars>0){last;} + # If that was the last entry then stop searchi +ng } say "-------------- Done converting Star Allele references ----------- +--"; if(@Stars>0){ + # If any SNPs have not been found then say "\n"."Conversions not completed: @Stars."; + # Inform the user which ones were not found }else{ + # Otherwise say "\n"."All conversions successful."; + # Inform the user that all were found } close $STARFile; + # Close the reference file print "Done!\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Variable blasphemy
by BrowserUk (Patriarch) on Jul 24, 2015 at 15:04 UTC | |
by SixTheCat (Novice) on Jul 24, 2015 at 15:08 UTC | |
by SixTheCat (Novice) on Jul 24, 2015 at 15:12 UTC | |
by poj (Abbot) on Jul 24, 2015 at 15:38 UTC | |
by SixTheCat (Novice) on Jul 24, 2015 at 15:51 UTC | |
by GotToBTru (Prior) on Jul 24, 2015 at 16:36 UTC | |
by SixTheCat (Novice) on Jul 24, 2015 at 15:49 UTC | |
by Monk::Thomas (Friar) on Jul 24, 2015 at 15:55 UTC | |
|
Re: Variable blasphemy
by Laurent_R (Canon) on Jul 24, 2015 at 15:52 UTC | |
by SixTheCat (Novice) on Jul 24, 2015 at 15:54 UTC | |
by marinersk (Priest) on Jul 24, 2015 at 20:58 UTC | |
|
Re: Variable blasphemy
by Tux (Canon) on Jul 25, 2015 at 11:49 UTC | |
|
Re: Variable blasphemy
by Monk::Thomas (Friar) on Jul 24, 2015 at 15:51 UTC | |
by SixTheCat (Novice) on Jul 24, 2015 at 15:52 UTC |