| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
package jalview.util; |
| 22 |
|
|
| 23 |
|
import java.util.ArrayList; |
| 24 |
|
import java.util.HashMap; |
| 25 |
|
import java.util.HashSet; |
| 26 |
|
import java.util.List; |
| 27 |
|
import java.util.Locale; |
| 28 |
|
import java.util.Map; |
| 29 |
|
import java.util.Set; |
| 30 |
|
|
| 31 |
|
import jalview.bin.Cache; |
| 32 |
|
import jalview.bin.argparser.Arg; |
| 33 |
|
import jalview.io.FileFormatI; |
| 34 |
|
import jalview.io.FileFormats; |
| 35 |
|
|
| |
|
| 51.8% |
Uncovered Elements: 40 (83) |
Complexity: 16 |
Complexity Density: 0.25 |
|
| 36 |
|
public class ArgParserUtils |
| 37 |
|
{ |
| 38 |
|
public static Set<String> alignmentExtensions = null; |
| 39 |
|
|
| 40 |
|
public static Set<String> annotationsExtensions = null; |
| 41 |
|
|
| 42 |
|
public static Set<String> featuresExtensions = null; |
| 43 |
|
|
| 44 |
|
public static Set<String> treeExtensions = null; |
| 45 |
|
|
| 46 |
|
public static List<Arg> argSet = null; |
| 47 |
|
|
| 48 |
|
public static Map<Arg, Set<String>> argExtensionsMap = null; |
| 49 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 50 |
9 |
public static void preProcessArgs(List<String> filenames)... |
| 51 |
|
{ |
| 52 |
9 |
processFilenames(filenames, true); |
| 53 |
|
} |
| 54 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 55 |
9 |
public static Map<String, BaseInfo> processFilenames(... |
| 56 |
|
List<String> filenames, boolean addArgs) |
| 57 |
|
{ |
| 58 |
9 |
return processFilenames(filenames, addArgs, null); |
| 59 |
|
} |
| 60 |
|
|
| |
|
| 23.1% |
Uncovered Elements: 40 (52) |
Complexity: 13 |
Complexity Density: 0.36 |
|
| 61 |
9 |
public static Map<String, BaseInfo> processFilenames(... |
| 62 |
|
List<String> filenames, boolean addArgs, List<Object> files) |
| 63 |
|
{ |
| 64 |
|
|
| 65 |
|
|
| 66 |
9 |
if (alignmentExtensions == null) |
| 67 |
|
{ |
| 68 |
1 |
setValidExtensions(); |
| 69 |
|
} |
| 70 |
|
|
| 71 |
9 |
Set<String> filesSet = new HashSet<>(filenames); |
| 72 |
|
|
| 73 |
9 |
Map<String, BaseInfo> baseInfoMap = new HashMap<>(); |
| 74 |
|
|
| 75 |
|
|
| 76 |
|
|
| 77 |
9 |
final List<String> filenamesCopy = new ArrayList<>(filenames); |
| 78 |
9 |
for (String filename : filenamesCopy) |
| 79 |
|
{ |
| 80 |
0 |
if (filename == null) |
| 81 |
|
{ |
| 82 |
0 |
continue; |
| 83 |
|
} |
| 84 |
0 |
String ext = FileUtils.getExtension(filename); |
| 85 |
0 |
if (ext != null && ext.length() > 0 |
| 86 |
|
&& alignmentExtensions.contains(ext)) |
| 87 |
|
{ |
| 88 |
0 |
BaseInfo bi = new BaseInfo(filename); |
| 89 |
|
|
| 90 |
|
|
| 91 |
0 |
String base = FileUtils.getBase(filename); |
| 92 |
|
|
| 93 |
0 |
for (Arg arg : argSet) |
| 94 |
|
{ |
| 95 |
0 |
for (String possibleExt : argExtensionsMap.get(arg)) |
| 96 |
|
{ |
| 97 |
0 |
String possibleFile = base + possibleExt; |
| 98 |
0 |
if (filesSet.contains(possibleFile)) |
| 99 |
|
{ |
| 100 |
0 |
bi.putAssociatedFile(arg, possibleFile); |
| 101 |
0 |
int filePos = filenames.indexOf(possibleFile); |
| 102 |
0 |
filenames.remove(possibleFile); |
| 103 |
|
|
| 104 |
|
|
| 105 |
0 |
if (files != null && files.get(filePos) != null |
| 106 |
|
&& possibleFile.equals(files.get(filePos).toString())) |
| 107 |
|
{ |
| 108 |
0 |
files.remove(filePos); |
| 109 |
|
} |
| 110 |
0 |
break; |
| 111 |
|
} |
| 112 |
|
} |
| 113 |
|
} |
| 114 |
|
|
| 115 |
0 |
baseInfoMap.put(filename, bi); |
| 116 |
|
} |
| 117 |
|
} |
| 118 |
|
|
| 119 |
9 |
if (addArgs) |
| 120 |
|
{ |
| 121 |
|
|
| 122 |
|
|
| 123 |
9 |
for (String filename : baseInfoMap.keySet()) |
| 124 |
|
{ |
| 125 |
0 |
BaseInfo bi = baseInfoMap.get(filename); |
| 126 |
|
|
| 127 |
0 |
int pos = filenames.indexOf(filename); |
| 128 |
0 |
if (bi.associatedFiles != null) |
| 129 |
|
{ |
| 130 |
0 |
for (Arg a : bi.associatedFiles.keySet()) |
| 131 |
|
{ |
| 132 |
0 |
String associatedFile = bi.associatedFiles.get(a); |
| 133 |
0 |
if (associatedFile == null) |
| 134 |
|
{ |
| 135 |
|
|
| 136 |
0 |
continue; |
| 137 |
|
} |
| 138 |
0 |
filenames.add(pos + 1, a.argString()); |
| 139 |
0 |
filenames.add(pos + 2, |
| 140 |
|
HttpUtils.equivalentJalviewUrl(associatedFile)); |
| 141 |
|
} |
| 142 |
|
} |
| 143 |
|
|
| 144 |
0 |
filenames.add(pos, Arg.OPEN.argString()); |
| 145 |
|
} |
| 146 |
|
} |
| 147 |
|
|
| 148 |
9 |
return baseInfoMap; |
| 149 |
|
} |
| 150 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (25) |
Complexity: 1 |
Complexity Density: 0.04 |
|
| 151 |
1 |
private static void setValidExtensions()... |
| 152 |
|
{ |
| 153 |
1 |
alignmentExtensions = new HashSet<>(); |
| 154 |
1 |
FileFormats ffs = FileFormats.getInstance(); |
| 155 |
1 |
List<String> validFormats = ffs.getReadableFormats(); |
| 156 |
|
|
| 157 |
1 |
for (String fname : validFormats) |
| 158 |
|
{ |
| 159 |
22 |
FileFormatI tff = ffs.forName(fname); |
| 160 |
22 |
String[] extensions = tff.getExtensions().split(","); |
| 161 |
22 |
for (String ext : extensions) |
| 162 |
|
{ |
| 163 |
31 |
alignmentExtensions.add(ext.toLowerCase(Locale.ROOT)); |
| 164 |
|
} |
| 165 |
|
} |
| 166 |
|
|
| 167 |
1 |
annotationsExtensions = new HashSet<>(); |
| 168 |
1 |
for (String ext : Cache.getDefault( |
| 169 |
|
"ARGPREPROCESSORANNOTATIONSEXTENSIONS", |
| 170 |
|
"annotation,annotations,jvannotation,jvannotations,gff,gff2,gff3") |
| 171 |
|
.split(",")) |
| 172 |
|
{ |
| 173 |
7 |
annotationsExtensions.add(ext); |
| 174 |
|
} |
| 175 |
|
|
| 176 |
1 |
featuresExtensions = new HashSet<>(); |
| 177 |
1 |
for (String ext : Cache.getDefault("ARGPREPROCESSORFEATURESEXTENSIONS", |
| 178 |
|
"feature,features,jvfeature,jvfeatures").split(",")) |
| 179 |
|
{ |
| 180 |
4 |
featuresExtensions.add(ext); |
| 181 |
|
} |
| 182 |
|
|
| 183 |
1 |
treeExtensions = new HashSet<>(); |
| 184 |
1 |
for (String ext : Cache.getDefault("ARGPREPROCESSORTREEEXTENSIONS", |
| 185 |
|
"tree,tre,newick,nwk").split(",")) |
| 186 |
|
{ |
| 187 |
4 |
treeExtensions.add(ext); |
| 188 |
|
} |
| 189 |
|
|
| 190 |
1 |
argSet = new ArrayList<>(); |
| 191 |
1 |
argSet.add(Arg.ANNOTATIONS); |
| 192 |
1 |
argSet.add(Arg.FEATURES); |
| 193 |
1 |
argSet.add(Arg.TREE); |
| 194 |
|
|
| 195 |
1 |
argExtensionsMap = new HashMap<>(); |
| 196 |
1 |
argExtensionsMap.put(Arg.ANNOTATIONS, annotationsExtensions); |
| 197 |
1 |
argExtensionsMap.put(Arg.FEATURES, featuresExtensions); |
| 198 |
1 |
argExtensionsMap.put(Arg.TREE, treeExtensions); |
| 199 |
|
} |
| 200 |
|
|
| |
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 4 |
Complexity Density: 0.8 |
|
| 201 |
|
public static class BaseInfo |
| 202 |
|
{ |
| 203 |
|
String filename; |
| 204 |
|
|
| 205 |
|
Map<Arg, String> associatedFiles = null; |
| 206 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 207 |
0 |
BaseInfo(String filename)... |
| 208 |
|
{ |
| 209 |
0 |
this.filename = filename; |
| 210 |
|
} |
| 211 |
|
|
| |
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 212 |
0 |
void putAssociatedFile(Arg a, String file)... |
| 213 |
|
{ |
| 214 |
0 |
if (associatedFiles == null) |
| 215 |
|
{ |
| 216 |
0 |
associatedFiles = new HashMap<>(); |
| 217 |
|
} |
| 218 |
0 |
associatedFiles.put(a, file); |
| 219 |
|
} |
| 220 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 221 |
0 |
public Map<Arg, String> getAssociatedFilesMap()... |
| 222 |
|
{ |
| 223 |
0 |
return associatedFiles; |
| 224 |
|
} |
| 225 |
|
} |
| 226 |
|
|
| 227 |
|
} |