use of org.rcsb.mmtf.dataholders.MmtfStructure in project mmtf-spark by sbl-sdsc.
the class MmtfReader method readMmtfFiles.
/**
* Reads uncompressed and compressed MMTF files recursively from
* a given directory.
* This methods reads files with the mmtf or mmtf.gz extension.
*
* @param path Path to MMTF files
* @param sc Spark context
* @return structure data as keyword/value pairs
*/
public static JavaPairRDD<String, StructureDataInterface> readMmtfFiles(String path, JavaSparkContext sc) {
return sc.parallelize(getFiles(path)).mapToPair(new PairFunction<File, String, StructureDataInterface>() {
private static final long serialVersionUID = 9018971417443154996L;
public Tuple2<String, StructureDataInterface> call(File f) throws Exception {
try {
if (f.toString().contains(".mmtf.gz")) {
InputStream in = new FileInputStream(f);
MmtfStructure mmtf = new MessagePackSerialization().deserialize(new GZIPInputStream(in));
return new Tuple2<String, StructureDataInterface>(f.getName().substring(0, f.getName().indexOf(".mmtf")), new GenericDecoder(mmtf));
} else if (f.toString().contains(".mmtf")) {
InputStream in = new FileInputStream(f);
MmtfStructure mmtf = new MessagePackSerialization().deserialize(in);
return new Tuple2<String, StructureDataInterface>(f.getName().substring(0, f.getName().indexOf(".mmtf")), new GenericDecoder(mmtf));
} else
return null;
} catch (Exception e) {
System.out.println(e);
return null;
}
}
}).filter(t -> t != null);
}
Aggregations