perl - Comparing FILE1 value to FILE2 range and printing matches -


I am very new to Pearl and I am working on a bioinformatics project at the university. I have a list of conditions in FILE1, in format:

  99269 550 100 126477 1700  

and format in the FILE2:

  517 1878 forward 700 2500 forward 2156 3289 forward 99000 100000 forward 22000 23000 backward  

I want to compare the values ​​in FILE1 to each position at FILE2, and if the situation If I fall into any of the categories, I want to print the position, boundary and direction.

Then my expected output would be:

  99269 99000 100000 forward 550 517 1878 forward 1700 517 1878 forward  

Will not run with errors, but it does not produce any information, so I'm unsure where I'm going wrong! When I divide the last 'if' rule, then it will only work if the situation is at the exact same line.

My code is as follows:

  #! Strict use of USR / Bin / Pearl; Use warnings; My $ outputfile = "/ user / adverb / documents / CC 22 CDSTPT"; Open FILE1, "/ User / EdwardTechnical / Documents / CC 22 Position. Txt" or Die "can not open; CC 22: $!" ;; Open FILE2, "/ User / EdwardTextical / Documents / CDCPiption. Txt" or Die "Can not Open; CDS: $!"; Open (Output file, "> $ outputfile") or die "Output file can not be opened: $! \ N"; While (& lt; FILE1 & gt;) {if (/ ^ (\ d +) /) {my $ CC22 = $ 1; While (& lt; FILE2 & gt;) {if (/ ^ (\ d +) \ s + (\ d +) \ s + (\ S +) /) {my $ CDS1 = $ 1; My $ CDS2 = $ 2; My $ CDS3 = $ 3; If ($ CC22 & $; CDS1 & amp; $ CC22 & lt; $ CDS2) {Printed OUTPUTFILE "$ CC22 $ CDS1 $ CDS2 $ CDS3 \ n"; }}}}} Closed (FILE1); Close (make 2);  

I have posted.

Because you are only reading FILE2 once it is only compared with the first line of FILE1

The subsequent rows are compared to the closed file

Hiding the rows from FILE1 in an array and then comparing each row in FILE2, each array entry, as shown below

  #! Use / usr / bin / perl strict; Use warnings; My $ outputfile = "out.txt"; Open FILE1, "file1.txt" or die "can not open, gt22: $!" ;;; Open FILE2, "file2.txt" or die "can not open; cds: $!" ;; Open (Output file, "> $ outputfile") or die "Output file can not be opened: $! \ N"; My @ file1list = (); While (& lt; FILE1 & gt;) {if (/ ^ (\ d +) /) {push @ file1list, $ 1; }} While {& lt; FILE2 & gt;) {if (/ ^ (\ d +) \ s + (\ d +) \ s + (\ S +) /) {my $ CDS1 = $ 1; My $ CDS2 = $ 2; My $ CDS3 = $ 3; {If ($ CC22 & $; CDS1 & amp; amp; $ CC22 & lt; $ CDS2) for my $ CC22 (@ file1list) {Printed OUTPUTFILE "$ CC22 $ CDS1 $ CDS2 $ CDS3 \ n"; }}}  

(There are stylish issues with this program (like capital letters for variables) but I ignored them, this is a good program for beginners)


Comments

Popular posts from this blog

winforms - C# Form - Property Change -

java - Messages from .properties file do not display UTF-8 characters -

javascript - amcharts makechart not working -