Can anyone tell me how can I do it
I have two files. file1 = 1.fasta asd is like
>123.1
tgcgtgctagctgacctgcgtgcagctgc
>123.2
tcgtcgatcgacgtgcagctgactgcttgct
>123.3
acccggtgcggggggtcgatcgacgtc
file2 = result.ods file in ubuntu and contains data as:
id seq_start_pos seq_end_pos
123.1 10 15
123.2 11 18
123.3 8 16
and I want a script which can generate output like:
seq_is small_seq large_seq
123.1 ctgac ctagctgacctgc
123.2 cgtgcagc tcgacgtgcagctgac
123.3 cggggggt ggtgcggggggtcgat
This is the proper format of result which I want. actually small seq is region between 15-10 =5 bp in seq file 1 and large seq is 4-4 bp up/downstream of the region 10-15 .
Basically I want to extract small_seq along with 4-4 bp upstream ad downstream in excel file
If anyone can provide me script for extracting this region, I shall be highly thankful to him/her.
1 answer
regions.bed
123 5 10
125 8 13
test.fasta
>123
AGTCGCTCGGCGGCTAGTCGCTCGGCGGCT
CGGCTGCGGCCGGCTGCGGCTGCGGCCGGCTG
>125
AGGATCGGCTCGGCGGAGGATCGGCTCGGCGG
CTCGGCTGCGCTCGGCTCGGCTGCGCTCGG
Using bedtools:
bedtools getfasta -fi test.fasta -bed regions.bed -fo small.fasta
awk '{ print $1"\t"$2-4"\t"$3+4}' regions.bed | bedtools getfasta -fi test.fasta -bed - -fo long.fasta
paste small.fasta long.fasta | paste - - | awk '{ gsub(">.*:",":",$2); print $1$2"\t"$3"\t"$4}'
Using pyfaidx:
from pyfaidx import Fasta
sq = Fasta("test.fasta")
flank=4
with open("regions.txt") as regions:
for line in regions:
cord=line.split()
print sq[cord[0]].name,sq[cord[0]][int(cord[1]):int(cord[2])],sq[cord[0]][int(cord[1])-flank:int(cord[2])+flank]
Note: When adding the flanking regions, make sure the coordinates don't go out of length(sequence). Otherwise the programs scold you with error messages.
Log in to answer this question.
have you tried anything from your end ? You can play around with bedtools getfasta and command
pasteto achieve what you want or if you know some python, its easy with pyfaidxI ran this commad biy it is not working
see my answer here: A: How to extract a region of protein or small domain '150-300' from a long sequenc