public boolean testPredicate(Feature targetFeature) { String targetKey = targetFeature.getKey().getKeyString(); if (sameKey && !targetKey.equals(key)) return false; Vector<String> chadoNames = null; if (isDatabaseEntry) { GFFStreamFeature gffFeature = ((GFFStreamFeature) targetFeature.getEmblFeature()); if (gffFeature.getChadoGene() != null) { chadoNames = new Vector<String>(); ChadoCanonicalGene chadoGene = gffFeature.getChadoGene(); chadoNames.add(chadoGene.getGeneUniqueName()); List<uk.ac.sanger.artemis.io.Feature> transcripts = chadoGene.getTranscripts(); for (int i = 0; i < transcripts.size(); i++) { GFFStreamFeature feature = (GFFStreamFeature) transcripts.get(i); chadoNames.add(GeneUtils.getUniqueName(feature)); } } } String thisFeatureSystematicName = targetFeature.getSystematicName(); for (int i = 0; i < geneNames.length; i++) { if (geneNames[i].equals(thisFeatureSystematicName) || (chadoNames != null && chadoNames.contains(geneNames[i]))) { geneName = geneNames[i]; return true; } } return false; }
/** * @param features * @param qualifiersToTransfer * @param key * @param sameKey * @param isDatabaseEntry * @param geneNames * @return */ private static String[] transfer( final FeatureVector features, final QualifierVector qualifiersToTransfer, final String key, final boolean sameKey, final boolean overwrite, final boolean isDatabaseEntry, String[] geneNames, final StringBuffer genesUpdated) { final TransferFeaturePredicate predicate = new TransferFeaturePredicate(key, sameKey, isDatabaseEntry, geneNames); for (int i = 0; i < features.size(); i++) { Feature thisFeature = features.elementAt(i); if (predicate.testPredicate(thisFeature)) { StringBuffer qualifierBuffer = new StringBuffer(); for (int j = 0; j < qualifiersToTransfer.size(); j++) { Qualifier newQualifier = qualifiersToTransfer.elementAt(j); String qualifierName = newQualifier.getName(); try { if (overwrite) { thisFeature.setQualifier(newQualifier); qualifierBuffer.append( " " + qualifierName + " (overwritten)\n" + parseStringVector(newQualifier.getValues())); } else { final StringVector oldValues; if (thisFeature.getQualifierByName(newQualifier.getName()) == null) oldValues = null; else oldValues = thisFeature.getQualifierByName(newQualifier.getName()).getValues(); final Qualifier newQualifierTmp = getQualifierWithoutDuplicateValues(newQualifier, oldValues); if (newQualifierTmp == null) continue; thisFeature.addQualifierValues(newQualifierTmp); qualifierBuffer.append( " " + qualifierName + " (added)\n" + parseStringVector(newQualifier.getValues())); } } catch (Exception e1) { e1.printStackTrace(); } } geneNames = removeArrayElement(geneNames, predicate.getGeneName()); if (qualifierBuffer.length() > 0) genesUpdated.append( thisFeature.getSystematicName() + " (" + key + ")\n" + qualifierBuffer); } } return geneNames; }