My script should do the following. It takes an old list of scalars and creates a new, matching list of numbers. The old list is called @oldMarkers and the new list is like @newMarkers.
Input Example: chr1, chr2, IMP, chr3, IMP, IMP, IMP, chr4
An example output looks like this: 1, 2, 2.1, 3, 3.1, 3.2, 3.3, 4
The point of the script is to read the @oldMarkers list and output the list, where for each instance of the element containing the letters "chr", an integer is entered into the @newMarkers array. For each IMP instance in @oldMarkers, the decimal is appended to @newMarkers. The new decimal has the same "base integer" as the previous number, but is added to it .1. In other words, it is assumed that several subsequent instances of "IMP" should have the same integer as the last record read "chr", with the decimal value referenced counts the number of IMPs that match the last "chr" record.
The script below works almost 100%. It even usually works in the following example. @OldMarkers has a lot of IMP entries in some places. If there are more than 10 IMPs in the line, then it is assumed that the code should insert values ββin @newMarkers, so that all the "IMPs" of this block of records have the same integer, which also corresponds to the number corresponding to the last one; read the "chr" instance in @oldMarkers. To this integer is added 0.1. And when the decimal value reaches 0.9, the decimals will βstartβ back to .1 and go from there, to the end of the IMP record segment.
For example, if @oldMarkers has a block of 13 "IMPs" and is:
chr1, chr2, IMP, IMP, IMP, IMP, IMP, IMP, IMP, IMP, IMP, IMP, IMP, IMP, IMP, chr2
then @newMarkers should be:
1, 2, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9, 2.1, 2.2, 2.3, 2.4, 3
Summary script:
. , . - , - "chr4" "IMP" . while , @oldMarkers.
. script , @newMarkers "chr" "IMP" @oldMarker. if else.
, , , "chr" "IMP" . if else .
@newMarker, .
, . , , IMP 10, script "" . , .1 . , 10, . "".
?
my @oldMarkers = ();
my @newMarkers = ();
while ( my $line = <$FILE> )
{
chomp $line;
my @entries = split( '\t', $line );
push( @oldMarkers, $entries[ 1 ] );
}
for ( my $i = 0 ; $i < scalar @oldMarkers ; $i++ )
{
if ( $oldMarkers[ $i ] =~ m/chr/ )
{
if ( $oldMarkers[ $i - 1 ] =~ m/IMP/ )
{
push( @newMarkers, int( $newMarkers[ $i - 1 ] ) + 1 );
}
else
{
push( @newMarkers, $newMarkers[ $i - 1 ] + 1 );
}
}
else
{
if ( $oldMarkers[ $i - 1 ] =~ m/IMP/ )
{
my $value = $newMarkers[ $i - 1 ] - int( $newMarkers[ $i - 1 ] );
if ( $value < .9 )
{
push( @newMarkers, $newMarkers[ $i - 1 ] + .1 );
}
elsif ( $value > .9 )
{
push( @newMarkers, int( $newMarkers[ $i - 1 ] ) + .1 );
}
}
else
{
push( @newMarkers, int( $newMarkers[ $i - 1 ] ) + .1 );
}
}
}
print $newMarkerfile join( "\t", @newMarkers);