forked from AprilJack/igc_script_backup
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGFFtoGTF.java
More file actions
executable file
·63 lines (56 loc) · 1.62 KB
/
GFFtoGTF.java
File metadata and controls
executable file
·63 lines (56 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import java.io.File;
import java.io.FileNotFoundException;
import java.util.HashSet;
import java.util.Scanner;
public class GFFtoGTF {
public GFFtoGTF(String[] args)
{
if(args.length < 2)
{
System.err.println("Usage: GFFtoGTF GFF3file feature1 [feature2] ... > output.gtf\n"
+ "ex: GFFtoGTF annotation.gff exons transposable_elements tRNA > output.gtf\n"
);
System.exit(1);
}
HashSet<String> features = new HashSet<String>();
for(int i = 1; i < args.length; i++)
features.add(args[i]);
try {
Scanner s = new Scanner(new File(args[0]));
while(s.hasNextLine())
{
String line = s.nextLine();
String[] split = line.split("\t");
if(split.length > 1)
{
if(features.contains(split[2]))
{
//feature of interest... lets output in GTF format!
String[] info = split[8].split(";");
String gene_id = "";
String description = "";
for(String str: info)
{
if(str.startsWith("ID=")||str.startsWith("Parent="))
gene_id = str.split("=")[1].split(":")[0].trim();
else
{
//description+= str.split("=")[0].trim()+"=\""+str.split("=")[1].trim()+"\"; ";
description+= str;
}
}
System.out.println(split[0]+"\t"+split[1]+"\t"+split[2]+"\t"+split[3]+"\t"+split[4]+"\t.\t"+split[6]+"\t0.0\tgene_id \""+gene_id+"\"; transcript_id \""+gene_id+"\"; "+description);
}
}
}
s.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new GFFtoGTF(args);
}
}