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  package org.utgenome.gwt.utgb.client.bio;
26  
27  import java.io.Serializable;
28  
29  
30  
31  
32  
33  
34  
35  public class GenomeDB implements Serializable {
36  	
37  
38  
39  	private static final long serialVersionUID = 1L;
40  
41  	public static enum DBType {
42  		AUTO, BED, SAM, BAM, FASTA, DAS, CytoBand;
43  
44  		private DBType() {
45  		}
46  
47  		public static String[] getDBTypeList() {
48  			DBType[] values = DBType.values();
49  			String[] dbTypes = new String[values.length];
50  			for (int i = 0; i < values.length; ++i) {
51  				dbTypes[i] = values[i].name();
52  			}
53  			return dbTypes;
54  		}
55  
56  	}
57  
58  	
59  
60  
61  
62  
63  
64  
65  	public String path;
66  
67  	
68  
69  
70  	public String ref;
71  
72  	
73  
74  
75  	public DBType type = DBType.AUTO;
76  
77  	public GenomeDB() {
78  	}
79  
80  	protected GenomeDB(GenomeDB db) {
81  		this(db.type, db.path, db.ref);
82  	}
83  
84  	public GenomeDB(String path, String refSeq) {
85  		this(DBType.AUTO, path, refSeq);
86  	}
87  
88  	public GenomeDB(DBType type, String path, String ref) {
89  		if (type == null)
90  			type = DBType.AUTO;
91  		if (path == null)
92  			throw new NullPointerException("Database ID is null");
93  		if (ref == null)
94  			throw new NullPointerException("Reference is null");
95  
96  		this.type = type;
97  		this.path = path;
98  		this.ref = ref;
99  	}
100 
101 	@Override
102 	public String toString() {
103 		return "db(path:" + path + ", type:" + type + ", ref:" + ref + ")";
104 	}
105 
106 	public DBType resolveDBType() {
107 		return resolveDBType(this);
108 	}
109 
110 	
111 
112 
113 
114 
115 
116 	public static DBType resolveDBType(GenomeDB db) {
117 		if (db.type == DBType.AUTO) {
118 			if (db.path.endsWith(".sam"))
119 				return DBType.SAM;
120 			else if (db.path.endsWith(".bam"))
121 				return DBType.BAM;
122 			else if (db.path.endsWith(".bed"))
123 				return DBType.BED;
124 			else if (db.path.endsWith(".fa"))
125 				return DBType.FASTA;
126 			else if (db.path.endsWith(".cytoband"))
127 				return DBType.CytoBand;
128 
129 			return null;
130 		}
131 		else
132 			return db.type;
133 	}
134 
135 	public static DBType resolveDBType(String path) {
136 		if (path.endsWith(".sam"))
137 			return DBType.SAM;
138 		else if (path.endsWith(".bam"))
139 			return DBType.BAM;
140 		else if (path.endsWith(".bed"))
141 			return DBType.BED;
142 		else if (path.endsWith(".fa"))
143 			return DBType.FASTA;
144 		else if (path.endsWith(".cytoband"))
145 			return DBType.CytoBand;
146 		return null;
147 	}
148 
149 }