3
$\begingroup$

I tried to subset the dataframe in R since there are empty space after each line in the sequence which shows 'NA' when i read the files into R ,as a result of which when i subset it just takes the sequence Protein_IDS and sequence line by line not as whole

Im looking for this Protein_ID in one column and respective sequence in other

Proteins_IDs                Sequence                                                    
  <chr>                       <chr>                                                       
1 fig|6666666.151743.peg.5284 MERQAVAVVFHDWRRAIQQRNKTAAADRGVDPVGVGHNSKIESLQPRSSVCRASLIQVPG
2 NA                          RLLNGEIFYSLAEAKVLIEAWRRHYNTVRPHSSLGYRPPAPETATPPYPASGSASLHLRP
3 NA                          DMAAMGLIH                                                   
4 NA                          NA                                                          
5 fig|6666666.151743.peg.5285 MIDRQTAQVRRWSFVLGSSIAAMAAASATPAWAQCSPDPTVADSVTNCTGTDSDGLRVTT
6 NA                          DGSMVEVAPSASVSGAGAAAITVDIAPVSGSYYARKATINVGGSVDGGTQSGISVLSGSV

So i have made another file with list of protein ID which i want to subset from this file..I tried removing empty space from the file but couldn;t as it the sequence should come in one line but instead there is line break

data files

I tried this SEQ <- inner_join(seq,protein_id) whose output is this its like each ID is associated with multiple sequence

fig|6666666.151743.peg.5044 MTKNTIHRTILVCASLIAMPAMAQGTTEAGQEGASLADIVVTAQRRSENLQNVPISVTAI
2 fig|6666666.151743.peg.5063 MTVEQALARMLEGTGLEAQRLSPTAYRLVQAAPPASRRDPVRPAPPLPPEGSVDIIVTGT
3 fig|6666666.151743.peg.5135 MLRVADGYVEEAADDAIVPSPAVPLSVPSAPVRFEAAPARYGARRGPNVPAILVIVLLHA
$\endgroup$
2
  • $\begingroup$ It is very hard to understand your question. Please try to formulate the question, by telling what you have, what you want and what you have tried (including code). $\endgroup$
    – benn
    Nov 30 '18 at 12:02
  • $\begingroup$ edited the question $\endgroup$
    – kcm
    Nov 30 '18 at 12:11
5
$\begingroup$

I want to advise you to use FASTA format, instead of obscure unknown formats. In R, there are many packages that can handle FASTA format and it is therefore more convenient. I will show you how to make a FASTA file from your data, and then I will show an example of how to import such a FASTA file and sub select your proteins of interest.

input <- scan("seq2.txt", what = character(), sep = "\t")
length(input)
new <- gsub("f", ">f", input[-1:-2])
write.table(new, "seq2.fasta", quote = F, row.names = F, col.names = F)

library(seqinr)
fasta.file <- read.fasta("seq2.fasta", seqtype = "AA", as.string = TRUE)
prot.id <- scan("protein_id.txt", what = character(), sep = "\t")
selection <- fasta.file[names(fasta.file) %in% prot.id]
length(selection)
[1] 87

head(selection, 2)
$`fig|6666666.151743.peg.5044`
[1] "MTKNTIHRTILVCASLIAMPAMAQGTTEAGQEGASLADIVVTAQRRSENLQNVPISVTAITSEQAIKLGITQPDVIAQMVPGLQLNHSAWGLTPFLRGVGTNSVAIGNEPAVALFVDDVYLPTGSAGVFQLNSISSIEVLKGPQGTLFGRNATGGVIHIRTRDPSFDPSASATASYGNYDTISGQLYGSTGLTDTVAINFALQGIDQRKGWGVNGTTGNEANSMSGWGGRAKLLWNMGEETSLLVAGSYDRRSSDQGQPGRSIAGTFTRDGYSADAAGLGFYDVMSNLDTVQKSTTRSLSGKLTHDFGSARLVLISAFSKTVVDPVVSDSDGSPSPFFQTREFAMGGRTFTQEVQLLSPEGSAVKWILGAFYLHDRSFMDATYEGQAFGTSKSHTDAVQRTNSIAGFGQVTTEILPRTNLTLGLRYTSDRRSLDAVARLLPATGAAVTFGPFEDAKTFNSVTGRASIDHHFSDDLMGYIAYNRGFKSGIYNFTGIVAGTTTLPPPVNPETLDAYTIGFKSEFLNRRLRVNAEAFLYEYSDLQVQIVLPTGTTLTNASKATIKGIDFEISAIPVRNLTVSASIGLLDGRYKDFRNAPSFFLLPPNAPTPYDPARCSGPNPYPAVQGSAPATQRSCDVSGNRLIQAPPFSSNLQLLYTLPTDLGDFDLSASWAHGGNYEYDVFSSPLTRQPRTDIVNGSVQWTAPGGTFNVRLWANNLTGEKYYTIATTGSTAGAKYAAAAPRTYGVTLGANF"
attr(,"name")
[1] "fig|6666666.151743.peg.5044"
attr(,"Annot")
[1] ">fig|6666666.151743.peg.5044"
attr(,"class")
[1] "SeqFastaAA"

$`fig|6666666.151743.peg.5063`
[1] "MTVEQALARMLEGTGLEAQRLSPTAYRLVQAAPPASRRDPVRPAPPLPPEGSVDIIVTGTKREEPLARLPISVAIVQAPGEQGGALLPGTEEVAQRLDGLTLTNLGPGRNRQFIRGVADSPFNGNSQSTVAILINDARATYNAPDPDLKLVDVERVELLKGPQGSLYGTGTLGGVYHIVTRPPDAGSFAAMAGMGASLATHGEMGGSAEAMVNLPVVADRLALRAVAYAVREPGWIDTAGRGDANRGELRGGRVALRALAGDWTVDLNGMAQMRDVADSQYVYARHALERPAQPAEPHDNDFALMALRVAGKLGGADLVYAGNWVDHDVSSTLDASDLSASAFGIAPPALYLEQRRNRLFDQEVRLSQTRDDGLSWLAGLSFVDVRNHLSGVVRGVRDETVGTGIQGVVEFSAFGDMRMPLTGALSLSVGGRLFHSRIEEEQGARHARIEASVARSGFTPSLALSWQAGAHDFLYARYAGALRPGGLSRTGAASAERFESDELQTVEMGWRHSASAWLTVNLDAFLTTWSHMQSDYLLADGLIGTRNVGDARIRGVEASVDWKPAAGWAISAGLVGQSALLTRTNEGLRLEDRHLPVVPDWKARFGVNRHFDLSGWSGSMGVNLAYLGPSRLSFDPGLDRRMGDYALANADLALRRKDWSIRLSGSNLLDCKADSFAFGNPFALARGTQYTPLRPRQWAIGFTKNW"
attr(,"name")
[1] "fig|6666666.151743.peg.5063"
attr(,"Annot")
[1] ">fig|6666666.151743.peg.5063"
attr(,"class")
[1] "SeqFastaAA"
$\endgroup$
5
  • $\begingroup$ looks like its bit more complicated than i thought let me run ,do you have a sed or awk ways to get around this file format? $\endgroup$
    – kcm
    Nov 30 '18 at 13:54
  • 1
    $\begingroup$ No, like I said: I advice you to USE the fasta file format because you can use a lot of tools for your purposes instead of reinventing the wheel with your own format. $\endgroup$
    – benn
    Nov 30 '18 at 13:58
  • $\begingroup$ how did you write the selection object into a file as the object is list .."Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors) : cannot coerce class ‘"SeqFastaAA"’ to a data.frame" $\endgroup$
    – kcm
    Nov 30 '18 at 14:06
  • $\begingroup$ able to write it...and im really glad for your help..... $\endgroup$
    – kcm
    Nov 30 '18 at 14:17
  • 1
    $\begingroup$ Great to hear, good luck with the analysis. $\endgroup$
    – benn
    Nov 30 '18 at 16:28

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.