Hello,

I want to extract some specific strings in csv file, using either excel, R or Python.

for example as below: I want to find string from column A in column B and return in column C with 5 amino acid before and after **N**; thanks!!

```
A           B                                                       C
INETTDFR    MHRFLLMLLFPFSDNRPMMFFRSFIVFFFLIFFASNVSSRKQTYVIHT        IVGKINETTDF
            VTTSTKHIVTSLFNSLQTENINDDDFSLPEIHYIYENAMSGFSATLTDDQLDT
            VKNTKGFISAYPDELLSLHTTYSHEFLGLEFGIGLWNETSLSSDVIIGLVDTG
            ISPEHVSFRDTHMTPVPSRWRGSCDEGTNFSSSECNKKIIGASAFYKGYE
            SIVGKINETTDFRSTRDAQGHGTHTASTAAGDIVPKANYFGQAKGLASGM
            RFTSRIAAYKACWALGCASTDVIAAIDRAILDGVDVISLSLGGSSRPFYVDP
            IAIAGFGAMQKNIFVSCSAGNSGPTASTVSNGAPWLMTVAASYTDRTFPAIV
            RIGNRKSLVGSSLYKGKSLKNLPLAFNRTAGEESGAVFCIRDSLKRELVEGK
            IVICLRGASGRTAKGEEVKRSGGAAMLLVSTEAEGEELLADPHVLPAVSLGF
            SDGKTLLNYLAGAANATASVRFRGTAYGATAPMVAAFSSRGPSVAGPEIAKP
            DIAAPGLNILAGWSPFSSPSLLRSDPRRVQFNIISGTSMACPHISGIAALIKSV
            HGDWSPAMIKSAIMTTARITDNRNRPIGDRGAAGAESAATAFAFGAGNVDPT
            RAVDPGLVYDTSTVDYLNYLCSLNYTSERILLFSGTNYTCASNAVVLSPGDLN
            YPSFAVNLVNGANLKTVRYKRTVTNVGSPTCEYMVHVEEPKGVKVRVEPKVL
            KFQKARERLSYTVTYDAEASRNSSSSSFGVLVWICDKYNVRSPIAVTWE
```
Something like this should get you started. I haven't tested this, though, and you may need to change `delimiter` and `quotechar` parameters based on what your input and output look like:

```
#!/usr/bin/env python

import csv
import sys

padding = 5
assert padding >= 0, 'padding is less than zero, which does not make sense'

residues_of_interest = 'N'
roi_length = len(residues_of_interest)

csv_writer = csv.writer(sys.stdout, delimiter=',', quotechar='\"', quoting=csv.QUOTE_ALL)
for row in csv.reader(iter(sys.stdin.readline, ''), delimiter=',', quotechar='\"'):
    A = row[0]
    B = row[1]
    pos_roi_in_A = A.find(residues_of_interest)
    if pos_roi_in_A == -1:
        continue  # skip over lines where residues-of-interest string is not in A
    pos = B.find(A) + pos_roi_in_A  # anchor 'pos' value on the start position of ROI
    lower_bound = padding
    upper_bound = len(B) - padding
    #
    # consider four cases of a bounded string search result
    #
    if pos == -1:
        C = None
    elif pos < lower_bound:
        C = B[0:(pos + roi_length + padding)]
    elif pos > upper_bound:
        C = B[(pos - padding):upper_bound]
    else:
        C = B[(pos - padding):(pos + roi_length + padding)]
    #
    # write A, B and C to standard output
    #
    csv_writer.writerow([A, B, C])
```

You might run it like so:

    $ padded_substring_finder.py < in.csv > out.csv