Skip to content
Snippets Groups Projects
Commit eeaeb78e authored by tjc's avatar tjc
Browse files

DatabaseStreamFeature should extend GFFStreamFeature

git-svn-id: svn+ssh://svn.internal.sanger.ac.uk/repos/svn/pathsoft/artemis/trunk@2836 ee4ac58c-ac51-4696-9907-e4b3aa274f04
parent 45c34f0e
No related branches found
No related tags found
No related merge requests found
...@@ -86,7 +86,7 @@ public class DatabaseDocumentEntry extends SimpleDocumentEntry ...@@ -86,7 +86,7 @@ public class DatabaseDocumentEntry extends SimpleDocumentEntry
if(feature instanceof DatabaseStreamFeature) if(feature instanceof DatabaseStreamFeature)
return (DatabaseStreamFeature)feature; return (DatabaseStreamFeature)feature;
else else
return (EmblStreamFeature)feature; return (GFFStreamFeature)feature;
} }
else else
return new DatabaseStreamFeature(feature); return new DatabaseStreamFeature(feature);
......
...@@ -31,11 +31,11 @@ import java.io.*; ...@@ -31,11 +31,11 @@ import java.io.*;
* This is an implementation of Feature that can read and write itself to a * This is an implementation of Feature that can read and write itself to a
* CHADO stream. * CHADO stream.
* *
* @version $Id: DatabaseStreamFeature.java,v 1.1 2005-03-31 12:09:13 tjc Exp $ * @version $Id: DatabaseStreamFeature.java,v 1.2 2005-06-13 18:36:49 tjc Exp $
**/ **/
public class DatabaseStreamFeature public class DatabaseStreamFeature
extends SimpleDocumentFeature extends GFFStreamFeature
implements DocumentFeature, StreamFeature, ComparableFeature implements DocumentFeature, StreamFeature, ComparableFeature
{ {
/** /**
...@@ -151,23 +151,23 @@ public class DatabaseStreamFeature ...@@ -151,23 +151,23 @@ public class DatabaseStreamFeature
* @return null if in_stream is at the end of file when the method is * @return null if in_stream is at the end of file when the method is
* called * called
**/ **/
protected static DatabaseStreamFeature //protected static DatabaseStreamFeature
readFromStream(LinePushBackReader stream) // readFromStream(LinePushBackReader stream)
throws IOException // throws IOException
{ //{
String line = stream.readLine (); // String line = stream.readLine ();
return readFromStream(line); // return readFromStream(line);
} //}
protected static DatabaseStreamFeature //protected static DatabaseStreamFeature
readFromStream(String line) // readFromStream(String line)
throws IOException // throws IOException
{ //{
if(line == null) // if(line == null)
return null; // return null;
return new DatabaseStreamFeature(line); // return new DatabaseStreamFeature(line);
} //}
/** /**
* This is used by readFromStream() as temporary storage. It is a class * This is used by readFromStream() as temporary storage. It is a class
......
...@@ -115,11 +115,28 @@ public class DatabaseDocument extends Document ...@@ -115,11 +115,28 @@ public class DatabaseDocument extends Document
* Return a Document with the last element stripped off. * Return a Document with the last element stripped off.
* *
**/ **/
public Document getParent() public String getFeatureName(String feature_id, Connection conn)
throws java.sql.SQLException
{
Statement st = conn.createStatement();
String sql = "SELECT name FROM feature WHERE feature_id= "+feature_id;
appendToLogFile(sql,sqlLog);
ResultSet rs = st.executeQuery(sql);
rs.next();
return rs.getString("name");
}
/**
*
* Return a Document with the last element stripped off.
*
**/
public Document getParent()
{ {
return null; return null;
} }
/** /**
* *
* Return true if and only if the Document refered to by this object exists * Return true if and only if the Document refered to by this object exists
...@@ -157,9 +174,9 @@ public class DatabaseDocument extends Document ...@@ -157,9 +174,9 @@ public class DatabaseDocument extends Document
Connection conn = getConnection(); Connection conn = getConnection();
System.out.println("Connected"); System.out.println("Connected");
String entry = getGene(conn,feature_id) + getSequence(conn); String entry = getGFF(conn,feature_id) + getSequence(conn);
// String entry = getSequence(conn); // String entry = getSequence(conn);
appendToLogFile(entry,sqlLog);
ByteArrayInputStream instream = new ByteArrayInputStream(entry.getBytes()); ByteArrayInputStream instream = new ByteArrayInputStream(entry.getBytes());
return instream; return instream;
} }
...@@ -172,45 +189,47 @@ public class DatabaseDocument extends Document ...@@ -172,45 +189,47 @@ public class DatabaseDocument extends Document
return null; return null;
} }
private String getGene(Connection conn, String parentFeatureID) private String getGFF(Connection conn, String parentFeatureID)
throws java.sql.SQLException throws java.sql.SQLException
{ {
Statement st = conn.createStatement(); Statement st = conn.createStatement();
String sql = "SELECT strand, fmin, fmax, value, uniquename, featureprop.type_id, strand"+ String sql = "SELECT strand, fmin, fmax, value, uniquename, feature.type_id, featureprop.type_id, strand"+
" FROM feature, featureloc, featureprop WHERE srcfeature_id = "+parentFeatureID+ " FROM feature, featureloc, featureprop WHERE srcfeature_id = "+parentFeatureID+
" and featureloc.feature_id=featureprop.feature_id"+ " and featureloc.feature_id=featureprop.feature_id"+
" and featureloc.feature_id=feature.feature_id" + " and featureloc.feature_id=feature.feature_id" +
" and feature.type_id=cvterm.cvterm_id and cvterm.name='gene'"; " and feature.type_id=cvterm.cvterm_id"; // and cvterm.name='gene'";
appendToLogFile(sql,sqlLog); appendToLogFile(sql,sqlLog);
ResultSet rs = st.executeQuery(sql); ResultSet rs = st.executeQuery(sql);
StringBuffer cdsBuffer = new StringBuffer(); StringBuffer cdsBuffer = new StringBuffer();
String parentFeature = getFeatureName(parentFeatureID,conn);
int loop = 1; int loop = 1;
while(rs.next()) while(rs.next())
{ {
int fmin = rs.getInt("fmin")+1; int fmin = rs.getInt("fmin")+1;
int fmax = rs.getInt("fmax"); int fmax = rs.getInt("fmax");
long type_id = rs.getLong("type_id"); long type_id = rs.getLong(6);
long prop_type_id = rs.getLong(7);
int strand = rs.getInt("strand"); int strand = rs.getInt("strand");
String name = rs.getString("uniquename"); String name = rs.getString("uniquename");
String typeName = getCvtermName(conn,type_id); String typeName = getCvtermName(conn,type_id);
String propTypeName = getCvtermName(conn,prop_type_id);
// start with uniquename // make gff format
cdsBuffer.append("CHADO="+name+" ");
cdsBuffer.append(parentFeature+"\t"); // seqid
if(strand == -1) cdsBuffer.append("chado\t"); // source
cdsBuffer.append("complement("); cdsBuffer.append(typeName+"\t"); // type
cdsBuffer.append(fmin+".."); cdsBuffer.append(fmin+"\t"); // start
cdsBuffer.append(fmax); cdsBuffer.append(fmax+"\t"); // end
if(strand == -1) cdsBuffer.append(".\t"); // score
cdsBuffer.append(")"); if(strand == -1) // strand
cdsBuffer.append("-\t");
cdsBuffer.append(";"); else
cdsBuffer.append("/"+typeName+"=\""); cdsBuffer.append("+\t");
cdsBuffer.append(rs.getString("value")+"\"\n"); cdsBuffer.append(".\t"); // phase
cdsBuffer.append("ID="+name+";"+propTypeName+"="+rs.getString("value")+"\n"); // attributes
progress_listener.progressMade("Read from database: "+name); progress_listener.progressMade("Read from database: "+name);
} }
...@@ -276,7 +295,7 @@ public class DatabaseDocument extends Document ...@@ -276,7 +295,7 @@ public class DatabaseDocument extends Document
rs.next(); rs.next();
name = rs.getString("name"); name = rs.getString("name");
return rs.getString("residues"); return "##FASTA\n>" + name + "\n" + rs.getString("residues");
} }
...@@ -378,8 +397,8 @@ public class DatabaseDocument extends Document ...@@ -378,8 +397,8 @@ public class DatabaseDocument extends Document
try try
{ {
String dat = new java.util.Date().toString(); String dat = new java.util.Date().toString();
bw = new BufferedWriter(new FileWriter(dat+":: "+logFileName, true)); bw = new BufferedWriter(new FileWriter(logFileName, true));
bw.write(logEntry); bw.write(dat+":: "+logEntry);
bw.newLine(); bw.newLine();
bw.flush(); bw.flush();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment