0
$\begingroup$

I have two separate files A and B of more than 100000 records of protein sequences. Now I need to find the sequences that are in A but not in B. Both files are in text format. Each ID and Sequence is separated by new line character. I tried making pandas data frame and finding the difference but couldn't make it work.

File A:

>Q63544|9
----------------------MDVFKKGFSIAREGVVGAVEKTKQGVTEAAEKTKEGVMY
>Q63544|51
KTKQGVTEAAEKTKEGVMYVGTKTKGERGTSVTSVAEKTKEQANAVSEAVVSSVNTVATKT
>Q63544|54
QGVTEAAEKTKEGVMYVGTKTKGERGTSVTSVAEKTKEQANAVSEAVVSSVNTVATKTVEE
>Q63544|67
VMYVGTKTKGERGTSVTSVAEKTKEQANAVSEAVVSSVNTVATKTVEEAENIVVTTGVVRK
>Q63544|72
TKTKGERGTSVTSVAEKTKEQANAVSEAVVSSVNTVATKTVEEAENIVVTTGVVRKEDLEP
>Q63544|73
KTKGERGTSVTSVAEKTKEQANAVSEAVVSSVNTVATKTVEEAENIVVTTGVVRKEDLEPP

File B:

>Q63544|51
KTKQGVTEAAEKTKEGVMYVGTKTKGERGTSVTSVAEKTKEQANAVSEAVVSSVNTVATKT
>Q63544|54
QGVTEAAEKTKEGVMYVGTKTKGERGTSVTSVAEKTKEQANAVSEAVVSSVNTVATKTVEE
>Q63544|67
VMYVGTKTKGERGTSVTSVAEKTKEQANAVSEAVVSSVNTVATKTVEEAENIVVTTGVVRK
>Q63544|73
KTKGERGTSVTSVAEKTKEQANAVSEAVVSSVNTVATKTVEEAENIVVTTGVVRKEDLEPP

What I need: A-B

>Q63544|9
----------------------MDVFKKGFSIAREGVVGAVEKTKQGVTEAAEKTKEGVMY 
>Q63544|72
TKTKGERGTSVTSVAEKTKEQANAVSEAVVSSVNTVATKTVEEAENIVVTTGVVRKEDLEP

Any help or suggestion would be appreciated.

$\endgroup$

1 Answer 1

1
$\begingroup$

You can do this very easily using python sets as follows:

with open("file_a.txt", "r") as f:
    data_a = f.read().splitlines()

with open("file_b.txt", "r") as f:
    data_b = f.read().splitlines()

set(data_a) - set(data_b)

# {'----------------------MDVFKKGFSIAREGVVGAVEKTKQGVTEAAEKTKEGVMY',
#  '>Q63544|72',
#  '>Q63544|9',
#  'TKTKGERGTSVTSVAEKTKEQANAVSEAVVSSVNTVATKTVEEAENIVVTTGVVRKEDLEP'}
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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