Hi All
I have a question.
I would like to edit some string characters by replacing with characters of choice located in another file. For example in sample file
excluding the first line beginning with ">" I would like to change string elements at position 10 which is N to T, at position 100 which is T to C and at position 157 which is an A to G in the above example based on information present in the following file:
Can anyone suggest how I can do this, preferably using Perl as I'm learning that. I would like to perform this over multiple files and thus I'll really appreciate your input.
Hv a nice day:)
Cheers
map function is used to create hash from the contents of @b array (which contains lines from postion_file). When map is executed, its code is run for each element of the @b array. When processing those elements, they are assigned into "$_" variable inside "map" block, so (split /\s+/)[1] and (split /\s+/)[2] operate on them, extracting second and third field (position and letter) from each line. Those two elements are then returned by map into %h hash, populating it with position as the key and the letter begin its value.
About second part of your question, which built-in variables do you have in mind?
Thanks Bartus ... your explanation was clear ... actually the $/ variable you have already described in another post so its fine ... Could you remind me again the $& variable please? I guess I can find it on perlvar too, but in this context will be nice to hear from you.
Related to this question what if instead of replacing the characters I had to insert or delete the position_file letters in the original file ?? What could be changed in the code to do that ?? I'm imagining a push/pop function somewhere but could you enlighten me on this when you have a few moments?
Cheers and thanks for all your help always.
Hv a nice day:)
$& holds string that was matched by last regex, so in s/.{100}/$&\n/g; it will contain hundred characters, to which newline is then appended. It is done to restore your formating of hundred chars per line. As for the changes in behavior of the script, to delete characters on positions stored in "position file", substitute
$F[$i-1]=$h{$i}
with
$F[$i-1]=""
To insert characters at specified positions, substitute the same line with: