0

I have two files:

File A sample

>> AT5G46880.1|PACid:19669936  
#    score  bias  c-Evalue  i-Evalue hmmfrom  hmm to    alifrom  ali to    envfrom  env to     acc
---   ------ ----- --------- --------- ------- -------    -------     -------    ------- -------    ----
1 !  276.3   0.7   5.9e-85   3.8e-82       1     231 []     317     555 ..     317     555 .. 0.96

Alignments for each domain:
== domain 1  score: 276.3 bits;  conditional E-value: 5.9e-85
         MSA_At_Os_START   1 dkslllelaleameeLlslaeeeeplWvksmdkk..pgkeslnleeylrlFeela...kkpegykseasravgvVemdpealv 78 
                             +k + +e a+++++eL +++++eeplW+k+ ++k   +  +ln eey+rlF++ +   +++ ++  eas+a++vV+m++++lv
AT5G46880.1|PACid:19669936 317 EKVIAMEFAVSCVQELTKMCDTEEPLWIKKKSDKigGEILCLNEEEYMRLFPWPMenqNNKGDFLREASKANAVVIMNSITLV 399
                             57899***************************99744445**************9999888999******************* PP

         MSA_At_Os_START  79 eilmddelanrwdelfpsiv.kastlevistgaag.ngtlelmqaelqvlsplvpaRevvflRyckq.ledgtwvvvdvsldh 158
                             + +++   a++w+e+f+siv +a+t+++is+g++g +g+l+lm+aelqvlsplvp+Re +flRy++q +e g w++vd+++d+
AT5G46880.1|PACid:19669936 400 DAFLN---ADKWSEMFCSIVaRAKTVQIISSGVSGaSGSLLLMFAELQVLSPLVPTREAYFLRYVEQnAETGNWAIVDFPIDS 479
                             *****...***********************************************************7889**********99 PP

         MSA_At_Os_START 159 knrgp...kskyvrvrllpSGclIqdlengyskvtwVeHlevdewsvkelyrpllrsglalgakrwvatLrrqcer 231
                              + +    ++  ++++++pSGc+Iqd++ngys+v wVeH+evde++v+e++ ++++sg+a+ga+rw+  L+rqcer
AT5G46880.1|PACid:19669936 480 FHDQMqpmNTITHEYKRKPSGCIIQDMPNGYSQVKWVEHVEVDEKHVHETFAEYVKSGMAFGANRWLDVLQRQCER 555
                             8777777799****************************************************************97 PP

>> AT1G73360.1|PACid:19649192  
#    score  bias  c-Evalue  i-Evalue hmmfrom  hmm to    alifrom  ali to    envfrom  env to     acc
---   ------ ----- --------- --------- ------- -------    ------- -------    ------- -------    ----
1 !  270.5   0.1   3.4e-83   2.2e-80       1     231 []     230     457 ..     230     457 .. 0.98
2 ?    1.9   0.0      0.43   2.8e+02      73      95 ..     544     566 ..     511     654 .. 0.79

Alignments for each domain:
 == domain 1  score: 270.5 bits;  conditional E-value: 3.4e-83
         MSA_At_Os_START   1 dkslllelaleameeLlslaeeeeplWvksmdkkpgkeslnleeylrlFeela..kkpegykseasravgvVemdpealveil 81 
                             dk++++ +al+ameeLl+l++++eplW+++ +++   ++lnl +y+++F++    +k++++++easr++g+V m+++alv+++
AT1G73360.1|PACid:19649192 230 DKPIMTGIALTAMEELLRLLQTNEPLWTRTDGCR---DILNLGSYENVFPRSSnrGKNQNFRVEASRSSGIVFMNAMALVDMF 309
                             7999***************************986...9***************99999************************* PP

         MSA_At_Os_START  82 mddelanrwdelfpsiv.kastlevistgaag..ngtlelmqaelqvlsplvpaRevvflRyckqledgtwvvvdvsldhknr 161
                             md     +w elfpsi+  ++tl vis+g++g  +g+l+l+++e++vlsplv +Re++ lRyc+q e+g+w+vv+vs+d ++ 
AT1G73360.1|PACid:19649192 310 MD---CVKWTELFPSIIaASKTLAVISSGMGGthEGALHLLYEEMEVLSPLVATREFCELRYCQQTEQGSWIVVNVSYDLPQ- 388
                             **...9*************************************************************************887. PP

         MSA_At_Os_START 162 gpkskyvrvrllpSGclIqdlengyskvtwVeHlevd.ewsvkelyrpllrsglalgakrwvatLrrqcer 231
                                 +  ++ ++pSGclIqd++ngyskvtwVeH+e + ++ v+elyr+++++g+a+ga rwv+tL+r+cer
AT1G73360.1|PACid:19649192 389 --FVSHSQSYRFPSGCLIQDMPNGYSKVTWVEHIETEeKELVHELYREIIHRGIAFGADRWVTTLQRMCER 457
                             ..56999******************************888*****************************97 PP

== domain 2  score: 1.9 bits;  conditional E-value: 0.43
         MSA_At_Os_START  73 dpealveilmddelanrwdelfp 95 
                             +p++++++l+d+ ++ +wd l  
AT1G73360.1|PACid:19649192 544 SPQNVFNFLKDERTRPQWDVLSN 566
                             3899*******667899*97654 PP

File B sample

AT5G46880.1
AT5G27818.1
AT5G77690.1

the desired output in this case should be

 AT5G46880.1  317     555

it should show the id and values from column 7 and 8 ie, alifrom and ali to.

Files A and B are much larger than the provided samples. What I want is match each ID line from file B to A, and if there is match in file A (ID after >>), then print the values in the alifrom and alito columns to a new file along with the id. The data alignments for each domain are not needed.

I think to first delete unnecessary data from file A and store first five lines starting from >> till Alignments for each domain then compare. but don't know how to proceed.

note: file A is not tab delimited

  • Please add to your question the desired output for the two example files you have above, so we know what format you want the output to look like. Do you want a separate file for each "id"? – jw013 May 13 '15 at 16:20
4

With the subsequent awk program:

awk '
  BEGIN             { FS = "([[:space:]]+|[|])" }
  NR==FNR           { id[$1] ; next }
  /^>>/ && $2 in id { data = $2 ; f = 1 }
  f && /^[0-9]/     { data = data " : " $10 " " $11 }
  f && !NF          { f = 0 ; print data }
' FileB FileA

you will get this output:

AT5G46880.1 : 317 555
AT1G73360.1 : 230 457 : 544 566

Note: I've added the second ID to FileB so that you can see how multiple attribute lines will be handled.

How the awk program works:

BEGIN - the field separator is defined so that we can later esily access the ID from lines starting with ">>".

NR==FNR - this is a pattern that is true while reading the first file; the ID's are stored.

/^>>/ && $2 in id - we match lines with the IDs and check whether the found ID had been memorized from the first file. The ID is saved for output and a processing flag set.

f && /^[0-9]/ - if the flag is set and we match a line starting with a digit we add the respective fields 10 and 11 to the output data (separated by a colon).

f && !NF - if the flag is set and an empty line is found then the processing is done for that block and the flag cleared.

  • 1
    First, the file order should be FileB FileA according to your script, right? Second, I think the desired fields are 10 and 11 not 7 and 8. Perhaps OP could clarify whether or not $12 should be included as well. – jw013 May 13 '15 at 16:30
  • nothing...only blank file generated – user106326 May 14 '15 at 5:05
  • @user106326; I have tested the awk program with the data you posted and it worked; the output I posted is what was shown on stdout. Please re-inspect carefully what you've done. (An empty output may be an indication of switched files A and B. - The first file argument, FileB, must contain the IDs, and the second file argument, FileA, must contain the actual data to parse.) – Janis May 14 '15 at 6:23
  • sorry for my fault. yes it works. there were some alterations in file A. it works like miracle. and thank you for the follow through of the command. thanks a lot – user106326 May 14 '15 at 10:13
0

Try this

grep -A4 -f <(sed 's/^/^>> /' fileB) fileA | 
    sed -r '/^>>/! s/(\S+\s+){8}((\S+\s+){3}).*/\2/
            s/[][>.-]*\s*//'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.