How to extract the shortest and the longest isoform from Trinity.fasta file?
1
0
Entering edit mode
2.8 years ago
FadyNabil ▴ 20

I have a Trinity.fasta file an I want to extract the shortest and the longest isoform from it

assembly fasta trinity • 1.1k views
ADD COMMENT
1
Entering edit mode
2.8 years ago

Hey,

samtools faidx Trinity.fasta # create an index to get the length of each sequence (length values are stored in the second column of the Trinity.fasta.fai file)

awk 'BEGIN{getline; min=$2;max=$2}
            {(min>$2)?min=$2:"";(max>$2)?"":max=$2}
       END{print min, max}' Trinity.fasta.fai # print the max and min values in the second column of  the Trinity.fasta.fai

#201 2114

awk '/^>/ {printf("\n%s\n",$0);next; } { printf("%s",$0);}  END {printf("\n");}' < Trinity.fasta > linear.fasta # linearize the Trinity.fasta
cat linear.fasta | grep -A1 'len=201' --no-group-separator > sequences_201.fasta # get the shortest sequences using the field 'len=###' in the fasta header
cat linear.fasta | grep -A1 'len=2114' --no-group-separator > sequences_2114.fasta # get the longest sequences using the field 'len=###' in the fasta header
ADD COMMENT

Login before adding your answer.

Traffic: 3030 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6