X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fhmmer%2FHmmerCommand.java;h=f38be0296b7145db164072a7af541d9d00b0b4fa;hb=72404f561ccd190eab1990874f017bbe94bf9e10;hp=20e00834e4fb3d4655cf0b07a2cb8193ccc892d4;hpb=57e8b75999c110509906efa4ec8107f23785739f;p=jalview.git diff --git a/src/jalview/hmmer/HmmerCommand.java b/src/jalview/hmmer/HmmerCommand.java index 20e0083..f38be02 100644 --- a/src/jalview/hmmer/HmmerCommand.java +++ b/src/jalview/hmmer/HmmerCommand.java @@ -8,10 +8,12 @@ import jalview.datamodel.AlignmentI; import jalview.datamodel.AnnotatedCollectionI; import jalview.datamodel.Annotation; import jalview.datamodel.HiddenMarkovModel; +import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.gui.AlignFrame; import jalview.gui.JvOptionPane; import jalview.gui.Preferences; +import jalview.io.FastaFile; import jalview.io.HMMFile; import jalview.io.StockholmFile; import jalview.util.FileUtils; @@ -45,6 +47,51 @@ public abstract class HmmerCommand implements Runnable protected final List params; + /* + * constants for i18n lookup of passed parameter names + */ + static final String DATABASE_KEY = "label.database"; + + static final String THIS_ALIGNMENT_KEY = "label.this_alignment"; + + static final String USE_ACCESSIONS_KEY = "label.use_accessions"; + + static final String AUTO_ALIGN_SEQS_KEY = "label.auto_align_seqs"; + + static final String NUMBER_OF_RESULTS_KEY = "label.number_of_results"; + + static final String TRIM_TERMINI_KEY = "label.trim_termini"; + + static final String RETURN_N_NEW_SEQ = "label.check_for_new_sequences"; + + static final String REPORTING_CUTOFF_KEY = "label.reporting_cutoff"; + + static final String CUTOFF_NONE = "label.default"; + + static final String CUTOFF_SCORE = "label.score"; + + static final String CUTOFF_EVALUE = "label.evalue"; + + static final String REPORTING_SEQ_EVALUE_KEY = "label.reporting_seq_evalue"; + + static final String REPORTING_DOM_EVALUE_KEY = "label.reporting_dom_evalue"; + + static final String REPORTING_SEQ_SCORE_KEY = "label.reporting_seq_score"; + + static final String REPORTING_DOM_SCORE_KEY = "label.reporting_dom_score"; + + static final String INCLUSION_SEQ_EVALUE_KEY = "label.inclusion_seq_evalue"; + + static final String INCLUSION_DOM_EVALUE_KEY = "label.inclusion_dom_evalue"; + + static final String INCLUSION_SEQ_SCORE_KEY = "label.inclusion_seq_score"; + + static final String INCLUSION_DOM_SCORE_KEY = "label.inclusion_dom_score"; + + static final String ARG_TRIM = "--trim"; + + static final String INCLUSION_THRESHOLD_KEY = "label.inclusion_threshold"; + /** * Constructor * @@ -193,7 +240,7 @@ public abstract class HmmerCommand implements Runnable /** * Exports an alignment, and reference (RF) annotation if present, to the - * specified file, in Stockholm format + * specified file, in Stockholm format, removing all HMM sequences * * @param seqs * @param toFile @@ -201,13 +248,15 @@ public abstract class HmmerCommand implements Runnable * @throws IOException */ public void exportStockholm(SequenceI[] seqs, File toFile, - AnnotatedCollectionI annotated) throws IOException + AnnotatedCollectionI annotated) + throws IOException { if (seqs == null) { return; } AlignmentI newAl = new Alignment(seqs); + if (!newAl.isAligned()) { newAl.padGaps(); @@ -241,6 +290,17 @@ public abstract class HmmerCommand implements Runnable } } + for (SequenceI seq : newAl.getSequencesArray()) + { + if (seq.getAnnotation() != null) + { + for (AlignmentAnnotation ann : seq.getAnnotation()) + { + seq.removeAlignmentAnnotation(ann); + } + } + } + StockholmFile file = new StockholmFile(newAl); String output = file.print(seqs, false); PrintWriter writer = new PrintWriter(toFile); @@ -292,6 +352,25 @@ public abstract class HmmerCommand implements Runnable } } + // TODO is needed? + /** + * Exports a sequence to the specified file + * + * @param hmm + * @param hmmFile + * @throws IOException + */ + public void exportSequence(SequenceI seq, File seqFile) throws IOException + { + if (seq != null) + { + FastaFile file = new FastaFile(); + PrintWriter writer = new PrintWriter(seqFile); + writer.print(file.print(new SequenceI[] { seq }, false)); + writer.close(); + } + } + /** * Answers the HMM profile for the profile sequence the user selected (default * is just the first HMM sequence in the alignment) @@ -318,6 +397,29 @@ public abstract class HmmerCommand implements Runnable } /** + * Answers the query sequence the user selected (default is just the first + * sequence in the alignment) + * + * @return + */ + protected SequenceI getSequence() + { + String alignToParamName = MessageManager + .getString("label.use_sequence"); + for (ArgumentI arg : params) + { + String name = arg.getName(); + if (name.equals(alignToParamName)) + { + String seqName = arg.getValue(); + SequenceI seq = alignment.findName(seqName); + return seq; + } + } + return null; + } + + /** * Answers an absolute path to the given file, in a format suitable for * processing by a hmmer command. On a Windows platform, the native Windows file * path is converted to Cygwin format, by replacing '\'with '/' and drive letter @@ -346,4 +448,87 @@ public abstract class HmmerCommand implements Runnable return path; } + + /** + * A helper method that deletes any HMM consensus sequence from the given + * collection, and from the parent alignment if ac is a subgroup + * + * @param ac + */ + void deleteHmmSequences(AnnotatedCollectionI ac) + { + List hmmSeqs = ac.getHmmSequences(); + for (SequenceI hmmSeq : hmmSeqs) + { + if (ac instanceof SequenceGroup) + { + ((SequenceGroup) ac).deleteSequence(hmmSeq, false); + AnnotatedCollectionI context = ac.getContext(); + if (context != null && context instanceof AlignmentI) + { + ((AlignmentI) context).deleteSequence(hmmSeq); + } + } + else + { + ((AlignmentI) ac).deleteSequence(hmmSeq); + } + } + } + + /** + * Sets the names of any duplicates within the given sequences to include their + * respective lengths. Deletes any duplicates that have the same name after this + * step + * + * @param seqs + */ + void renameDuplicates(AlignmentI al) + { + + SequenceI[] seqs = al.getSequencesArray(); + List wasRenamed = new ArrayList<>(); + + for (SequenceI seq : seqs) + { + wasRenamed.add(false); + } + + for (int i = 0; i < seqs.length; i++) + { + for (int j = 0; j < seqs.length; j++) + { + if (seqs[i].getName().equals(seqs[j].getName()) && i != j + && !wasRenamed.get(j)) + { + + wasRenamed.set(i, true); + String range = "/" + seqs[j].getStart() + "-" + seqs[j].getEnd(); + // setting sequence name to include range - to differentiate between + // sequences of the same name. Currently have to include the range twice + // because the range is removed (once) when setting the name + // TODO come up with a better way of doing this + seqs[j].setName(seqs[j].getName() + range + range); + } + + } + if (wasRenamed.get(i)) + { + String range = "/" + seqs[i].getStart() + "-" + seqs[i].getEnd(); + seqs[i].setName(seqs[i].getName() + range + range); + } + } + + for (int i = 0; i < seqs.length; i++) + { + for (int j = 0; j < seqs.length; j++) + { + if (seqs[i].getName().equals(seqs[j].getName()) && i != j) + { + al.deleteSequence(j); + } + } + } + } + }