This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to convert a text file into gtf file?

I am facing a problem while running feature counts as my input reference file is in text format. I would like to know a way to convert this file into gtf.

>hsa_piR_000001|gb|DQ569913|Homo sapiens:21:43519790:43519815:Plus
AAACAAACCUGACUUUGUGGGGGCGC
>hsa_piR_000002|gb|DQ569914|Homo sapiens:15:49361981:49362009:Minus
AAACAAAGAAACAGGUGGUGAGAAUGUGU
>hsa_piR_000003|gb|DQ569915|Homo sapiens:19:39999145:39999173:Minus
AAACAGAUGUGCUCAAGCUGAGUGGUCCA
>hsa_piR_000004|gb|DQ569917|Homo sapiens:2:231979486:231979511:Minus
AAACAGUGGUUACAGGGGGCUCAGAU
>hsa_piR_000005|gb|DQ569918|Homo sapiens:3:199288152:199288178:Minus
AAACAUUGAGGAUGUCUACGGCAACAC
>hsa_piR_000006|gb|DQ569921|Homo sapiens:11:13587875:13587903:Plus
AAACCGAAUAAAGUCUUCAUCUGAUGCUC
>hsa_piR_000007|gb|DQ569922|Homo sapiens:12:131188624:131188651:Minus
AAACCUACAUCCACACAGAAACGUACAC
>hsa_piR_000008|gb|DQ569923|Homo sapiens:17:362636:362661:Plus
AAACGAGGUAAUGAUCCUGGAGCCUA

This is the input text file.

Thank you in advance

rna-seq

A little bit more info would be appreciated, but maybe you can do it re-ordering the columns. See more abour the GTF format Here

1 answer

You seem to have genomic coordinates in there like 21:43519790:43519815.

You can extract them with awk into featureCount SAF format (see manual for details):

awk '{if($1 ~ /^>/) print}' test.txt \
| awk -F "sapiens:" '{print $2}' \
| awk -F ":" 'OFS="\t" {print $1"_"$2"_"$3, $1, $2, $3, $4}' \
| awk '{gsub("Plus","+");gsub("Minus","-");print}' > test.saf

Then use featureCounts to quantify bam files against that SAF file:

featureCounts -a test.saf -F SAF -o test_countmatrix.saf *.bam

Be sure though that the chromosome names in BAM and SAF have the same naming convention, so both are called e.g. 1 for chromosome one and not like 1 in the SAF and chr1 in the BAM.

Thank you for your suggestion. After running the first command that you mentioned, the resulting saf file didnot have gene_ids in it. Few lines from saf file:

21_43519790_43519815 21 43519790 43519815 + 15_49361981_49362009 15 49361981 49362009 - 19_39999145_39999173 19 39999145 39999173 - 2_231979486_231979511 2 231979486 231979511 - 3_199288152_199288178 3 199288152 199288178 - 11_13587875_13587903 11 13587875 13587903 + 12_131188624_131188651 12 131188624 131188651 - 17_362636_362661 17 362636 362661 + 19_19719474_19719504 19 19719474 19719504 - 11_111105815_111105840 11 111105815 111105840 - 16_34608961_34608986 16 34608961 34608986 + 19_1224098_1224128 19 1224098 1224128 - 9_81670460_81670490 9 81670460 81670490 -

I got chromosome number and co-ordinates but gene_id is still missing. Hope you will look into this. Thanking you in advance.

Log in to answer this question.