X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fio%2FFeaturesFile.java;h=a704f24d93fec206ccbb651e1640e53e0de3413a;hb=b19880049cdb11882e68c75d7960465be4aa8665;hp=c08c84e32771b43dd0e02e04ddd8e2e9a833852d;hpb=65740880573a48adc758bec3939ece9d9ae104dd;p=jalview.git diff --git a/src/jalview/io/FeaturesFile.java b/src/jalview/io/FeaturesFile.java index c08c84e..a704f24 100755 --- a/src/jalview/io/FeaturesFile.java +++ b/src/jalview/io/FeaturesFile.java @@ -28,6 +28,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Map.Entry; import java.util.TreeMap; @@ -108,12 +109,12 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI /** * Constructor which does not parse the file immediately * - * @param file File or String filename + * @param file + * File or String filename * @param paste * @throws IOException */ - public FeaturesFile(Object file, DataSourceType paste) - throws IOException + public FeaturesFile(Object file, DataSourceType paste) throws IOException { super(false, file, paste); } @@ -234,7 +235,7 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI // skip comments/process pragmas if (line.length() == 0 || line.startsWith("#")) { - if (line.toLowerCase().startsWith("##")) + if (line.toLowerCase(Locale.ROOT).startsWith("##")) { processGffPragma(line, gffProps, align, newseqs); } @@ -311,7 +312,7 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI // should report somewhere useful for UI if necessary warningMessage = ((warningMessage == null) ? "" : warningMessage) + "Parsing error at\n" + line; - System.out.println("Error parsing feature file: " + ex + "\n" + line); + jalview.bin.Console.outPrintln("Error parsing feature file: " + ex + "\n" + line); ex.printStackTrace(System.err); resetMatcher(); return false; @@ -346,14 +347,14 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI String line; while ((line = nextLine()) != null) { - if (line.toUpperCase().startsWith(ENDFILTERS)) + if (line.toUpperCase(Locale.ROOT).startsWith(ENDFILTERS)) { return; } String[] tokens = line.split(TAB_REGEX); if (tokens.length != 2) { - System.err.println(String.format("Invalid token count %d for %d", + jalview.bin.Console.errPrintln(String.format("Invalid token count %d for %d", tokens.length, line)); } else @@ -391,7 +392,7 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI */ if (gffColumns.length < 6) { - System.err.println("Ignoring feature line '" + line + jalview.bin.Console.errPrintln("Ignoring feature line '" + line + "' with too few columns (" + gffColumns.length + ")"); return false; } @@ -414,13 +415,13 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI seq = alignment.getSequenceAt(idx); } catch (NumberFormatException ex) { - System.err.println("Invalid sequence index: " + seqIndex); + jalview.bin.Console.errPrintln("Invalid sequence index: " + seqIndex); } } if (seq == null) { - System.out.println("Sequence not found: " + line); + jalview.bin.Console.outPrintln("Sequence not found: " + line); return false; } @@ -566,21 +567,19 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI } /** - * Returns contents of a Jalview format features file, for visible features, as - * filtered by type and group. Features with a null group are displayed if their - * feature type is visible. Non-positional features may optionally be included - * (with no check on type or group). + * Returns contents of a Jalview format features file, for visible features, + * as filtered by type and group. Features with a null group are displayed if + * their feature type is visible. Non-positional features may optionally be + * included (with no check on type or group). * * @param sequences * @param fr * @param includeNonPositional - * if true, include non-positional features - * (regardless of group or type) + * if true, include non-positional features (regardless of group or + * type) * @param includeComplement - * if true, include visible complementary - * (CDS/protein) positional features, with - * locations converted to local sequence - * coordinates + * if true, include visible complementary (CDS/protein) positional + * features, with locations converted to local sequence coordinates * @return */ public String printJalviewFormat(SequenceI[] sequences, @@ -602,8 +601,8 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI .entrySet()) { FeatureColourI colour = featureColour.getValue(); - out.append(colour.toJalviewFormat(featureColour.getKey())).append( - newline); + out.append(colour.toJalviewFormat(featureColour.getKey())) + .append(newline); } } @@ -632,8 +631,9 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI /** * Outputs any visible complementary (CDS/peptide) positional features as - * Jalview format, within feature group. The coordinates of the linked features - * are converted to the corresponding positions of the local sequences. + * Jalview format, within feature group. The coordinates of the linked + * features are converted to the corresponding positions of the local + * sequences. * * @param out * @param fr @@ -684,7 +684,8 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI /* * output features by group */ - for (Entry>> groupFeatures : map.entrySet()) + for (Entry>> groupFeatures : map + .entrySet()) { out.append(newline); String group = groupFeatures.getKey(); @@ -764,8 +765,8 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI } /** - * Outputs any feature filters defined for visible feature types, sandwiched by - * STARTFILTERS and ENDFILTERS lines + * Outputs any feature filters defined for visible feature types, sandwiched + * by STARTFILTERS and ENDFILTERS lines * * @param out * @param visible @@ -815,9 +816,9 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI * @param includeNonPositional * @return */ - private int outputFeaturesByGroup(StringBuilder out, - FeatureRenderer fr, String[] featureTypes, - SequenceI[] sequences, boolean includeNonPositional) + private int outputFeaturesByGroup(StringBuilder out, FeatureRenderer fr, + String[] featureTypes, SequenceI[] sequences, + boolean includeNonPositional) { List featureGroups = fr.getFeatureGroups(); @@ -866,8 +867,8 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI if (featureTypes.length > 0 && (isNullGroup || visibleGroups.contains(group))) { - features.addAll(sequences[i].getFeatures().getFeaturesForGroup( - true, group, featureTypes)); + features.addAll(sequences[i].getFeatures() + .getFeaturesForGroup(true, group, featureTypes)); } for (SequenceFeature sf : features) @@ -905,9 +906,8 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI * @param sequenceName * @param sequenceFeature */ - protected void formatJalviewFeature( - StringBuilder out, String sequenceName, - SequenceFeature sequenceFeature) + protected void formatJalviewFeature(StringBuilder out, + String sequenceName, SequenceFeature sequenceFeature) { if (sequenceFeature.description == null || sequenceFeature.description.equals("")) @@ -1009,7 +1009,7 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI @Override public String print(SequenceI[] sqs, boolean jvsuffix) { - System.out.println("Use printGffFormat() or printJalviewFormat()"); + jalview.bin.Console.outPrintln("Use printGffFormat() or printJalviewFormat()"); return null; } @@ -1017,19 +1017,16 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI * Returns features output in GFF2 format * * @param sequences - * the sequences whose features are to be - * output + * the sequences whose features are to be output * @param visible - * a map whose keys are the type names of - * visible features + * a map whose keys are the type names of visible features * @param visibleFeatureGroups * @param includeNonPositionalFeatures * @param includeComplement * @return */ - public String printGffFormat(SequenceI[] sequences, - FeatureRenderer fr, boolean includeNonPositionalFeatures, - boolean includeComplement) + public String printGffFormat(SequenceI[] sequences, FeatureRenderer fr, + boolean includeNonPositionalFeatures, boolean includeComplement) { FeatureRenderer fr2 = null; if (includeComplement) @@ -1038,11 +1035,13 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI fr2 = Desktop.getAlignFrameFor(comp).getFeatureRenderer(); } - Map visibleColours = fr.getDisplayedFeatureCols(); + Map visibleColours = fr + .getDisplayedFeatureCols(); StringBuilder out = new StringBuilder(256); - out.append(String.format("%s %d\n", GFF_VERSION, gffVersion == 0 ? 2 : gffVersion)); + out.append(String.format("%s %d\n", GFF_VERSION, + gffVersion == 0 ? 2 : gffVersion)); String[] types = visibleColours == null ? new String[0] : visibleColours.keySet() @@ -1137,17 +1136,17 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI * AC_Male=0;AF_NFE=0.00000e 00;Hom_FIN=0;GQ_MEDIAN=9 * * - * A map-valued attribute is formatted as a comma-delimited list within braces, - * for example + * A map-valued attribute is formatted as a comma-delimited list within + * braces, for example * *
    * jvmap_CSQ={ALLELE_NUM=1,UNIPARC=UPI0002841053,Feature=ENST00000585561}
    * 
* - * The {@code jvmap_} prefix designates a values map and is removed if the value - * is parsed when read in. (The GFF3 specification allows 'semi-structured data' - * to be represented provided the attribute name begins with a lower case - * letter.) + * The {@code jvmap_} prefix designates a values map and is removed if the + * value is parsed when read in. (The GFF3 specification allows + * 'semi-structured data' to be represented provided the attribute name begins + * with a lower case letter.) * * @param sb * @param map @@ -1234,11 +1233,11 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI * format) * * @param alignedRegions - * a list of "Align fromStart toStart fromCount" + * a list of "Align fromStart toStart fromCount" * @param mapIsFromCdna - * if true, 'from' is dna, else 'from' is protein + * if true, 'from' is dna, else 'from' is protein * @param strand - * either 1 (forward) or -1 (reverse) + * either 1 (forward) or -1 (reverse) * @return * @throws IOException */ @@ -1334,7 +1333,7 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI */ if (gffColumns.length < 5) { - System.err.println("Ignoring GFF feature line with too few columns (" + jalview.bin.Console.errPrintln("Ignoring GFF feature line with too few columns (" + gffColumns.length + ")"); return null; } @@ -1365,7 +1364,7 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI } } catch (IOException e) { - System.err.println("GFF parsing failed with: " + e.getMessage()); + jalview.bin.Console.errPrintln("GFF parsing failed with: " + e.getMessage()); return null; } } @@ -1391,7 +1390,9 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI } catch (IOException q) { } - FastaFile parser = new FastaFile(this); + // Opening a FastaFile object with the remainder of this object's dataIn. + // Tell the constructor to NOT close the dataIn when finished. + FastaFile parser = new FastaFile(this, false); List includedseqs = parser.getSeqs(); SequenceIdMatcher smatcher = new SequenceIdMatcher(newseqs); @@ -1454,8 +1455,8 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI List sfs = seq.getFeatures().getPositionalFeatures(); if (!sfs.isEmpty()) { - String newName = (String) sfs.get(0).getValue( - GffHelperI.RENAME_TOKEN); + String newName = (String) sfs.get(0) + .getValue(GffHelperI.RENAME_TOKEN); if (newName != null) { seq.setName(newName); @@ -1531,7 +1532,7 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI } else { - System.err.println("Ignoring unknown pragma: " + line); + jalview.bin.Console.errPrintln("Ignoring unknown pragma: " + line); } } }