From: <gk...@us...> - 2010-05-05 14:17:05
|
Revision: 23134 http://gmod.svn.sourceforge.net/gmod/?rev=23134&view=rev Author: gk_fan Date: 2010-05-05 14:16:49 +0000 (Wed, 05 May 2010) Log Message: ----------- + Fixed GFF3 input from URL when run from the command line Modified Paths: -------------- apollo/trunk/src/java/apollo/dataadapter/DataInput.java apollo/trunk/src/java/apollo/dataadapter/gff3/GFF3Adapter.java Modified: apollo/trunk/src/java/apollo/dataadapter/DataInput.java =================================================================== --- apollo/trunk/src/java/apollo/dataadapter/DataInput.java 2010-05-05 13:26:27 UTC (rev 23133) +++ apollo/trunk/src/java/apollo/dataadapter/DataInput.java 2010-05-05 14:16:49 UTC (rev 23134) @@ -124,14 +124,27 @@ return getInputString() != null; } - public boolean isFile() { return getType() == DataInputType.FILE; } - + public boolean isFile() { + return getType() == DataInputType.FILE; + } + public String getFilename() { if (!isFile()) return null; return getInputString(); } + + public boolean isUrl() { + return getType() == DataInputType.URL; + } + public String getUrl() { + if (!isUrl()) { + return null; + } + return getInputString(); + } + /** Returns true if DataInputType is BASEPAIR_RANGE */ public boolean isRegion() { return getType() == DataInputType.BASEPAIR_RANGE; Modified: apollo/trunk/src/java/apollo/dataadapter/gff3/GFF3Adapter.java =================================================================== --- apollo/trunk/src/java/apollo/dataadapter/gff3/GFF3Adapter.java 2010-05-05 13:26:27 UTC (rev 23133) +++ apollo/trunk/src/java/apollo/dataadapter/gff3/GFF3Adapter.java 2010-05-05 14:16:49 UTC (rev 23134) @@ -122,7 +122,12 @@ */ public void setDataInput(apollo.dataadapter.DataInput di) { - setGffFilename(di.getFilename()); + if (di.isFile()) { + setGffFilename(di.getFilename()); + } + else if (di.isUrl()) { + setGffFilename(di.getUrl()); + } if (di.hasSequenceFilename()) { setSeqFilename(di.getSequenceFilename()); } @@ -238,6 +243,7 @@ */ private void writeSeqs(PrintWriter out, List<SequenceI> seqs) { + out.println("##FASTA"); for (SequenceI seq : seqs) { if (seq.getLength() > 0) { out.print(FastaFile.print(seq)); @@ -597,169 +603,168 @@ Map<String, int []> cdsCoords, CurationSet curation) throws ApolloAdapterException { - Map<String, FeatureSetI[]> resultSets = - new TreeMap<String, FeatureSetI[]>(); - Set<String> errors = new HashSet<String>(); - Set<GFF3Data> matches = new HashSet<GFF3Data>(); - for (Map.Entry<String, GFF3Data> mapEntry : gffMap.entrySet()) { - GFF3Data data = mapEntry.getValue(); - GFF3Entry gff = data.getEntry(); - SeqFeatureI feat = data.getFeat(); - feat.setRefSequence(curation.getRefSequence()); - if (!gff.isAnnotation()) { - processEvidence(feat); - } - // add matches for post processing if they're missing match_part features - if (gff.getType().equals("match")) { - matches.add(data); - } - boolean added = false; - List<String> pids = gff.getAttributeValues("Parent"); - if (pids != null) { - int pnum = 0; - for (String pid : pids) { - GFF3Data pdata = gffMap.get(pid); - if (gff.isAnnotation()) { - SeqFeatureI parent = pdata.getFeat(); - if (!feat.isTranscript() && !feat.isExon()) { - if (!errors.contains(feat.getName())) { - IOUtil.errorDialog("Only transcripts and exons can be children of annotations: " + - feat.getName() + "[" + feat.getFeatureType() + "]"); - errors.add(feat.getName()); - } - added = true; - continue; + Map<String, FeatureSetI[]> resultSets = new TreeMap<String, FeatureSetI[]>(); + Set<String> errors = new HashSet<String>(); + Set<GFF3Data> matches = new HashSet<GFF3Data>(); + for (Map.Entry<String, GFF3Data> mapEntry : gffMap.entrySet()) { + GFF3Data data = mapEntry.getValue(); + GFF3Entry gff = data.getEntry(); + SeqFeatureI feat = data.getFeat(); + feat.setRefSequence(curation.getRefSequence()); + if (!gff.isAnnotation()) { + processEvidence(feat); + } + // add matches for post processing if they're missing match_part features + if (gff.getType().equals("match")) { + matches.add(data); + } + boolean added = false; + List<String> pids = gff.getAttributeValues("Parent"); + if (pids != null) { + int pnum = 0; + for (String pid : pids) { + GFF3Data pdata = gffMap.get(pid); + if (gff.isAnnotation()) { + SeqFeatureI parent = pdata.getFeat(); + if (!feat.isTranscript() && !feat.isExon()) { + if (!errors.contains(feat.getName())) { + IOUtil.errorDialog("Only transcripts and exons can be children of annotations: " + + feat.getName() + "[" + feat.getFeatureType() + "]"); + errors.add(feat.getName()); } - if (feat.isExon() && !parent.isTranscript()) { - if (!errors.contains(feat.getName())) { - IOUtil.errorDialog("Exons can only be children of transcripts: " + feat.getName() + " -> " + - parent.getName() + "[" + parent.getFeatureType() + "]"); - errors.add(feat.getName()); - } - added = true; - continue; - } - } - ++pnum; - if (pdata == null) { //orphan - logger.warn("Missing parent " + pid + " for " + - gff.getName()); + added = true; continue; } - if (pnum > 1) { - if (pnum == 2) { - feat.setId(feat.getId() + "-1"); + if (feat.isExon() && !parent.isTranscript()) { + if (!errors.contains(feat.getName())) { + IOUtil.errorDialog("Exons can only be children of transcripts: " + feat.getName() + " -> " + + parent.getName() + "[" + parent.getFeatureType() + "]"); + errors.add(feat.getName()); } - feat = feat.cloneFeature(); - feat.setId(feat.getId().replaceFirst("-\\d+$", - "-" + pnum)); + added = true; + continue; } - if (gff.isAnnotation()) { - processAnnotation(data, pdata.getFeat(), cdsCoords); + } + ++pnum; + if (pdata == null) { //orphan + logger.warn("Missing parent " + pid + " for " + + gff.getName()); + continue; + } + if (pnum > 1) { + if (pnum == 2) { + feat.setId(feat.getId() + "-1"); } - try { - pdata.getFeat().addFeature(feat); - added = true; - } - catch (ClassCastException e) { - /* + feat = feat.cloneFeature(); + feat.setId(feat.getId().replaceFirst("-\\d+$", + "-" + pnum)); + } + if (gff.isAnnotation()) { + processAnnotation(data, pdata.getFeat(), cdsCoords); + } + try { + pdata.getFeat().addFeature(feat); + added = true; + } + catch (ClassCastException e) { + /* throw new ApolloAdapterException("Cannot add " + feat + "(" + data.getEntry().getType() + ")" + " to " + pdata.getFeat() + "(" + pdata.getEntry().getType() + ")"); - */ - logger.warn("Cannot add " + feat + - "(" + data.getEntry().getType() + ")" + " to " + - pdata.getFeat() + "(" + pdata.getEntry().getType() + - ")"); - } + */ + logger.warn("Cannot add " + feat + + "(" + data.getEntry().getType() + ")" + " to " + + pdata.getFeat() + "(" + pdata.getEntry().getType() + + ")"); } } - //a transcript can potentially not have a gene associated with it, in which - //case we need to generate one (the GFF3 spec doesn't REQUIRE a transcript - //to have a gene, which seems kind of silly to me...) - else { - if (!feat.isAnnotTop()) { - if (gff.isAnnotation()) { - logger.warn("No parent feature found for " + feat + - "(" + gff.getType() + "). Generating dummy parent feature."); - generateParent(feat, annots); - added = true; - } + } + //a transcript can potentially not have a gene associated with it, in which + //case we need to generate one (the GFF3 spec doesn't REQUIRE a transcript + //to have a gene, which seems kind of silly to me...) + else { + if (!feat.isAnnotTop()) { + if (gff.isAnnotation()) { + logger.warn("No parent feature found for " + feat + + "(" + gff.getType() + "). Generating dummy parent feature."); + generateParent(feat, annots); + added = true; } } - if (!added) { - if (gff.isAnnotation()) { - // need to wrap one-level annotations in a AnnotationFeatureI otherwise Apollo isn't happy - if (feat.isAnnotTop() && gff.isOneLevelAnnotation()) { - AnnotatedFeatureI fs = new AnnotatedFeature(); - fs.addFeature(feat); - fs.setStrand(feat.getStrand()); - fs.setId(feat.getId() + "-fs"); - fs.setFeatureType(feat.getFeatureType()); - feat = fs; - } - // arbitrarily add strand-less features to plus strand - if (feat.getStrand() == 0) { - annots.getForwardSet().addFeature(feat); - } - else { - annots.addFeature(feat); - } + } + if (!added) { + if (gff.isAnnotation()) { + // need to wrap one-level annotations in a AnnotationFeatureI otherwise Apollo isn't happy +// if (feat.isAnnotTop() && gff.isOneLevelAnnotation()) { +// AnnotatedFeatureI fs = new AnnotatedFeature(); +// fs.addFeature(feat); +// fs.setStrand(feat.getStrand()); +// fs.setId(feat.getId() + "-fs"); +// fs.setFeatureType(feat.getFeatureType()); +// feat = fs; +// } + // arbitrarily add strand-less features to plus strand + if (feat.getStrand() == 0) { + annots.getForwardSet().addFeature(feat); } else { - processEvidence(feat); - FeatureSetI []fsArray = resultSets.get(gff.getSource()); - if (fsArray == null) { - fsArray = new FeatureSet[2]; - resultSets.put(gff.getSource(), fsArray); - } - int arrayIdx = gff.getStrand() == 1 ? 1 : 0; - FeatureSetI fs = fsArray[arrayIdx]; - if (fs == null) { - fs = new FeatureSet(gff.getSource(), gff.getStrand()); - fsArray[arrayIdx] = fs; - } - fs.addFeature(feat); - /* - results.addFeature(feat); - */ + annots.addFeature(feat); } } - } - - // add FeaturePair objects to any matches with no match_part children - for (GFF3Data data : matches) { - SeqFeatureI match = data.getFeat(); - if (match.getFeatures().size() == 0) { - GFF3Entry matchPart = new GFF3Entry(data.getEntry().toString()); - matchPart.setType("match_part"); - try { - SeqFeatureI matchPartFeat = matchPart.createFeature(oboParser); - processEvidence(matchPartFeat); - match.addFeature(matchPartFeat); + else { + processEvidence(feat); + FeatureSetI []fsArray = resultSets.get(gff.getSource()); + if (fsArray == null) { + fsArray = new FeatureSet[2]; + resultSets.put(gff.getSource(), fsArray); } - catch (ClassNotFoundException e) { - throw new ApolloAdapterException("Cannot locate Apollo datamodel class: " + e.getMessage()); + int arrayIdx = gff.getStrand() == 1 ? 1 : 0; + FeatureSetI fs = fsArray[arrayIdx]; + if (fs == null) { + fs = new FeatureSet(gff.getSource(), gff.getStrand()); + fsArray[arrayIdx] = fs; } - catch (IllegalAccessException e) { - throw new ApolloAdapterException(e); - } - catch (InstantiationException e) { - throw new ApolloAdapterException("Cannot instantiate class: " + e.getMessage()); - } + fs.addFeature(feat); + /* + results.addFeature(feat); + */ } } + } - for (Map.Entry<String, FeatureSetI[]> e : resultSets.entrySet()) { - if (e.getValue()[0] != null) { - results.addFeature(e.getValue()[0]); + // add FeaturePair objects to any matches with no match_part children + for (GFF3Data data : matches) { + SeqFeatureI match = data.getFeat(); + if (match.getFeatures().size() == 0) { + GFF3Entry matchPart = new GFF3Entry(data.getEntry().toString()); + matchPart.setType("match_part"); + try { + SeqFeatureI matchPartFeat = matchPart.createFeature(oboParser); + processEvidence(matchPartFeat); + match.addFeature(matchPartFeat); } - if (e.getValue()[1] != null) { - results.addFeature(e.getValue()[1]); + catch (ClassNotFoundException e) { + throw new ApolloAdapterException("Cannot locate Apollo datamodel class: " + e.getMessage()); } + catch (IllegalAccessException e) { + throw new ApolloAdapterException(e); + } + catch (InstantiationException e) { + throw new ApolloAdapterException("Cannot instantiate class: " + e.getMessage()); + } } - setTranslationEnds(gffMap, cdsCoords); + } + + for (Map.Entry<String, FeatureSetI[]> e : resultSets.entrySet()) { + if (e.getValue()[0] != null) { + results.addFeature(e.getValue()[0]); + } + if (e.getValue()[1] != null) { + results.addFeature(e.getValue()[1]); + } + } + setTranslationEnds(gffMap, cdsCoords); } private void generateParent(SeqFeatureI feat, StrandedFeatureSetI annots) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |