-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathGTF.java
More file actions
executable file
·60 lines (53 loc) · 1.5 KB
/
GTF.java
File metadata and controls
executable file
·60 lines (53 loc) · 1.5 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
import java.util.HashMap;
import java.util.LinkedList;
public class GTF {
HashMap<String,LinkedList<Annotation>> byChr = new HashMap<String,LinkedList<Annotation>>();
HashMap<String,Annotation> byId = new HashMap<String,Annotation>();
/**
* Sorts the byChr Annotations to ensure that they are ordered by their left-most coord
*/
public void sort()
{
}
public GTF(String gtfFile)
{
SuperScanner ss = new SuperScanner(gtfFile);
System.err.print("Loading "+gtfFile);
int lineCount = 0;
while(ss.hasMore())
{
lineCount++;
String line = ss.getLine();
String[] split = line.split("\t");
if(split.length > 8 && split[2].length() >0)
{
String chrStr = split[6]+split[0];
String ann = split[2];
if(ann.compareTo("exon")==0)
{
int start = Integer.parseInt(split[3].trim());
int end = Integer.parseInt(split[4].trim());
String id = split[8].replaceAll("\"", "");
id=id.replaceAll("\"", "");
id=id.substring(id.indexOf("transcript_id")+14,id.indexOf(";", id.indexOf("transcript_id")+14));
if(byId.get(id) == null)
{
Annotation an = new Annotation(chrStr,id);
an.addRegion(start, end);
if(byChr.get(chrStr)==null)
byChr.put(chrStr,new LinkedList<Annotation>());
byChr.get(chrStr).add(an);
byId.put(id, an);
an.addAnnotation(split[8]);
}
else
{
byId.get(id).addRegion(start,end);
}
}
}
if(lineCount%10000 == 0) System.err.print(".");
}
System.err.println();
}
}