This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Splitting NCBI Accession ID

Hi,

I have a file 'ids.txt' containing IDs like this:

gi|78062356|ref|YP_372264.1|

gi|206563435|ref|YP_002234198.1|

gi|402568881|ref|YP_006618225.1|

gi|54024439|ref|YP_118681.1|

gi|146275970|ref|YP_001166130.1|

How can I have them into two columns one having the gi's and the other having all the ref's like as shown below?

78062356       YP_372264.1

206563435     YP_002234198.1

402568881     YP_006618225.1

54024439       YP_118681.1

146275970     YP_001166130.1

Preferably in R or Python.

blast ncbi accessionid r python

4 answers

Python version:

f1=open('text.txt')
for line in f1:
    old=line.rstrip('\n').split("|")
    gi=old[1]
    acc=old[3]
    print(gi+'\t'+acc)

f1.close()
cut -d'|' -f2,4 ids.txt | tr '|' '\t'

Worked perfectly. Thanks!

Preferably in R or Python.

When you specify a requirement like you should also say if this is an assignment question. If not, this can be easily done using shell (awk -F '|' '{print $2"\t"$4}' your_file > new_file).

Worked perfectly! Thanks!

Sorry I didn't get you about the assignment question.

People sometimes ask for solutions in a specific language if they are looking for answers to assignment/homework questions.

Simple sed solution:

sed -e 's/gi|//g;s/|[a-z]*|/\t/g' inputfile.txt

Log in to answer this question.